Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const htmlData = r"""
</ruby>
&nbsp;is Japanese Kanji.
</p>
<h3>Support for maxLines:</h3>
<h5>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.</h5>
<h3>Support for <code>sub</code>/<code>sup</code></h3>
Solve for <var>x<sub>n</sub></var>: log<sub>2</sub>(<var>x</var><sup>2</sup>+<var>n</var>) = 9<sup>3</sup>
<p>One of the most <span>common</span> equations in all of physics is <br /><var>E</var>=<var>m</var><var>c</var><sup>2</sup>.</p>
Expand Down Expand Up @@ -261,30 +263,36 @@ class _MyHomePageState extends State<MyHomePage> {
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...");
Expand Down
2 changes: 2 additions & 0 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ class StyledText extends StatelessWidget {
textAlign: style.textAlign,
textDirection: style.direction,
textScaleFactor: textScaleFactor,
maxLines: style.maxLines,
overflow: style.textOverflow,
),
);
}
Expand Down
16 changes: 8 additions & 8 deletions lib/src/widgets/iframe_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
);
}
}
25 changes: 25 additions & 0 deletions lib/style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,20 @@ class Style {
Alignment? alignment;
String? markerContent;

/// MaxLine
///
///
///
///
int? maxLines;

/// TextOverflow
///
///
///
///
TextOverflow? textOverflow;

Style({
this.backgroundColor = Colors.transparent,
this.color,
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -278,6 +294,9 @@ class Style {
//TODO merge border
alignment: other.alignment,
markerContent: other.markerContent,

maxLines: other.maxLines,
textOverflow: other.textOverflow,
);
}

Expand Down Expand Up @@ -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,
);
}

Expand Down Expand Up @@ -348,6 +369,8 @@ class Style {
Border? border,
Alignment? alignment,
String? markerContent,
int? maxLines,
TextOverflow? textOverflow,
bool? beforeAfterNull,
}) {
return Style(
Expand Down Expand Up @@ -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,
);
}

Expand Down