Skip to content

Commit 5e6a42d

Browse files
committed
links side changes
1 parent d517aac commit 5e6a42d

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 1.0.8
2+
* fix: Links get formatted but are not clickable in the PDF ([#35](https://github.com/alihassan143/htmltopdfwidgets/issues/35))
13
## 1.0.7
24
* fix nested child skipping issue fixed
35
## 1.0.6

lib/src/html_to_widgets.dart

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ class WidgetsHTMLDecoder {
104104
await _parserFormattingElementAttributes(domNode, baseTextStyle);
105105

106106
textAlign = attributes.$1;
107+
107108
delta.add(TextSpan(
108109
text: "${domNode.text.replaceAll(RegExp(r'\n+$'), '')} ",
109-
style: attributes.$2));
110+
style: attributes.$2,
111+
annotation: attributes.$3 == null
112+
? null
113+
: AnnotationUrl(attributes.$3!)));
110114
} else if (HTMLTags.specialElements.contains(localName)) {
111115
if (delta.isNotEmpty) {
112116
final newlist = List<TextSpan>.from(delta);
@@ -265,10 +269,11 @@ class WidgetsHTMLDecoder {
265269
}
266270

267271
//// Parses the attributes of a formatting element and returns a TextStyle.
268-
Future<(TextAlign?, TextStyle)> _parserFormattingElementAttributes(
272+
Future<(TextAlign?, TextStyle, String?)> _parserFormattingElementAttributes(
269273
dom.Element element, TextStyle baseTextStyle) async {
270274
final localName = element.localName;
271275
TextAlign? textAlign;
276+
String? link;
272277
TextStyle attributes = baseTextStyle;
273278
final List<TextDecoration> decoration = [];
274279
switch (localName) {
@@ -320,6 +325,7 @@ class WidgetsHTMLDecoder {
320325
attributes = attributes
321326
.copyWith(color: PdfColors.blue)
322327
.merge(customStyles.linkStyle);
328+
link = href;
323329
}
324330
break;
325331

@@ -341,12 +347,16 @@ class WidgetsHTMLDecoder {
341347
decoration.add(nattributes.$2.decoration!);
342348
}
343349
textAlign = nattributes.$1;
350+
if (nattributes.$3 != null) {
351+
link = nattributes.$3;
352+
}
344353
}
345354

346355
///will combine style get from the children
347356
return (
348357
textAlign,
349-
attributes.copyWith(decoration: TextDecoration.combine(decoration))
358+
attributes.copyWith(decoration: TextDecoration.combine(decoration)),
359+
link
350360
);
351361
}
352362

@@ -445,7 +455,13 @@ class WidgetsHTMLDecoder {
445455
} else if (HTMLTags.formattingElements.contains(localName)) {
446456
final attributes =
447457
await _parserFormattingElementAttributes(element, baseTextStyle);
448-
458+
result.add(RichText(
459+
text: TextSpan(
460+
text: element.text,
461+
style: attributes.$2,
462+
annotation: attributes.$3 == null
463+
? null
464+
: AnnotationUrl(attributes.$3!))));
449465
result.add(Text(element.text, style: attributes.$2));
450466
} else if (HTMLTags.specialElements.contains(localName)) {
451467
/// Handle special elements (e.g., headings, lists, images)
@@ -484,7 +500,12 @@ class WidgetsHTMLDecoder {
484500
final attributes =
485501
await _parserFormattingElementAttributes(child, baseTextStyle);
486502
textAlign = attributes.$1;
487-
delta.add(TextSpan(text: child.text, style: attributes.$2));
503+
504+
delta.add(TextSpan(
505+
text: child.text,
506+
style: attributes.$2,
507+
annotation:
508+
attributes.$3 == null ? null : AnnotationUrl(attributes.$3!)));
488509
} else {
489510
delta.add(TextSpan(text: child.text, style: baseTextStyle));
490511
}
@@ -670,7 +691,10 @@ class WidgetsHTMLDecoder {
670691

671692
delta.add(TextSpan(
672693
text: "${child.text.replaceAll(RegExp(r'\n+$'), ' ')} ",
673-
style: attributes.$2.merge(customStyles.paragraphStyle)));
694+
style: attributes.$2.merge(customStyles.paragraphStyle),
695+
annotation: attributes.$3 == null
696+
? null
697+
: AnnotationUrl(attributes.$3!)));
674698
}
675699
}
676700
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: htmltopdfwidgets
22
description: A Dart package that converts HTML and Markdown rich text content into high-quality PDF widgets. Simplify the creation of PDF documents by seamlessly transforming your structured text content into printable, professional PDFs. Perfect for generating reports, invoices, and more!
3-
version: 1.0.7
3+
version: 1.0.8
44
homepage: https://github.com/alihassan143/htmltopdfwidgets
55

66
environment:

0 commit comments

Comments
 (0)