@@ -66,12 +66,12 @@ class HtmlParser extends StatelessWidget {
6666 return RichText (text: parsedTree);
6767 }
6868
69- /// [parseHTML] converts a string to a DOM document using the dart `html` library.
69+ /// [parseHTML] converts a string of HTML to a DOM document using the dart `html` library.
7070 static dom.Document parseHTML (String data) {
7171 return htmlparser.parse (data);
7272 }
7373
74- ///TODO document
74+ /// [parseCSS] converts a string of CSS to a CSS stylesheet using the dart `csslib` library.
7575 static css.StyleSheet parseCSS (String data) {
7676 return cssparser.parse (data);
7777 }
@@ -92,7 +92,10 @@ class HtmlParser extends StatelessWidget {
9292 return tree;
9393 }
9494
95- ///TODO document
95+ /// [_recursiveLexer] is the recursive worker function for [lexDomTree] .
96+ ///
97+ /// It runs the parse functions of every type of
98+ /// element and returns a [StyledElement] tree representing the element.
9699 static StyledElement _recursiveLexer (
97100 dom.Node node, List <String > customRenderTags, List <String > blacklistedElements) {
98101 List <StyledElement > children = List <StyledElement >();
@@ -156,7 +159,7 @@ class HtmlParser extends StatelessWidget {
156159 }
157160
158161 /// [applyCustomStyles] applies the [Style] objects passed into the [Html]
159- /// widget onto the [StyledElement] tree.
162+ /// widget onto the [StyledElement] tree, no cascading of styles is done at this point .
160163 StyledElement _applyCustomStyles (StyledElement tree) {
161164 if (style == null ) return tree;
162165 style.forEach ((key, style) {
@@ -173,6 +176,8 @@ class HtmlParser extends StatelessWidget {
173176 return tree;
174177 }
175178
179+ /// [_cascadeStyles] cascades all of the inherited styles down the tree, applying them to each
180+ /// child that doesn't specify a different style.
176181 StyledElement _cascadeStyles (StyledElement tree) {
177182 tree.children? .forEach ((child) {
178183 child.style = tree.style.copyOnlyInherited (child.style);
@@ -197,6 +202,9 @@ class HtmlParser extends StatelessWidget {
197202 }
198203
199204 /// [parseTree] converts a tree of [StyledElement] s to an [InlineSpan] tree.
205+ ///
206+ /// [parseTree] is responsible for handling the [customRender] parameter and
207+ /// deciding what different `Style.display` options look like as Widgets.
200208 InlineSpan parseTree (RenderContext context, StyledElement tree) {
201209 // Merge this element's style into the context so that children
202210 // inherit the correct style
@@ -347,14 +355,18 @@ class HtmlParser extends StatelessWidget {
347355 return tree;
348356 }
349357
350- ///TODO document
358+ /// [_processInlineWhitespace] is responsible for removing redundant whitespace
359+ /// between and among inline elements. It does so by creating a boolean [Context]
360+ /// and passing it to the [_processInlineWhitespaceRecursive] function.
351361 static StyledElement _processInlineWhitespace (StyledElement tree) {
352362 final whitespaceParsingContext = Context (false );
353363 tree = _processInlineWhitespaceRecursive (tree, whitespaceParsingContext);
354364 return tree;
355365 }
356366
357- ///TODO document
367+ /// [_processInlineWhitespaceRecursive] analyzes the whitespace between and among different
368+ /// inline elements, and replaces any instance of two or more spaces with a single space, according
369+ /// to the w3's HTML whitespace processing specification linked to above.
358370 static StyledElement _processInlineWhitespaceRecursive (StyledElement tree, Context <bool > wpc) {
359371 if (tree.style.display == Display .BLOCK ) {
360372 wpc.data = false ;
@@ -394,27 +406,16 @@ class HtmlParser extends StatelessWidget {
394406 }
395407
396408 /// [processListCharacters] adds list characters to the front of all list items.
397- /// TODO document better
409+ ///
410+ /// The function uses the [_processListCharactersRecursive] function to do most of its work.
398411 static StyledElement _processListCharacters (StyledElement tree) {
399- // if (tree.name == "ol" || tree.name == "ul") {
400- // for (int i = 0; i < tree.children?.length; i++) {
401- // if (tree.children[i].name == "li") {
402- // switch(tree.style.listStyleType) {
403- // case ListStyleType.DISC:
404- // tree.children[i].style.markerContent = '•';
405- // break;
406- // case ListStyleType.DECIMAL:
407- // tree.children[i].style.markerContent = '${i + 1}.';
408- // break;
409- // }}
410- // }
411- // }
412- // tree.children?.forEach(_processListCharacters);
413412 final olStack = ListQueue <Context <int >>();
414413 tree = _processListCharactersRecursive (tree, olStack);
415414 return tree;
416415 }
417416
417+ /// [_processListCharactersRecursive] uses a Stack of integers to properly number and
418+ /// bullet all list items according to the [ListStyleType] they have been given.
418419 static StyledElement _processListCharactersRecursive (
419420 StyledElement tree, ListQueue <Context <int >> olStack) {
420421 if (tree.name == 'ol' ) {
@@ -439,7 +440,9 @@ class HtmlParser extends StatelessWidget {
439440 return tree;
440441 }
441442
442- /// TODO document better
443+ /// [_processBeforesAndAfters] adds text content to the beginning and end of
444+ /// the list of the trees children according to the `before` and `after` Style
445+ /// properties.
443446 static StyledElement _processBeforesAndAfters (StyledElement tree) {
444447 if (tree.style? .before != null ) {
445448 tree.children.insert (0 , TextContentElement (text: tree.style.before));
@@ -550,6 +553,9 @@ class HtmlParser extends StatelessWidget {
550553 }
551554
552555 /// [removeEmptyElements] recursively removes empty elements.
556+ ///
557+ /// An empty element is any [EmptyContentElement] , any empty [TextContentElement] ,
558+ /// or any block-level [TextContentElement] that contains only whitespace.
553559 static StyledElement _removeEmptyElements (StyledElement tree) {
554560 List <StyledElement > toRemove = new List <StyledElement >();
555561 tree.children? .forEach ((child) {
@@ -561,7 +567,6 @@ class HtmlParser extends StatelessWidget {
561567 child.style.whiteSpace != WhiteSpace .PRE &&
562568 tree.style.display == Display .BLOCK &&
563569 child.text.trim ().isEmpty) {
564- //TODO should this be moved to the whitespace functions?
565570 toRemove.add (child);
566571 } else {
567572 _removeEmptyElements (child);
@@ -572,6 +577,8 @@ class HtmlParser extends StatelessWidget {
572577 return tree;
573578 }
574579
580+ /// [_processFontSize] changes percent-based font sizes (negative numbers in this implementation)
581+ /// to pixel-based font sizes.
575582 static StyledElement _processFontSize (StyledElement tree) {
576583 double parentFontSize = tree.style? .fontSize? .size ?? FontSize .medium.size;
577584
@@ -586,7 +593,10 @@ class HtmlParser extends StatelessWidget {
586593 }
587594}
588595
589- ///TODO document better
596+ /// The [RenderContext] is available when parsing the tree. It contains information
597+ /// about the [BuildContext] of the `Html` widget, contains the configuration available
598+ /// in the [HtmlParser] , and contains information about the [Style] of the current
599+ /// tree root.
590600class RenderContext {
591601 final BuildContext buildContext;
592602 final HtmlParser parser;
@@ -599,7 +609,10 @@ class RenderContext {
599609 });
600610}
601611
602- ///TODO document
612+ /// A [ContainerSpan] is a widget with an [InlineSpan] child or children.
613+ ///
614+ /// A [ContainerSpan] can have a border, background color, height, width, padding, and margin
615+ /// and can represent either an INLINE or BLOCK-level element.
603616class ContainerSpan extends StatelessWidget {
604617 final Widget child;
605618 final List <InlineSpan > children;
0 commit comments