A card template can contain both intended URLs and still produce the wrong links after the browser parses it. Nested anchors are invalid HTML. The parser repairs their structure, so the final link boundaries can differ from what the component author thought the markup expressed.
Do not approve the card because a source search finds both href values. Compare each intended destination and label with the actual parsed anchor tree. A valid destination attached to incomplete or misleading text can still break the reader’s task.
The crawlable navigation contract establishes when a component should emit an anchor. This guide supplies a narrower parser fixture for a component that emits anchors in an invalid relationship.
Use the anchor content model as the boundary
The HTML Standard’s anchor content model disallows an anchor descendant inside another anchor, interactive descendants and descendants carrying tabindex. An outer card link cannot simply wrap every inner action without considering those restrictions.
The HTML parsing rules define recovery from malformed input. Recovery is not permission for a publisher to rely on invalid nesting. It also does not guarantee that every imagined source relationship survives as a relationship in the DOM.
This test uses a genuine browser parser for one controlled case. It is not a custom regular expression pretending to implement the HTML tree builder. The source and expected reader outcome are retained independently from the browser result.
State the intended two-link contract
Imagine a fictional setup card that needs two separate destinations. The main link must read “Open setup guide” and point to the setup guide. A second link must read “View limits” and point to the limit explanation. Neither label should include the other action.
| Approved anchor | Approved destination | Required text |
|---|---|---|
| Main setup link | https://docs.example/guides/setup | Open setup guide |
| Limits link | https://docs.example/guides/limits | View limits |
The defective template puts the limits link inside the setup anchor, between “Open setup” and “guide.” The repaired template makes them siblings. There is no production hostname, secret or customer data in this fixture. The example domain is used only to resolve relative addresses in a local document.
A simple count of two anchors cannot distinguish these cases. Neither can a check that searches the source for the word guide. The acceptance oracle must connect each destination to its intended label after parsing.
Run the actual parser fixture
Run this Python example in an environment with Playwright and Chromium already installed, adjusting the executable path to that approved local installation if necessary. It uses set_content and performs no navigation to the example host or package installation.
import json
from playwright.sync_api import sync_playwright
bad_html = """<!doctype html><html lang="en"><head>
<base href="https://docs.example/"><title>Local fixture</title>
</head><body><p><a href="/guides/setup">Open setup
<a href="/guides/limits">View limits</a> guide</a></p></body></html>"""
good_html = """<!doctype html><html lang="en"><head>
<base href="https://docs.example/"><title>Local fixture</title>
</head><body><p><a href="/guides/setup">Open setup guide</a>
<a href="/guides/limits">View limits</a></p></body></html>"""
expected = [
['https://docs.example/guides/setup', 'Open setup guide'],
['https://docs.example/guides/limits', 'View limits'],
]
with sync_playwright() as p:
browser = p.chromium.launch(headless=True, executable_path='/usr/bin/chromium')
page = browser.new_page()
def links(markup):
page.set_content(markup)
return page.locator('a').evaluate_all(r"""nodes => nodes.map(a => [
a.href, a.textContent.replace(/\s+/g, ' ').trim()
])""")
bad = links(bad_html)
good = links(good_html)
assert bad != expected
assert bad[0][1] == 'Open setup'
assert good == expected
print(json.dumps({'broken': bad, 'repaired': good}))
browser.close()
print('parsed destination and text oracle PASS')The broken output gives the setup link the text “Open setup,” while the trailing word guide remains outside that anchor. The repaired output matches both independently specified destination-and-text pairs. The fixture deliberately fails the broken relationship rather than merely proving that malformed input can still display words.
These results concern the shown markup under the tested browser. Keep the actual browser version and output in the engineering receipt. Do not extend this one fixture into a claim that every malformed card has the same repaired tree.
Separate parser repair from interaction code
After the source structure is corrected, test the real component’s ordinary activation, keyboard activation, new-tab behavior and copied address. The local code above inspects parsed links; it does not certify the application’s event handlers, focus behavior or routing enhancement.
An overlay click handler can still send a visitor to the outer card destination while an inner anchor exposes another address. That is an interaction defect even after the HTML is valid. Review the component under the site’s normal accessibility process instead of adding another event handler to compensate for invalid markup.
Use the anchor promise review for whether the destination fulfills the label. Use the base URL fixture when a valid relative href resolves against the wrong base. Parser boundaries, URL resolution and content relevance are separate findings.
Find the producer shared across cards, related links or CMS blocks. Correct that component and sample representative combinations, especially cards with more than one action. A manual repair in one article will not protect every instance of the same invalid template.
Keep a regression that counts meaning
Retain both the malformed input and the independently expected sibling-link output in a bounded test. Require the destination-and-label pairs, then review actual interactions on the deployed component. A test that only asserts the absence of a nested a element can pass after parser repair even when the source was invalid.
Close on valid authored structure, correct parsed relationships and verified reader interactions. Record discovery and indexing separately. Fixing a parser-repaired card creates a reliable navigation relationship; it does not prove that a search engine will crawl or rank either destination.
