Section 12.2.4.3.
()
| 345 | |
| 346 | // Section 12.2.4.3. |
| 347 | func (p *parser) addFormattingElement() { |
| 348 | tagAtom, attr := p.tok.DataAtom, p.tok.Attr |
| 349 | p.addElement() |
| 350 | |
| 351 | // In order to optimize the search, we need the attributes to be sorted, so we |
| 352 | // can just use slices.Equal. |
| 353 | slices.SortFunc(attr, attrCompare) |
| 354 | |
| 355 | // Implement the Noah's Ark clause, but with three per family instead of two. |
| 356 | identicalElements := 0 |
| 357 | findIdenticalElements: |
| 358 | for i := len(p.afe) - 1; i >= 0; i-- { |
| 359 | n := p.afe[i] |
| 360 | if n.Type == scopeMarkerNode { |
| 361 | break |
| 362 | } |
| 363 | if n.Type != ElementNode { |
| 364 | continue |
| 365 | } |
| 366 | if n.Namespace != "" { |
| 367 | continue |
| 368 | } |
| 369 | if n.DataAtom != tagAtom { |
| 370 | continue |
| 371 | } |
| 372 | if !slices.Equal(n.Attr, attr) { |
| 373 | continue findIdenticalElements |
| 374 | } |
| 375 | |
| 376 | identicalElements++ |
| 377 | if identicalElements >= 3 { |
| 378 | p.afe.remove(n) |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | // Sort the attributes to optimize future identical-element searches. |
| 383 | top := p.top() |
| 384 | slices.SortFunc(top.Attr, attrCompare) |
| 385 | |
| 386 | p.afe = append(p.afe, top) |
| 387 | } |
| 388 | |
| 389 | // Section 12.2.4.3. |
| 390 | func (p *parser) clearActiveFormattingElements() { |
no test coverage detected