wrapNonLIListChildren scans the direct children of an / and wraps any element that is not in a fresh . HTML spec is explicit that ` ` / ` ` may only contain ` ` (plus optional ` ` / ` `); browsers parse a non- child by silently hoisting it out of the lis
(list *xhtml.Node, rep *Report)
| 563 | // and we don't want to silently mutate user-authored content beyond the |
| 564 | // minimum needed to satisfy the structural rule. |
| 565 | func wrapNonLIListChildren(list *xhtml.Node, rep *Report) { |
| 566 | child := list.FirstChild |
| 567 | for child != nil { |
| 568 | next := child.NextSibling |
| 569 | if child.Type == xhtml.ElementNode && strings.ToLower(child.Data) != "li" { |
| 570 | // Wrap the offending element in a fresh <li>. The <li> inherits |
| 571 | // no attributes — the wrapped element keeps its own styling so |
| 572 | // nested-list indentation declared on the inner <ul>/<ol> |
| 573 | // survives. The recursive walk re-enters the new <li> later to |
| 574 | // stamp the native list-item style on it. |
| 575 | li := &xhtml.Node{ |
| 576 | Type: xhtml.ElementNode, |
| 577 | Data: "li", |
| 578 | DataAtom: atom.Li, |
| 579 | } |
| 580 | rep.Applied = append(rep.Applied, Finding{ |
| 581 | RuleID: RuleListDirectChildNonLI, |
| 582 | Severity: SeverityWarning, |
| 583 | TagOrAttr: child.Data, |
| 584 | Excerpt: excerptOf(child), |
| 585 | Hint: "Wrapped non-<li> child of <" + list.Data + "> in a synthetic <li> (HTML spec requires <ul>/<ol> children to be <li>)", |
| 586 | }) |
| 587 | list.InsertBefore(li, child) |
| 588 | list.RemoveChild(child) |
| 589 | li.AppendChild(child) |
| 590 | } |
| 591 | child = next |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | // hasInlineStyleProp reports whether the given style="..." string already |
| 596 | // declares the named property. Lookup is case-insensitive on the property |
no test coverage detected