Repository navigation
HTML import: <a href> links become hyperlinks (#1879) - #1911
Merged
Merged
Conversation
An <a> with an http, https, ftp or mailto href is now an Inline::Hyperlink to that URL, and href="#name" an anchor link; every other href (javascript:, data:, file:, relative, ...) stays plain text, as before. The href is read as a browser's URL parser reads it (controls and spaces trimmed, tabs and line breaks inside removed), against an allow-list, so obfuscated schemes fail closed. The link lives in the element's computed look, so the cascade, restyle and the formatting-element reopen carry it with no stack of its own; an <a> closes an open <a> first, as the adoption agency does. A link gets a browser's look (underline, Word's Hyperlink blue) under the page's CSS, and color: inherit now gives the parent's colour back over it. Breaks, tabs and pictures are written outside the link; an unresolved image's alt text is the link's text. A link counts by its text for the empty-paragraph rule, and is never cut as a typed list marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lto (#1879) A links.html fixture with the shapes real pages use (styled text in a link, mailto, an anchor link, a javascript: button, a relative link, a link in a cell and one around a <br>) checks the links found and that each URL comes back from a saved package as an external relationship, the anchor as w:anchor. The Gmail quote header's address is now a mailto link, and links.html joins the every-prefix loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening a plain .htm page with links in the suite gives a tab whose document holds them as hyperlinks (the javascript: one as text). The area notes describe how links are read, carried, styled and saved, with the known limits (text-decoration propagation, bookmarks, the Hyperlink style, relative links). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r1) r1-m2: HTML leaves a named character reference that has no ';' and is followed by '=' or an ASCII letter or digit as written inside an attribute value, so href="?id=3©=2" must keep its '©=2' rather than become a copyright sign. attrs_of now decodes in that attribute mode; text keeps today's decoding. r1-m1: Color::Keep gives the parent's colour back over one the element set itself (a link's user-agent blue, <font color>); its doc said the colour was already there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 tasks
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Owner
Author
|
Merged automatically (auto-merge is on for this checkout): review stopped: round 1 had no Major; 1 minor finding(s) in #1912; merge rounds: none; whole suite green on ae7e6b2 (11954 tests; html-export and the UI sweep ran in CI, 14 checks passed); merge-check ok. Follow-ups, all in the leftovers issue #1912 (none are duplicates):
No finding was disputed. Both other r1 minors were fixed in ae7e6b2. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
HTML import (
docxcore::import::html) used to keep an<a>'s text and drop its target. Now an<a href>becomes anInline::Hyperlink:http,https,ftpormailtoURL becomes the link'starget.href="#name"becomes an anchor link (
w:anchor, percent-decoded);#alone makes no link.javascript:,vbscript:,data:,file:, any other scheme, relative and empty hrefs.link_ofreads an href the way a browser's URL parser does. It trims controls at both endsand removes tab, LF and CR inside, so
java	script:is caught. Then it checks anallow-list, so obfuscations fail closed.
",<,>and`are percent-encoded.restyle, mis-nesting and the formatting-element reopen carry it exactly as they carryformatting. A link that crosses
<p>boundaries becomes a link in each paragraph. An<a>closes an open
<a>first, as a browser's adoption agency does.0563C1) as directformatting, and the page's CSS overrides it.
color: inherit/currentcolornow gives backthe parent's colour, over a link's blue or a
<font color>. That makes Gmail'sa{color:inherit;text-decoration:none}work.the link goes on after it. An unresolved image's alt text inside a link is the link's text.
save_packagealready mints an externalrelationship for every target-only link. A test shows the targets survive
HtmlImport::package→ save → load. The suite's converting child saves the same way, so an
.htmopened in the suiteshows its links.
;that is followed by=or analphanumeric is kept as written, as HTML does. So
?id=3©=2stays a correct target(review r1).
Notes are in
docs/claude/html-import.mdunder "HTML import links (#1879)", with the knownlimits.
Closes #1879
Tests
html.rslink_tests(16):inherit;<a>;&name=in attributes.docxcore/tests/html_links.rsover a new newsletter-style fixturelinks.html: links inorder, and package save/load keeping targets (
TargetMode="External") andw:anchor.html_css.rs: the Gmail fixture'smailto:link, andlinks.htmlin the every-prefixloop.
convert_tests::a_web_pages_links_open_as_hyperlinks.ae7e6b24:cargo fmt, the workspacecargo clippy --all-targets,cargo test --workspace --locked, suite fmt / clippy /xvfb-run cargo test, the scripts'unittests and
check-claude-md. 11954 tests passed, 0 failed.html-exportclippy/test configuration (nowasm32-unknown-unknowntarget here) and the UI sweep. In an earlier run of the sweep on2cc88c4, 139 of 144 passed and 1 was an expected failure. Of the 4 failures:project-columns, in Project table code this PR does not touch.Review record
inheritrestoring the parent's colour, wider percent-encoding, links counted by their text forempty paragraphs, and alt text inside links.
ae7e6b24:Color::Keep's doc was stale;;-less&name=was decoded in attribute values.code predates this PR and lives in
markdown.rs, which the PR does not touch.<a name>/id;Hyperlinkcharacter style;<base href>and relative links;title/targetand hyperlinked pictures.