File tree Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Expand file tree Collapse file tree 2 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -520,13 +520,19 @@ class HtmlParser extends StatelessWidget {
520
520
}
521
521
parentAfterText = parentAfter? .text ?? " " ;
522
522
}
523
+ if (tree.text? .contains ("Linking" ) ?? false ) {
524
+ print (keepLeadingSpace.data);
525
+ print (tree.text);
526
+ print (BLOCK_ELEMENTS .contains (tree.element? .localName ?? "" ));
527
+ }
523
528
/// If the text is the first element in the current tree node list, it
524
- /// starts with a whitespace, it isn't a line break, and we don't need to
525
- /// keep the whitespace , delete it.
529
+ /// starts with a whitespace, it isn't a line break, and either the
530
+ /// whitespace is unnecessary or it is a block element , delete it.
526
531
if (textIndex < 1
527
532
&& tree.text! .startsWith (' ' )
528
533
&& tree.element? .localName != "br"
529
- && ! keepLeadingSpace.data
534
+ && (! keepLeadingSpace.data
535
+ || BLOCK_ELEMENTS .contains (tree.element? .localName ?? "" ))
530
536
) {
531
537
tree.text = tree.text! .replaceFirst (' ' , '' );
532
538
}
Original file line number Diff line number Diff line change @@ -70,6 +70,40 @@ const STYLED_ELEMENTS = [
70
70
"ul" ,
71
71
];
72
72
73
+ const BLOCK_ELEMENTS = [
74
+ "article" ,
75
+ "aside" ,
76
+ "blockquote" ,
77
+ "body" ,
78
+ "center" ,
79
+ "dd" ,
80
+ "div" ,
81
+ "dl" ,
82
+ "dt" ,
83
+ "figcaption" ,
84
+ "figure" ,
85
+ "footer" ,
86
+ "h1" ,
87
+ "h2" ,
88
+ "h3" ,
89
+ "h4" ,
90
+ "h5" ,
91
+ "h6" ,
92
+ "header" ,
93
+ "hr" ,
94
+ "html" ,
95
+ "li" ,
96
+ "main" ,
97
+ "nav" ,
98
+ "noscript" ,
99
+ "ol" ,
100
+ "p" ,
101
+ "pre" ,
102
+ "section" ,
103
+ "summary" ,
104
+ "ul" ,
105
+ ];
106
+
73
107
const INTERACTABLE_ELEMENTS = [
74
108
"a" ,
75
109
];
You can’t perform that action at this time.
0 commit comments