Skip to content

Leftovers from #1879: HTML import: <a href> links become hyperlinks #1912

Open

Description

@yeroo

Leftovers from #1879 (PR #1911): minor review findings and plan items deferred by the loop.

  • r1-pre1 (minor, review r1, docxcore/src/markdown.rs:333): Markdown export: escape hyperlink destinations (spaces, parentheses)
  • plan-p1 (minor, plan v2 out of scope): Html import: bookmarks for and id targets of anchor links
  • plan-p2 (minor, plan v2 out of scope): HTML import: Hyperlink character style on imported links
  • plan-p3 (minor, plan v2 out of scope): HTML import: resolve relative links against
  • plan-p4 (minor, plan v2 out of scope): HTML import: link title/target and hyperlinked pictures
r1-pre1

The Markdown export (docxcore/src/markdown.rs, inlines_to_md, ~line 333) writes a hyperlink as
format!("[{inner}]({url})") with the target or #anchor unescaped. A destination with a space
(an anchor my section, as HTML import's link_of percent-decodes href="#my%20section") is not
read as a link by CommonMark, and a URL with an unbalanced ) (https://x.test/a)b) is cut at the
first ). RTF, PDF and docx writers escape their output; Markdown does not.

Fix: wrap the destination in <…> (escaping </>), or percent-encode space and parentheses
there. Pre-existing; found by revmux round 1 of #1879 (HTML import links), which adds a new source
of such targets.

plan-p1

HTML import (#1879) makes href="#name" an anchor link (w:anchor), but nothing makes the
bookmark it names: <a name="x"> and elements with id="x" are not imported as bookmarks, so an
imported anchor link jumps nowhere. Needs a bookmark-name mapping shared by link anchors and
bookmarks (Word's rule: at most 40 characters, starting with a letter, no spaces), written as
w:bookmarkStart/w:bookmarkEnd. See docs/claude/html-import.md, "HTML import links (#1879)",
Known limits.

plan-p2

Imported HTML links (#1879) carry their look as direct formatting (underline, colour 0563C1) because
the Markdown package HtmlImport::package builds defines no Hyperlink character style. Word's own
HTML import applies w:rStyle="Hyperlink". Defining the style in the package and using it (with the
page's CSS still overriding) would match Word. See docs/claude/html-import.md, links section.

plan-p3

HTML import (#1879) leaves relative hrefs (page.html, /x, //host/x) as plain text, since
there is no base to resolve them against. Honour <base href> (and, for a page opened from disk,
perhaps the page's own URL) to resolve them into absolute allowed-scheme links.

plan-p4

HTML import (#1879) drops an <a>'s title and target: Word keeps them as w:hyperlink w:tooltip and w:tgtFrame. Also hyperlinked pictures (<a href><img></a>): the picture is written
outside the link today (out of scope since #1880).

Source: #1879, PR #1911
Severity: minor

Activity

  1. added
    follow-upfiled automatically by an agworkbench loop
    priority:P2correctness defect that blocks nothing open
    on Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upfiled automatically by an agworkbench looppriority:P2correctness defect that blocks nothing open

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions