(
/** @type {string} */ subject,
/** @type {TagPos | null} */ pos
)
| 5374 | |
| 5375 | // ---------- adoption agency algorithm ---------- |
| 5376 | const adoptionAgency = ( |
| 5377 | /** @type {string} */ subject, |
| 5378 | /** @type {TagPos | null} */ pos |
| 5379 | ) => { |
| 5380 | // step 1 |
| 5381 | const c = cur(); |
| 5382 | if ( |
| 5383 | c.namespace === NS_HTML && |
| 5384 | c.tagName === subject && |
| 5385 | !afe.some((e) => !e.marker && e.element === c) |
| 5386 | ) { |
| 5387 | open.pop(); |
| 5388 | return true; |
| 5389 | } |
| 5390 | let outer = 0; |
| 5391 | while (outer < 8) { |
| 5392 | outer++; |
| 5393 | // find formatting element |
| 5394 | let fmtIdx = -1; |
| 5395 | for (let i = afe.length - 1; i >= 0; i--) { |
| 5396 | if (afe[i].marker) break; |
| 5397 | if ( |
| 5398 | afeEl(afe[i]).tagName === subject && |
| 5399 | afeEl(afe[i]).namespace === NS_HTML |
| 5400 | ) { |
| 5401 | fmtIdx = i; |
| 5402 | break; |
| 5403 | } |
| 5404 | } |
| 5405 | if (fmtIdx === -1) return false; // act as any other end tag |
| 5406 | const fmt = afeEl(afe[fmtIdx]); |
| 5407 | const openIdx = open.indexOf(fmt); |
| 5408 | if (openIdx === -1) { |
| 5409 | afe.splice(fmtIdx, 1); |
| 5410 | return true; |
| 5411 | } |
| 5412 | if (!inScopeEl(fmt)) return true; // parse error, ignore |
| 5413 | // step: furthest block |
| 5414 | let furthestIdx = -1; |
| 5415 | for (let i = openIdx + 1; i < open.length; i++) { |
| 5416 | if (isSpecial(open[i])) { |
| 5417 | furthestIdx = i; |
| 5418 | break; |
| 5419 | } |
| 5420 | } |
| 5421 | if (furthestIdx === -1) { |
| 5422 | while (open.length > openIdx) open.pop(); |
| 5423 | afe.splice(fmtIdx, 1); |
| 5424 | return true; |
| 5425 | } |
| 5426 | const furthest = open[furthestIdx]; |
| 5427 | const commonAncestor = open[openIdx - 1]; |
| 5428 | let bookmark = fmtIdx; |
| 5429 | let node = furthest; |
| 5430 | let lastNode = furthest; |
| 5431 | let nodeIdx = furthestIdx; |
| 5432 | let inner = 0; |
| 5433 | while (true) { |
no test coverage detected