@@ -217,6 +217,7 @@ class HtmlRichTextParser extends StatelessWidget {
217217 "time" ,
218218 "span" ,
219219 "big" ,
220+ "sub" ,
220221 ];
221222
222223 // specialty elements require unique handling
@@ -519,6 +520,13 @@ class HtmlRichTextParser extends StatelessWidget {
519520 childStyle = childStyle.merge (
520521 TextStyle (backgroundColor: Colors .yellow, color: Colors .black));
521522 break ;
523+ case "sub" :
524+ childStyle = childStyle.merge (
525+ TextStyle (
526+ fontSize: childStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR ,
527+ ),
528+ );
529+ break ;
522530 case "del" :
523531 case "s" :
524532 case "strike" :
@@ -730,6 +738,18 @@ class HtmlRichTextParser extends StatelessWidget {
730738 case "img" :
731739 if (showImages) {
732740 if (node.attributes['src' ] != null ) {
741+
742+ final width = imageProperties? .width ??
743+ ((node.attributes['width' ] != null )
744+ ? double .tryParse (node.attributes['width' ])
745+ : null
746+ );
747+ final height = imageProperties? .height ??
748+ ((node.attributes['height' ] != null )
749+ ? double .tryParse (node.attributes['height' ])
750+ : null
751+ );
752+
733753 if (node.attributes['src' ].startsWith ("data:image" ) &&
734754 node.attributes['src' ].contains ("base64," )) {
735755 precacheImage (
@@ -739,20 +759,14 @@ class HtmlRichTextParser extends StatelessWidget {
739759 ),
740760 ),
741761 buildContext,
742- onError: onImageError,
762+ onError: onImageError ?? (_,__) {} ,
743763 );
744764 parseContext.rootWidgetList.add (GestureDetector (
745765 child: Image .memory (
746766 base64.decode (
747767 node.attributes['src' ].split ("base64," )[1 ].trim ()),
748- width: imageProperties? .width ??
749- ((node.attributes['width' ] != null )
750- ? double .tryParse (node.attributes['width' ])
751- : null ),
752- height: imageProperties? .height ??
753- ((node.attributes['height' ] != null )
754- ? double .tryParse (node.attributes['height' ])
755- : null ),
768+ width: (width ?? - 1 ) > 0 ? width: null ,
769+ height: (height ?? - 1 ) > 0 ? width: null ,
756770 scale: imageProperties? .scale ?? 1.0 ,
757771 matchTextDirection:
758772 imageProperties? .matchTextDirection ?? false ,
@@ -780,19 +794,30 @@ class HtmlRichTextParser extends StatelessWidget {
780794 precacheImage (
781795 NetworkImage (node.attributes['src' ]),
782796 buildContext,
783- onError: onImageError,
797+ onError: onImageError ?? (_,__) {} ,
784798 );
785799 parseContext.rootWidgetList.add (GestureDetector (
786800 child: Image .network (
787801 node.attributes['src' ],
788- width: imageProperties? .width ??
789- ((node.attributes['width' ] != null )
790- ? double .parse (node.attributes['width' ])
791- : null ),
792- height: imageProperties? .height ??
793- ((node.attributes['height' ] != null )
794- ? double .parse (node.attributes['height' ])
795- : null ),
802+ frameBuilder: (context, child, frame, _) {
803+ if (node.attributes['alt' ] != null && frame == null ) {
804+ return BlockText (
805+ child: RichText (
806+ textAlign: TextAlign .center,
807+ text: TextSpan (
808+ text: node.attributes['alt' ],
809+ style: nextContext.childStyle,
810+ ),
811+ )
812+ );
813+ }
814+ if (frame != null ) {
815+ return child;
816+ }
817+ return Container ();
818+ },
819+ width: (width ?? - 1 ) > 0 ? width: null ,
820+ height: (height ?? - 1 ) > 0 ? height: null ,
796821 scale: imageProperties? .scale ?? 1.0 ,
797822 matchTextDirection:
798823 imageProperties? .matchTextDirection ?? false ,
@@ -817,20 +842,6 @@ class HtmlRichTextParser extends StatelessWidget {
817842 },
818843 ));
819844 }
820- if (node.attributes['alt' ] != null ) {
821- parseContext.rootWidgetList.add (BlockText (
822- shrinkToFit: shrinkToFit,
823- margin:
824- EdgeInsets .symmetric (horizontal: 0.0 , vertical: 10.0 ),
825- padding: EdgeInsets .all (0.0 ),
826- child: RichText (
827- textAlign: TextAlign .center,
828- text: TextSpan (
829- text: node.attributes['alt' ],
830- style: nextContext.childStyle,
831- children: < TextSpan > [],
832- ))));
833- }
834845 }
835846 }
836847 break ;
@@ -955,39 +966,11 @@ class HtmlRichTextParser extends StatelessWidget {
955966 }
956967 }
957968
958- Paint _getPaint (Color color) {
959- Paint paint = new Paint ();
960- paint.color = color;
961- return paint;
962- }
963-
964969 String condenseHtmlWhitespace (String stringToTrim) {
965970 stringToTrim = stringToTrim.replaceAll ("\n " , " " );
966971 while (stringToTrim.indexOf (" " ) != - 1 ) {
967972 stringToTrim = stringToTrim.replaceAll (" " , " " );
968973 }
969974 return stringToTrim;
970975 }
971-
972- bool _isNotFirstBreakTag (dom.Node node) {
973- int index = node.parentNode.nodes.indexOf (node);
974- if (index == 0 ) {
975- if (node.parentNode == null ) {
976- return false ;
977- }
978- return _isNotFirstBreakTag (node.parentNode);
979- } else if (node.parentNode.nodes[index - 1 ] is dom.Element ) {
980- if ((node.parentNode.nodes[index - 1 ] as dom.Element ).localName == "br" ) {
981- return true ;
982- }
983- return false ;
984- } else if (node.parentNode.nodes[index - 1 ] is dom.Text ) {
985- if ((node.parentNode.nodes[index - 1 ] as dom.Text ).text.trim () == "" ) {
986- return _isNotFirstBreakTag (node.parentNode.nodes[index - 1 ]);
987- } else {
988- return false ;
989- }
990- }
991- return false ;
992- }
993976}
0 commit comments