@@ -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 }
0 commit comments