HtmlFilters
Functions that take a Lexbor document and return a modified version
To create a Lexbor document, use Lexbor::Parser.new(html)
Constants
A href/src lookalike inside a script body or an HTML comment: the parser-based pass ignores those (they are not element attributes), so when they are present the string rewrite is not equivalent and callers must use the parser path instead.
A code tag whose class doesn't already start with language-, which fix_code_classes would rewrite.
A href/src attribute value that make_links_relative would rewrite: anything not starting with "/", "#", a URL scheme (scheme'd values are absolute URLs; resolve+relativize round-trips a different-host absolute URL unchanged), and not empty (an empty value round-trips to empty, and the canonical link that carries it is skipped by the filter anyway).
Capture form of NEEDS_LINK_FIX: matches a href/src value that make_links_relative would rewrite, capturing the value and the quote character around it.
A root-relative href/src value that make_links_relative would rewrite (starts with "/" but not a protocol like "//").
Class methods
Make all relative href/src values absolute against base directly
on the html STRING, mirroring relativize_links_in_string. The
regexes already exclude absolute URLs, protocol-relative URLs and
anchors, so those pass through unchanged.
Shift headers so the highest level is n (n=2 means h1->h3, h2->h4, etc.) If n=2 and doc has h3 as the highest, then h3->h2, h4->h3, etc.
Post-process HTML to add language- prefix to code blocks. Idempotent: safe to run repeatedly (e.g. once per content pass and again on the page render), since it only adds the language- prefix when no token already carries one.
Make all relative links absolute against base (an absolute URL
like "https://example.com/blog/posts/foo/index.html").
Handles all tags with href/src attributes; external URLs and
in-page anchors are left untouched.
Note: no mutex needed, each call operates on its own document
Make all relative links relative to the page location. base is where the file containing the URIs is located relative to the site root. Handles all tags with href/src attributes. Note: no mutex needed, each call operates on its own document
Map a relative link to a markdown source file onto its rendered page: content links are written with .md paths so they also work when the source is browsed as markdown (e.g. on GitHub); once rendered, they must target the generated HTML. Anchors survive: foo.md#section becomes foo.html#section. Absolute URLs, root -relative paths, fragment-only links, and non-.md targets pass through untouched, so this is always safe to call on any href/src value regardless of the caller's own filtering.
Rewrite relative href/src values directly on the html STRING, without parsing the document. Used when pretty_html is off and only links need fixing: no lexbor parse, no re-serialization (which historically mangled code blocks), same relativize computation as make_links_relative applied to each value. Only call when string_rewrite_safe? says the html has no href/src lookalikes outside real attributes.