Web Platform Atlas
EN⚡RUUA⚡DE⚡FR⚡ES⚡PL⚡PT⚡ZH⚡JA⚡
Каталог / HTML / Misnested tags: <b><p></b></p>

13.2.10.2 Misnested tags: <b><p></b></p>

Статический предпросмотр (RU): для MDN, WPT, глоссария и BYOK-перевода откройте интерактивный Атлас.
⚡ Открыть главу в Атласе

13.2.10.2 Misnested tags: <b><p></b></p>

Этот раздел является ненормативным.

A case similar to the previous one is the following:

<b>1<p>2</b>3</p>

Up to the "2" the parsing here is straightforward:

html

head

body

b

#text: 1

p

#text: 2

The interesting part is when the end tag token with the tag name "b" is parsed.

Before that token is seen, the stack of open elements has four elements on it: html, body, b, and p. The list of active formatting elements just has the one: b. The insertion mode is "in body".

Upon receiving the end tag token with the tag name "b", the "adoption agency algorithm" is invoked, as in the previous example. However, in this case, there is a furthest block, namely the p element. Thus, this time the adoption agency algorithm isn't skipped over.

The common ancestor is the body element. A conceptual "bookmark" marks the position of the b in the list of active formatting elements, but since that list has only one element in it, the bookmark won't have much effect.

As the algorithm progresses, node ends up set to the formatting element (b), and last node ends up set to the furthest block (p).

The last node gets appended (moved) to the common ancestor, so that the DOM looks like:

html

head

body

b

#text: 1

p

#text: 2

A new b element is created, and the children of the p element are moved to it:

html

head

body

b

#text: 1

p

b

#text: 2

Finally, the new b element is appended to the p element, so that the DOM looks like:

html

head

body

b

#text: 1

p

b

#text: 2

The b element is removed from the list of active formatting elements and the stack of open elements, so that when the "3" is parsed, it is appended to the p element:

html

head

body

b

#text: 1

p

b

#text: 2

#text: 3