MCPcopy
hub / github.com/golang/net / addFormattingElement

Method addFormattingElement

html/parse.go:347–387  ·  view source on GitHub ↗

Section 12.2.4.3.

()

Source from the content-addressed store, hash-verified

345
346// Section 12.2.4.3.
347func (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
357findIdenticalElements:
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.
390func (p *parser) clearActiveFormattingElements() {

Callers 1

inBodyIMFunction · 0.80

Calls 4

addElementMethod · 0.95
topMethod · 0.95
EqualMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected