Skip to content

Commit c15d499

Browse files
authored
Merge pull request Sub6Resources#596 from nguyenxdat/master
Support maxlines
2 parents e32e68a + 2857b20 commit c15d499

File tree

4 files changed

+48
-13
lines changed

4 files changed

+48
-13
lines changed

example/lib/main.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const htmlData = r"""
4242
</ruby>
4343
&nbsp;is Japanese Kanji.
4444
</p>
45+
<h3>Support for maxLines:</h3>
46+
<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>
4547
<h3>Support for <code>sub</code>/<code>sup</code></h3>
4648
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>
4749
<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>
@@ -261,30 +263,36 @@ class _MyHomePageState extends State<MyHomePage> {
261263
padding: EdgeInsets.all(6),
262264
alignment: Alignment.topLeft,
263265
),
266+
'h5': Style(maxLines: 2, textOverflow: TextOverflow.ellipsis),
264267
},
265268
customRender: {
266269
"table": (context, child) {
267270
return SingleChildScrollView(
268271
scrollDirection: Axis.horizontal,
269-
child: (context.tree as TableLayoutElement).toWidget(context),
272+
child:
273+
(context.tree as TableLayoutElement).toWidget(context),
270274
);
271275
}
272276
},
273277
customImageRenders: {
274-
networkSourceMatcher(domains: ["flutter.dev"]): (context, attributes, element) {
278+
networkSourceMatcher(domains: ["flutter.dev"]):
279+
(context, attributes, element) {
275280
return FlutterLogo(size: 36);
276281
},
277-
networkSourceMatcher(domains: ["mydomain.com"]): networkImageRender(
282+
networkSourceMatcher(domains: ["mydomain.com"]):
283+
networkImageRender(
278284
headers: {"Custom-Header": "some-value"},
279285
altWidget: (alt) => Text(alt ?? ""),
280286
loadingWidget: () => Text("Loading..."),
281287
),
282288
// On relative paths starting with /wiki, prefix with a base url
283-
(attr, _) => attr["src"] != null && attr["src"]!.startsWith("/wiki"):
289+
(attr, _) =>
290+
attr["src"] != null && attr["src"]!.startsWith("/wiki"):
284291
networkImageRender(
285292
mapUrl: (url) => "https://upload.wikimedia.org" + url!),
286293
// Custom placeholder image for broken links
287-
networkSourceMatcher(): networkImageRender(altWidget: (_) => FlutterLogo()),
294+
networkSourceMatcher():
295+
networkImageRender(altWidget: (_) => FlutterLogo()),
288296
},
289297
onLinkTap: (url, _, __, ___) {
290298
print("Opening $url...");

lib/html_parser.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,8 @@ class StyledText extends StatelessWidget {
834834
textAlign: style.textAlign,
835835
textDirection: style.direction,
836836
textScaleFactor: textScaleFactor,
837+
maxLines: style.maxLines,
838+
overflow: style.textOverflow,
837839
),
838840
);
839841
}

lib/src/widgets/iframe_web.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class IframeContentElement extends ReplacedElement {
3737
//not actually an error
3838
ui.platformViewRegistry.registerViewFactory(createdViewId, (int viewId) => iframe);
3939
return Container(
40-
width: width ?? (height ?? 150) * 2,
41-
height: height ?? (width ?? 300) / 2,
42-
child: Directionality(
43-
textDirection: TextDirection.ltr,
44-
child: HtmlElementView(
45-
viewType: createdViewId,
46-
)
47-
)
40+
width: width ?? (height ?? 150) * 2,
41+
height: height ?? (width ?? 300) / 2,
42+
child: Directionality(
43+
textDirection: TextDirection.ltr,
44+
child: HtmlElementView(
45+
viewType: createdViewId,
46+
)
47+
)
4848
);
4949
}
5050
}

lib/style.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ class Style {
175175
Alignment? alignment;
176176
String? markerContent;
177177

178+
/// MaxLine
179+
///
180+
///
181+
///
182+
///
183+
int? maxLines;
184+
185+
/// TextOverflow
186+
///
187+
///
188+
///
189+
///
190+
TextOverflow? textOverflow;
191+
178192
Style({
179193
this.backgroundColor = Colors.transparent,
180194
this.color,
@@ -207,6 +221,8 @@ class Style {
207221
this.border,
208222
this.alignment,
209223
this.markerContent,
224+
this.maxLines,
225+
this.textOverflow,
210226
}) {
211227
if (this.alignment == null &&
212228
(display == Display.BLOCK || display == Display.LIST_ITEM)) {
@@ -288,6 +304,9 @@ class Style {
288304
//TODO merge border
289305
alignment: other.alignment,
290306
markerContent: other.markerContent,
307+
308+
maxLines: other.maxLines,
309+
textOverflow: other.textOverflow,
291310
);
292311
}
293312

@@ -323,6 +342,8 @@ class Style {
323342
textShadow: child.textShadow ?? textShadow,
324343
whiteSpace: child.whiteSpace ?? whiteSpace,
325344
wordSpacing: child.wordSpacing ?? wordSpacing,
345+
maxLines: child.maxLines ?? maxLines,
346+
textOverflow: child.textOverflow ?? textOverflow,
326347
);
327348
}
328349

@@ -358,6 +379,8 @@ class Style {
358379
Border? border,
359380
Alignment? alignment,
360381
String? markerContent,
382+
int? maxLines,
383+
TextOverflow? textOverflow,
361384
bool? beforeAfterNull,
362385
}) {
363386
return Style(
@@ -393,6 +416,8 @@ class Style {
393416
border: border ?? this.border,
394417
alignment: alignment ?? this.alignment,
395418
markerContent: markerContent ?? this.markerContent,
419+
maxLines: maxLines ?? this.maxLines,
420+
textOverflow: textOverflow ?? this.textOverflow,
396421
);
397422
}
398423

0 commit comments

Comments
 (0)