addText adds text to the preceding node if it is a text node, or else it calls addChild with a new text node.
(text string)
| 302 | // addText adds text to the preceding node if it is a text node, or else it |
| 303 | // calls addChild with a new text node. |
| 304 | func (p *parser) addText(text string) { |
| 305 | if text == "" { |
| 306 | return |
| 307 | } |
| 308 | |
| 309 | if p.shouldFosterParent() { |
| 310 | p.fosterParent(&Node{ |
| 311 | Type: TextNode, |
| 312 | Data: text, |
| 313 | }) |
| 314 | return |
| 315 | } |
| 316 | |
| 317 | t := p.top() |
| 318 | if n := t.LastChild; n != nil && n.Type == TextNode { |
| 319 | n.Data += text |
| 320 | return |
| 321 | } |
| 322 | p.addChild(&Node{ |
| 323 | Type: TextNode, |
| 324 | Data: text, |
| 325 | }) |
| 326 | } |
| 327 | |
| 328 | func attrCompare(a, b Attribute) int { |
| 329 | return cmp.Or( |
no test coverage detected