Skip to content

Commit 9ed5331

Browse files
authored
Merge pull request Sub6Resources#315 from JacobWrenn/master
Add support for list-style-position css attribute
2 parents 936de77 + c4d7138 commit 9ed5331

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

lib/html_parser.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,19 +267,24 @@ class HtmlParser extends StatelessWidget {
267267
style: tree.style,
268268
shrinkWrap: context.parser.shrinkWrap,
269269
child: Stack(
270-
children: <Widget>[
271-
PositionedDirectional(
272-
width: 30, //TODO derive this from list padding.
273-
start: 0,
274-
child: Text('${newContext.style.markerContent}\t',
275-
textAlign: TextAlign.end,
276-
style: newContext.style.generateTextStyle()),
277-
),
270+
children: [
271+
if (tree.style?.listStylePosition == ListStylePosition.OUTSIDE || tree.style?.listStylePosition == null)
272+
PositionedDirectional(
273+
width: 30, //TODO derive this from list padding.
274+
start: 0,
275+
child: Text('${newContext.style.markerContent}\t',
276+
textAlign: TextAlign.right,
277+
style: newContext.style.generateTextStyle()),
278+
),
278279
Padding(
279280
padding: EdgeInsetsDirectional.only(
280281
start: 30), //TODO derive this from list padding.
281282
child: StyledText(
282283
textSpan: TextSpan(
284+
text: (tree.style?.listStylePosition ==
285+
ListStylePosition.INSIDE)
286+
? '${newContext.style.markerContent}\t'
287+
: null,
283288
children: tree.children
284289
?.map((tree) => parseTree(newContext, tree))
285290
?.toList() ??

lib/style.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ class Style {
7777
/// Default: ListStyleType.DISC
7878
ListStyleType listStyleType;
7979

80+
/// CSS attribute "`list-style-position`"
81+
///
82+
/// Inherited: yes,
83+
/// Default: ListStylePosition.OUTSIDE
84+
ListStylePosition listStylePosition;
85+
8086
/// CSS attribute "`padding`"
8187
///
8288
/// Inherited: no,
@@ -183,6 +189,7 @@ class Style {
183189
this.lineHeight,
184190
this.letterSpacing,
185191
this.listStyleType,
192+
this.listStylePosition,
186193
this.padding,
187194
this.margin,
188195
this.textAlign,
@@ -251,6 +258,7 @@ class Style {
251258
lineHeight: other.lineHeight,
252259
letterSpacing: other.letterSpacing,
253260
listStyleType: other.listStyleType,
261+
listStylePosition: other.listStylePosition,
254262
padding: other.padding,
255263
//TODO merge EdgeInsets
256264
margin: other.margin,
@@ -288,6 +296,7 @@ class Style {
288296
fontWeight: child.fontWeight ?? fontWeight,
289297
letterSpacing: child.letterSpacing ?? letterSpacing,
290298
listStyleType: child.listStyleType ?? listStyleType,
299+
listStylePosition: child.listStylePosition ?? listStylePosition,
291300
textAlign: child.textAlign ?? textAlign,
292301
textShadow: child.textShadow ?? textShadow,
293302
whiteSpace: child.whiteSpace ?? whiteSpace,
@@ -309,6 +318,7 @@ class Style {
309318
double lineHeight,
310319
double letterSpacing,
311320
ListStyleType listStyleType,
321+
ListStylePosition listStylePosition,
312322
EdgeInsets padding,
313323
EdgeInsets margin,
314324
TextAlign textAlign,
@@ -341,6 +351,7 @@ class Style {
341351
lineHeight: lineHeight ?? this.lineHeight,
342352
letterSpacing: letterSpacing ?? this.letterSpacing,
343353
listStyleType: listStyleType ?? this.listStyleType,
354+
listStylePosition: listStylePosition ?? this.listStylePosition,
344355
padding: padding ?? this.padding,
345356
margin: margin ?? this.margin,
346357
textAlign: textAlign ?? this.textAlign,
@@ -421,6 +432,11 @@ enum ListStyleType {
421432
DECIMAL,
422433
}
423434

435+
enum ListStylePosition {
436+
OUTSIDE,
437+
INSIDE,
438+
}
439+
424440
enum VerticalAlign {
425441
BASELINE,
426442
SUB,

0 commit comments

Comments
 (0)