Skip to content

refactor(markdown): delete the crawlberg-side link pre-pass once h2m base_url is adopted #190

Closed

Description

@Goldziher

html-to-markdown-rs 3.15.0 adds ConversionOptions::base_url, which resolves relative
href/src (including srcset, media source, graphic, lazy-load fallbacks) against a
caller-supplied base and honours a document <base href> the way a browser does. That is the
same job as the crawlberg-side pre-pass added for #63
(crates/crawlberg/src/html/link_targets.rs), so the two now overlap.

Adopting base_url and deleting the URL-joining half of link_targets.rs is the right end
state. It also answers #104: the pre-pass exists only because the converter could not do this,
and dropping it removes the second HTML parse #104 is about.

What must stay in link_targets.rs — h2m's base_url does not do either of these:

  • the data: payload removal (keeping inline image bytes out of the markdown),
  • the raw-text guard (leaving <script>/<style>/<textarea> content untouched).

Two blockers, both of which make enabling base_url today a regression:

  1. src="" as a sentinel. fix(markdown): keep inline image data out of the markdown #105 writes an empty src=""/srcset="" to mark an image whose
    inline data payload was dropped. base_url resolves an empty reference to the base, so a
    dropped payload would become a link to the page itself. fix(markdown): leave raw text alone, decode the front matter base, and cover graphic data #123 fixes this by removing the
    attribute instead of emptying it, so base_url is only safe once fix(markdown): leave raw text alone, decode the front matter base, and cover graphic data #123 has landed.
  2. Fragment-only href="#x". The feat(markdown): resolve relative links against the page's own address or its base URL #63 pre-pass deliberately leaves these as written.
    Adopting base_url changes that output, so it is a behaviour change that needs its own
    decision and test coverage, not a silent side effect of a dependency bump.

The dependency is declared as a caret range (html-to-markdown-rs = { version = "3.14" }), so
3.15 arrives on a routine cargo update with base_url left None and nothing failing. A
canary test (html_to_markdown_has_no_base_url_option in crates/crawlberg/src/markdown.rs)
now fails when that happens, so the bump cannot land without someone reading this issue.

Order of work: #123, then adopt base_url, decide the fragment question, delete the joining
half of the pre-pass, close #104.

Refs #63, #94, #104, #105, #123.

Activity

  1. self-assigned this
    on Sep 26, 2026
  2. Goldziher commented on Sep 26, 2026

    @Goldziher
    MemberAuthor

    One factual correction, since this issue is now the tracker for #104 (closed in its favour).

    The canary this issue relies on does not exist: html_to_markdown_has_no_base_url_option is not in crates/crawlberg/src/markdown.rs, nor anywhere else in the repo. markdown.rs has a mod tests at line 85 containing seven tests — converts_heading, converts_paragraph, converts_link, converts_full_page, empty_html_returns_some, drops_noscript_fallback_content_by_default, preserves_content_when_no_noscript_present — and the string base_url appears nowhere in the file. git log -S'html_to_markdown_has_no_base_url_option' returns no commits, so it was never added and later removed; it was never written.

    That matters for this issue's closing sentence, "so the bump cannot land without someone reading this issue." Nothing currently enforces that. Combined with the fact that Cargo.toml:83's "3.14" is a caret range that already admits 3.15.0, a routine cargo update will pick up base_url silently, with it left None and nothing failing — exactly the scenario the canary was meant to prevent.

    Worth adding the canary for real as the first step of this issue, before the dependency moves on its own.

  3. added
    performance
    blocked
    duplicate-cluster
    on Sep 26, 2026
  4. added theissue type on Sep 26, 2026
  5. Goldziher commented on Sep 26, 2026

    @Goldziher
    MemberAuthor

    Correction to the note above: the canary does exist. It is html_to_markdown_has_no_base_url_option at crates/crawlberg/src/markdown.rs:430 on PR #82's branch fix/markdown-relative-links, added by 743ab35d7 ("test(markdown): fail if html-to-markdown-rs gains base_url"), with a pointer comment at markdown.rs:44.

    The earlier note searched main, where it is correctly absent — the canary lands when #82 merges. It was verified red-then-green before being committed: green on the pinned 3.14.3, and red after cargo update -p html-to-markdown-rs --precise 3.15.0, failing with a message that names this issue.

    It asserts on the serialised option set rather than on ConversionOptions::default().base_url, because that field does not exist on 3.14.3 and referencing it would be a compile error today rather than a failure when 3.15 arrives.

    So the enforcement #190 depends on is real, with one caveat worth keeping in view: it only fires once #82 lands. Until then a cargo update could still pull 3.15.0 — Cargo.toml's "3.14" is a caret range that already admits it, and the current pin to 3.14.3 is the lockfile, not the requirement.

  6. Goldziher commented on Sep 26, 2026

    @Goldziher
    MemberAuthor

    Label set: blocked is correct, duplicate-cluster is not — dropping it. This is gated, not redundant, and #104 already closed in its favour.

    The two notes above about the canary contradict each other and both are now stale. It is on main: html_to_markdown_has_no_base_url_option at crates/crawlberg/src/markdown.rs:430, with the pointer comment at :44, since PR #82 merged. So the body's closing claim — the bump cannot land without someone reading this issue — holds today, and the first note's suggestion to "add the canary for real" is already done.

    The upstream half has moved, which sharpens the blockers. html-to-markdown 3.15.0 is released (tag v3.15.0 in xberg-io/html-to-markdown), so Cargo.toml:84's "3.14" caret admits it now and the canary is the only thing standing between a routine cargo update and a silently-None base_url. Adoption additionally waits on xberg-io/html-to-markdown#510, which is open and sits under that repo's [Unreleased]: without it base_url resolves every destination except <blockquote cite>, which would force the joining half of the pre-pass to stay alive for that one attribute — so a 3.15.1 release is part of the blocker, not just 3.15.0. In-repo, blocker 1 still waits on #123 (open).

  7. removed
    duplicate-cluster
    on Sep 26, 2026
  8. tobocop2 commented on Sep 26, 2026

    @tobocop2
    Member

    One more case for the fragment decision here. With <a href="#top"> on https://example.com/dir/page, the links list reports https://example.com/dir/page#top, while the markdown keeps [top](#top). The links list joins every reference to the base (html/links.rs), and the markdown pre-pass leaves absolute and fragment-only references as written (html/link_targets.rs). This is the same on main, #98 and #122. Whatever this issue decides for fragment-only links when the rewrite moves to base_url should settle which of the two outputs is right, so the two stop disagreeing.

  9. added
    P3
    on Sep 27, 2026
  10. Goldziher commented on Oct 5, 2026

    @Goldziher
    MemberAuthor

    The crawlberg-side link pre-pass is removed; Crawlberg now passes the document URL through html-to-markdown 3.17.1 base_url handling. Fixed by 2ed5261 and included in 1.10.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3blockedperformance

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions