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’shtml.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)aroundtext— ortextalone when the destination is not safe, the way docling-core’s Markdown serializer writes an item’shyperlink. - 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 (&,') becomes&, since Markdown renderers decode entities in a destination. Every other byte, an existing%XXincluded, is kept as it is.