diff --git a/example/lib/main.dart b/example/lib/main.dart index 665fc768f7..47fafc19f2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -42,6 +42,8 @@ const htmlData = r"""  is Japanese Kanji.

+

Support for maxLines:

+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec vestibulum sapien feugiat lorem tempor, id porta orci elementum. Fusce sed justo id arcu egestas congue. Fusce tincidunt lacus ipsum, in imperdiet felis ultricies eu. In ullamcorper risus felis, ac maximus dui bibendum vel. Integer ligula tortor, facilisis eu mauris ut, ultrices hendrerit ex. Donec scelerisque massa consequat, eleifend mauris eu, mollis dui. Donec placerat augue tortor, et tincidunt quam tempus non. Quisque sagittis enim nisi, eu condimentum lacus egestas ac. Nam facilisis luctus ipsum, at aliquam urna fermentum a. Quisque tortor dui, faucibus in ante eget, pellentesque mattis nibh. In augue dolor, euismod vitae eleifend nec, tempus vel urna. Donec vitae augue accumsan ligula fringilla ultrices et vel ex.

Support for sub/sup

Solve for xn: log2(x2+n) = 93

One of the most common equations in all of physics is
E=mc2.

@@ -261,30 +263,36 @@ class _MyHomePageState extends State { padding: EdgeInsets.all(6), alignment: Alignment.topLeft, ), + 'h5': Style(maxLines: 2, textOverflow: TextOverflow.ellipsis), }, customRender: { "table": (context, child) { return SingleChildScrollView( scrollDirection: Axis.horizontal, - child: (context.tree as TableLayoutElement).toWidget(context), + child: + (context.tree as TableLayoutElement).toWidget(context), ); } }, customImageRenders: { - networkSourceMatcher(domains: ["flutter.dev"]): (context, attributes, element) { + networkSourceMatcher(domains: ["flutter.dev"]): + (context, attributes, element) { return FlutterLogo(size: 36); }, - networkSourceMatcher(domains: ["mydomain.com"]): networkImageRender( + networkSourceMatcher(domains: ["mydomain.com"]): + networkImageRender( headers: {"Custom-Header": "some-value"}, altWidget: (alt) => Text(alt ?? ""), loadingWidget: () => Text("Loading..."), ), // On relative paths starting with /wiki, prefix with a base url - (attr, _) => attr["src"] != null && attr["src"]!.startsWith("/wiki"): + (attr, _) => + attr["src"] != null && attr["src"]!.startsWith("/wiki"): networkImageRender( mapUrl: (url) => "https://upload.wikimedia.org" + url!), // Custom placeholder image for broken links - networkSourceMatcher(): networkImageRender(altWidget: (_) => FlutterLogo()), + networkSourceMatcher(): + networkImageRender(altWidget: (_) => FlutterLogo()), }, onLinkTap: (url, _, __, ___) { print("Opening $url..."); diff --git a/lib/html_parser.dart b/lib/html_parser.dart index 17f1764ca2..a3ed4cc88f 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -834,6 +834,8 @@ class StyledText extends StatelessWidget { textAlign: style.textAlign, textDirection: style.direction, textScaleFactor: textScaleFactor, + maxLines: style.maxLines, + overflow: style.textOverflow, ), ); } diff --git a/lib/src/widgets/iframe_web.dart b/lib/src/widgets/iframe_web.dart index a70de148da..1d2322feb7 100644 --- a/lib/src/widgets/iframe_web.dart +++ b/lib/src/widgets/iframe_web.dart @@ -37,14 +37,14 @@ class IframeContentElement extends ReplacedElement { //not actually an error ui.platformViewRegistry.registerViewFactory(createdViewId, (int viewId) => iframe); return Container( - width: width ?? (height ?? 150) * 2, - height: height ?? (width ?? 300) / 2, - child: Directionality( - textDirection: TextDirection.ltr, - child: HtmlElementView( - viewType: createdViewId, - ) - ) + width: width ?? (height ?? 150) * 2, + height: height ?? (width ?? 300) / 2, + child: Directionality( + textDirection: TextDirection.ltr, + child: HtmlElementView( + viewType: createdViewId, + ) + ) ); } } \ No newline at end of file diff --git a/lib/style.dart b/lib/style.dart index e4988f15dc..3ac5ae0e33 100644 --- a/lib/style.dart +++ b/lib/style.dart @@ -175,6 +175,20 @@ class Style { Alignment? alignment; String? markerContent; + /// MaxLine + /// + /// + /// + /// + int? maxLines; + + /// TextOverflow + /// + /// + /// + /// + TextOverflow? textOverflow; + Style({ this.backgroundColor = Colors.transparent, this.color, @@ -207,6 +221,8 @@ class Style { this.border, this.alignment, this.markerContent, + this.maxLines, + this.textOverflow, }) { if (this.alignment == null && (display == Display.BLOCK || display == Display.LIST_ITEM)) { @@ -278,6 +294,9 @@ class Style { //TODO merge border alignment: other.alignment, markerContent: other.markerContent, + + maxLines: other.maxLines, + textOverflow: other.textOverflow, ); } @@ -313,6 +332,8 @@ class Style { textShadow: child.textShadow ?? textShadow, whiteSpace: child.whiteSpace ?? whiteSpace, wordSpacing: child.wordSpacing ?? wordSpacing, + maxLines: child.maxLines ?? maxLines, + textOverflow: child.textOverflow ?? textOverflow, ); } @@ -348,6 +369,8 @@ class Style { Border? border, Alignment? alignment, String? markerContent, + int? maxLines, + TextOverflow? textOverflow, bool? beforeAfterNull, }) { return Style( @@ -383,6 +406,8 @@ class Style { border: border ?? this.border, alignment: alignment ?? this.alignment, markerContent: markerContent ?? this.markerContent, + maxLines: maxLines ?? this.maxLines, + textOverflow: textOverflow ?? this.textOverflow, ); }