Skip to main content

Module hyperlink

Module hyperlink 

Source
Expand description

Hyperlink destinations as the serializers write them (#860; docling-core 2.104.0’s is_safe_hyperlink / markdown_link_destination).

A destination comes from the converted document, where any string is a valid hyperlink — a DOCX relationship, an HTML href, a PDF link annotation. One with an active scheme (javascript:, data:, vbscript:) must not reach a reader as a clickable link, and one with a space or a ) must not end a Markdown inline link early and leave its tail to be read as Markdown or raw HTML. The backends bake links into an item’s text as [text](url) (the flat chain), so the sanitizing lives in one helper every bake site and every serializer goes through: an unsafe destination keeps the link text and drops the link; a safe one is written percent-escaped. The JSON export keeps the raw URI, as docling’s model does — a consumer of the JSON decides for itself.

Constants§

SAFE_HYPERLINK_SCHEMES
URI schemes that are written as live hyperlinks; any other scheme keeps only the link text (docling-core’s SAFE_HYPERLINK_SCHEMES).

Functions§

html_href
The destination escaped for an HTML href="…" attribute (Python’s html.escape: &, <, >, ", '), for a safe destination — the caller leaves the <a> out for an unsafe one.
is_safe_hyperlink
Whether a hyperlink destination may be rendered as a live link.
markdown_link
A Markdown inline link [text](destination) around text — or text alone when the destination is not safe, the way docling-core’s Markdown serializer writes an item’s hyperlink.
markdown_link_destination
The destination as it can stand inside [text](…): control characters, whitespace, parentheses, angle brackets, double quotes and backslashes are percent-encoded — each would otherwise end the destination or open raw HTML — and an & that starts an entity (&amp;, &#39;) becomes &amp;, since Markdown renderers decode entities in a destination. Every other byte, an existing %XX included, is kept as it is.