Normalize links in HTML subset formatting - #190
Conversation
snoopdave
left a comment
There was a problem hiding this comment.
PR-Review: 3 inline comments posted.
|
|
||
| // HTTP links | ||
| // Normalize supported links while retaining the surrounding text. | ||
| s = replace(s, CLOSING_A_TAG_PATTERN, "</a>"); |
There was a problem hiding this comment.
🐞Claude Issue: Important: CLOSING_A_TAG_PATTERN rewrites </a> unconditionally, but the opening tag is only rewritten when OPENING_A_TAG_PATTERN matches. Anchors it does not recognise therefore emit an unbalanced </a>:
<a>x</a> -> <a>x</a>
<a class="c" href="https://x/">y</a> -> <a class="c" href="https://x/">y</a>
This is pre-existing, but the loop is being rewritten here and already has an "unsupported anchor" output (<a>). Emitting that for unmatched opening tags as well would keep the markup balanced for a couple of lines of change.
There was a problem hiding this comment.
🤖Claude: fixed by broadening OPENING_A_TAG_PATTERN to <a(?:\s[\s\S]*?)?> so it matches every escaped opening anchor, not just ones starting <a href=. Each one now goes through the same reconstruction, so an anchor whose href is missing or unusable becomes <a> and the markup stays balanced:
<a>x</a> -> <a>x</a>
<a name="anchor">x</a> -> <a>x</a>
<a class="c" href="https://x/">y</a> -> <a href="https://x/">y</a>
The pattern requires whitespace or the closing delimiter after a, so sibling tags are unaffected — <abbr> still passes through escaped. Covered by new test testHtmlSubsetBalancesUnsupportedAnchors.
|
🐞Claude Issue: PR-Review: General Issues The following issues were found but cannot be attached to a specific line in the diff:
|
|
🤖Claude: fixed both. Changelog — added a bullet to the Docs — updated both places:
|
Normalize supported links to a consistent href format while preserving comment text and basic formatting.
Adds coverage for quoted and unquoted links, query strings, whitespace, entity text, and plain-text comments.
Validation:
mvn -V -ntp installon JDK 25 — 307 tests, no failures or errors, one skipped.