Repository navigation
Conversation
293204d to
250e0db
Compare
html-to-markdown-rs 3.15 adds a `base_url` conversion option that resolves relative href/src the same way `resolve_link_targets` does. The requirement is a caret range, so 3.15 arrives on a routine `cargo update` with the option left `None`: nothing fails to compile, no output changes, and nothing says the crate now carries two relative-link resolvers. A canary test reads the serialised option set of a default `ConversionOptions` and fails once `base_url` appears in it, with the reconciliation in the failure message. `..Default::default()` stays, so every other library default keeps flowing through; writing the fields out exhaustively would have made this crate own ~30 defaults it has no opinion on, and a later default change in the library would then stop reaching it, replacing one silent divergence with another. The option is deliberately not set. It would resolve the empty `src` that marks a dropped inline-data payload to the page URL, and it would rewrite the fragment-only hrefs this crate leaves as written, so it is only safe after #123. Deleting the pre-pass in favour of it is tracked in #190, which also closes out #104. Also mirrors the #63 and #94 entries into the docs-site changelog, which nothing syncs.
* fix(markdown): resolve relative links against the page URL The markdown kept each href and src as the HTML wrote it, so relative links did not work outside the page and a <base href> had no effect. html-to-markdown-rs has no base URL option. Before conversion, the HTML's relative addresses are rewritten in place to absolute URLs: a href, img src, the lazy-load image attributes, srcset candidates, media sources and quotation citations. The base is the page's first <base href>, resolved against the URL that served the page, the same base the links list uses. Every <base href> is rewritten to that base, so the front matter shows the address links resolve against. Addresses are decoded before they are resolved and escaped when written back. The decoding uses html5ever's tokenizer, which applies the WHATWG rules a browser applies, including the Windows-1252 table for numeric references 128-159. Values without an ampersand skip the tokenizer. Tag names match in any case. Absolute URLs of any scheme, fragment-only links and empty values stay as written. The converter's escaping and output formats stay the same. Closes #63 Closes #94 * test(markdown): fail if html-to-markdown-rs gains base_url html-to-markdown-rs 3.15 adds a `base_url` conversion option that resolves relative href/src the same way `resolve_link_targets` does. The requirement is a caret range, so 3.15 arrives on a routine `cargo update` with the option left `None`: nothing fails to compile, no output changes, and nothing says the crate now carries two relative-link resolvers. A canary test reads the serialised option set of a default `ConversionOptions` and fails once `base_url` appears in it, with the reconciliation in the failure message. `..Default::default()` stays, so every other library default keeps flowing through; writing the fields out exhaustively would have made this crate own ~30 defaults it has no opinion on, and a later default change in the library would then stop reaching it, replacing one silent divergence with another. The option is deliberately not set. It would resolve the empty `src` that marks a dropped inline-data payload to the page URL, and it would rewrite the fragment-only hrefs this crate leaves as written, so it is only safe after #123. Deleting the pre-pass in favour of it is tracked in #190, which also closes out #104. Also mirrors the #63 and #94 entries into the docs-site changelog, which nothing syncs. * refactor(scrape): extract the x-robots-tag directive pair scrape_from_crawl_response reached 81 lines against poly's 80-line limit once this branch threaded the document URL through. The header value and the directives derived from it are returned together because the raw value is reported on ScrapeResult while the directives gate link following. No behaviour change. Paid down here rather than added to the alef.toml baseline, per the ground rule on #42. --------- Co-authored-by: Na'aman Hirschfeld <nhirschfeld@gmail.com>
Nothing has ever compiled this branch5 checks, all red, one of them the It is also #105 gained Most serious: this reintroduces the
|
…e too The pre-pass emptied a data: address only on images, so a data: video, audio, iframe or source address was written into the markdown in full. These elements now get the same treatment, and a video or audio element falls back to a real nested source. The scrape test now asserts that fit_content keeps the image line, which the PR claimed and no test checked, and the changelog entry for #97 no longer describes the raw-text fix, which belongs to #123.
|
Thanks for the review. Every point is answered below; the changes are in Nothing has ever compiled this branchAgreed, and fixed. The branch now merges the current #105: the media list and the graphic share one data rule, every element on it has the attribute removed, and the two raw-text changelog sentences moved into the #102 entry. On a Linux box: Most serious: this reintroduces the
|
|
Triage note: two of the three parts are upstream work in The front-matter base re-encoding exists only because the converter does not decode |
…e too The pre-pass emptied a data: address only on images, so a data: video, audio, iframe or source address was written into the markdown in full. These elements now get the same treatment, and a video or audio element falls back to a real nested source. The scrape test now asserts that fit_content keeps the image line, which the PR claimed and no test checked, and the changelog entry for #97 no longer describes the raw-text fix, which belongs to #123.
c821f58 to
500f5be
Compare
…d cover graphic data tl has no raw-text handling, so the relative-link rewrite treated <a href> inside <title> as markup and wrote a full address into the front matter. The rewrite now walks tags in source order and skips any tag that starts inside title, textarea, script, style, xmp, iframe, noembed, noframes, noscript or plaintext, following the WHATWG tokenizer: each ends only at its own end tag in any case, an end tag inside a quoted attribute of the start tag does not end it, and an unclosed one runs to the end of the page. The front matter showed the base with character references encoded, because html-to-markdown-rs copies <base href> without decoding it. The rewritten <base href> is now always the resolved base written unencoded between double quotes, which a serialized URL cannot break out of. The data: rule for images now also empties <graphic> addresses. The start tags a real parser reads come from html5ever's tokenizer and tree builder, which covers raw text, SVG and MathML. A tl tag is rewritten only when its end offset and name match one of them, and the rewrite uses html5ever's parsed value, so CR, CRLF and NUL are normalized as a browser reads them. The written base percent-encodes ", < and >. A data: address attribute on an image or graphic is removed rather than emptied, so the converter falls through to a real address. A test pins that the converter does not decode the base yet.
…tags as tl does When the pre-pass drops an inline data address it now removes every later copy of the same attribute on that tag, in one forward pass, so a duplicate never takes the removed one's place. A srcset whose every candidate is inline data is removed instead of left empty. The attribute lookup reads the same bytes tl parsed, so a quote the masking scan misreads no longer makes the removal fall back to emptying, and a tag such as <a href=x="y> no longer gives the next link's address to the first.
…e too The pre-pass emptied a data: address only on images, so a data: video, audio, iframe or source address was written into the markdown in full. These elements now get the same treatment, and a video or audio element falls back to a real nested source. The scrape test now asserts that fit_content keeps the image line, which the PR claimed and no test checked, and the changelog entry for #97 no longer describes the raw-text fix, which belongs to #123.
500f5be to
5aab1cd
Compare
…ext-base-graphic # Conflicts: # CHANGELOG.md # docs-site/src/content/docs/changelog.md
|
Agreed. The decoded base in the front matter is fixed in the converter by xberg-io/html-to-markdown#537, so this half is dropped once crawlberg adopts it. The graphic data rule goes into the converter option in xberg-io/html-to-markdown#528. The raw-text part stays here. |
Stacked on #105. Merge that first, then retarget this to main.
Text inside raw text elements stays as written
The relative-link rewrite read
<title>use <a href="x.html"> tags</title>as markup and put a full address into the front matter title. The rewrite now changes only the tags an HTML parser reads as tags, which html5ever's tokenizer and tree builder decide. So link-shaped text intitle,textarea,script,styleand the other raw text elements stays as written, while inline SVG and MathML, where those names are ordinary elements, no longer hide the rest of the page.Base address in the front matter is decoded
<base href="https://example.com/it's/">gavebase: https://example.com/it's/, because the converter copies the value into the front matter without decoding it. The rewritten<base href>is now written unencoded between double quotes, with any",<or>percent-encoded so the value cannot end the attribute or open markup.<graphic>data addressesThe
data:rule for images now covers the addresses of<graphic>. Adata:address attribute is removed rather than emptied, so<graphic url="data:..." href="real.png">falls through to the real address.Closes #102
Closes #103
Closes #113