Skip to content

Commit

Permalink
fix in internal css decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
alihassan143 committed Dec 19, 2023
1 parent cdee600 commit 7f05fdd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 0.0.9+2
* fix internal css decoration not working
## 0.0.9+1

* optimiz parse logic
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.8+2"
version: "0.0.9+1"
http:
dependency: transitive
description:
Expand Down
22 changes: 14 additions & 8 deletions lib/src/html_to_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class WidgetsHTMLDecoder {
final deltaAttributes = _getDeltaAttributesFromHtmlAttributes(
element.attributes,
);

attributes = attributes.merge(deltaAttributes);
if (deltaAttributes.decoration != null) {
decoration.add(deltaAttributes.decoration!);
Expand Down Expand Up @@ -457,7 +458,7 @@ class WidgetsHTMLDecoder {

// Function to parse a complex HTML element and return a widget
Future<Widget> _parseDeltaElement(dom.Element element) async {
final delta = <Widget>[];
final delta = <TextSpan>[];
final children = element.nodes.toList();
final childNodes = <Widget>[];

Expand All @@ -480,21 +481,24 @@ class WidgetsHTMLDecoder {
// Parse text and attributes within the paragraph
final attributes = _parserFormattingElementAttributes(child)
..merge(customStyles.paragraphStyle);
delta.add(Text(child.text.replaceAll(RegExp(r'\n+$'), ''),
delta.add(TextSpan(
text: child.text.replaceAll(RegExp(r'\n+$'), ''),
style: attributes));
}
}
} else {
// Process text nodes and add them to delta variable
delta.add(Text(child.text?.replaceAll(RegExp(r'\n+$'), '') ?? "",
delta.add(TextSpan(
text: child.text?.replaceAll(RegExp(r'\n+$'), '') ?? "",
style: TextStyle(font: font, fontFallback: fontFallback)
..merge(customStyles.paragraphStyle)));
}
}

// Create a column with wrapped text and child nodes
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [Wrap(children: delta), ...childNodes]);
return Wrap(
alignment: WrapAlignment.start,
children: [RichText(text: TextSpan(children: delta)), ...childNodes]);
}

// Utility function to convert a CSS string to a map of CSS properties
Expand Down Expand Up @@ -538,7 +542,9 @@ class WidgetsHTMLDecoder {
//apply different text decorations like undrline line through
final textDecorationStr = cssMap["text-decoration"];
if (textDecorationStr != null) {
style = style.merge(_assignTextDecorations(style, textDecorationStr));
style = style.copyWith(
decoration:
_assignTextDecorations(style, textDecorationStr).decoration);
}
//apply background color on text
final backgroundColorStr = cssMap["background-color"];
Expand All @@ -565,7 +571,7 @@ class WidgetsHTMLDecoder {
final textdecorations = <TextDecoration>[];
for (final d in decorations) {
if (d == "line-through") {
textdecorations.add(TextDecoration.overline);
textdecorations.add(TextDecoration.lineThrough);
} else if (d == "underline") {
textdecorations.add(TextDecoration.underline);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: htmltopdfwidgets
description: Htmlt to pdf widgets library convert html text to pdf widgets
version: 0.0.9+1
version: 0.0.9+2
homepage: https://github.com/alihassan143/htmltopdfwidgets

environment:
Expand Down

0 comments on commit 7f05fdd

Please sign in to comment.