# links URL: /api/parsing/inline/links/ Section: inline -------------------------------------------------------------------------------- links - Patitas window.BENGAL_THEME_DEFAULTS = { appearance: 'light', palette: 'brown-bengal' }; window.Bengal = window.Bengal || {}; window.Bengal.enhanceBaseUrl = '/patitas/assets/js/enhancements'; window.Bengal.watchDom = true; window.Bengal.debug = false; window.Bengal.enhanceUrls = { 'toc': '/patitas/assets/js/enhancements/toc.632a9783.js', 'docs-nav': '/patitas/assets/js/enhancements/docs-nav.57e4b129.js', 'tabs': '/patitas/assets/js/enhancements/tabs.aac9e817.js', 'lightbox': '/patitas/assets/js/enhancements/lightbox.1ca22aa1.js', 'interactive': '/patitas/assets/js/enhancements/interactive.fc077855.js', 'mobile-nav': '/patitas/assets/js/enhancements/mobile-nav.d991657f.js', 'action-bar': '/patitas/assets/js/enhancements/action-bar.d62417f4.js', 'copy-link': '/patitas/assets/js/enhancements/copy-link.7d9a5c29.js', 'data-table': '/patitas/assets/js/enhancements/data-table.1f5bc1eb.js', 'lazy-loaders': '/patitas/assets/js/enhancements/lazy-loaders.a5c38245.js', 'holo': '/patitas/assets/js/enhancements/holo.ee13c841.js', 'link-previews': '/patitas/assets/js/enhancements/link-previews.8d906535.js' }; (function () { try { var defaults = window.BENGAL_THEME_DEFAULTS || { appearance: 'system', palette: '' }; var defaultAppearance = defaults.appearance; if (defaultAppearance === 'system') { defaultAppearance = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light'; } var storedTheme = localStorage.getItem('bengal-theme'); var storedPalette = localStorage.getItem('bengal-palette'); var theme = storedTheme ? (storedTheme === 'system' ? defaultAppearance : storedTheme) : defaultAppearance; var palette = storedPalette ?? defaults.palette; document.documentElement.setAttribute('data-theme', theme); if (palette) { document.documentElement.setAttribute('data-palette', palette); } } catch (e) { document.documentElement.setAttribute('data-theme', 'light'); } })(); { "prerender": [ { "where": { "and": [ { "href_matches": "/docs/*" }, { "not": { "selector_matches": "[data-external], [target=_blank], .external" } } ] }, "eagerness": "conservative" } ], "prefetch": [ { "where": { "and": [ { "href_matches": "/*" }, { "not": { "selector_matches": "[data-external], [target=_blank], .external" } } ] }, "eagerness": "conservative" } ] } Skip to main content Magnifying Glass ESC Recent Clear Magnifying Glass No results for "" Start typing to search... ↑↓ Navigate ↵ Open ESC Close Powered by Lunr ฅᨐฅ DocumentationArrow ClockwiseGet StartedCodeSyntaxDirectivesStarburstExtendingBookmarkReferenceInfoAboutTroubleshootingReleasesDevGitHubPatitas API Reference Magnifying Glass Search ⌘K Palette Appearance Chevron Down Mode Monitor System Sun Light Moon Dark Palette Snow Lynx Brown Bengal Silver Bengal Charcoal Bengal Blue Bengal List ฅᨐฅ Magnifying Glass Search X Close Documentation Caret Down Arrow Clockwise Get Started Code Syntax Directives Starburst Extending Bookmark Reference Info About Troubleshooting Releases Dev Caret Down GitHub Patitas API Reference Palette Appearance Chevron Down Mode Monitor System Sun Light Moon Dark Palette Snow Lynx Brown Bengal Silver Bengal Charcoal Bengal Blue Bengal Patitas API Reference Caret Right Directives Caret Right Builtins admonition container dropdown tabs contracts decorator options protocol registry Caret Right Lexer Caret Right Classifiers directive fence footnote heading html link_ref list quote thematic Caret Right Scanners block directive fence html core modes Caret Right Parsing Caret Right Blocks Caret Right List blank_line indent item_blocks marker mixin nested trace types core directive footnote table Caret Right Inline core emphasis links match_registry special tokens charsets containers token_nav Caret Right Plugins autolinks footnotes math strikethrough table task_lists Caret Right Renderers html Caret Right Roles Caret Right Builtins formatting icons math reference protocol registry Caret Right Utils hashing logger text errors highlighting icons location nodes parser patitas protocols stringbuilder tokens ParsingInline ᗢ Caret Down Link Copy URL External Open LLM text Copy Copy LLM text Share with AI Ask Claude Ask ChatGPT Ask Gemini Ask Copilot Module parsing.inline.links Link and image parsing for Patitas parser. Handles inline links, reference links, images, and footnote references. CommonMark 0.31.2 compliance: Link destinations can be angle-bracket delimited or raw Angle-bracket destinations: no newlines, can have spaces Raw destinations: no spaces, no control chars, balanced parens Backslash escapes work in destinations and titles 1Class10Functions Classes LinkParsingMixin 4 ▼ Mixin for link and image parsing. Required Host Attributes: - _link_refs: dict[str, tuple[str,… Mixin for link and image parsing. Required Host Attributes: _link_refs: dict[str, tuple[str, str]] Required Host Methods: _parse_inline(text, location) -> tuple[Inline, ...] Attributes Name Type Description _link_refs dict[str, tuple[str, str]] — Methods Internal Methods 3 ▼ _try_parse_footnote_ref 3 tuple[FootnoteRef, int] … ▼ Try to parse a footnote reference at position. Format: [^identifier] Returns (… def _try_parse_footnote_ref(self, text: str, pos: int, location: SourceLocation) -> tuple[FootnoteRef, int] | None Try to parse a footnote reference at position. Format: [^identifier] Returns (FootnoteRef, new_position) or None if not a footnote ref. Parameters Name Type Description text — pos — location — Returns tuple[FootnoteRef, int] | None _try_parse_link 3 tuple[Link, int] | None ▼ Try to parse a link at position. Handles: - [text](url) - inline link - [text]… def _try_parse_link(self, text: str, pos: int, location: SourceLocation) -> tuple[Link, int] | None Try to parse a link at position. Handles: text - inline link [text][ref] - full reference link [text][] - collapsed reference link [ref] - shortcut reference link Returns (Link, new_position) or None if not a link. Parameters Name Type Description text — pos — location — Returns tuple[Link, int] | None _try_parse_image 3 tuple[Image, int] | None ▼ Try to parse an image at position. Handles: - ![alt](url) - inline image - ![a… def _try_parse_image(self, text: str, pos: int, location: SourceLocation) -> tuple[Image, int] | None Try to parse an image at position. Handles: - inline image ![alt][ref] - full reference image ![alt][] - collapsed reference image ![alt] - shortcut reference image Returns (Image, new_position) or None if not an image. Parameters Name Type Description text — pos — location — Returns tuple[Image, int] | None Functions _process_escapes 1 str ▼ Process backslash escapes in link URLs and titles. CommonMark: Backslash escap… def _process_escapes(text: str) -> str Process backslash escapes in link URLs and titles. CommonMark: Backslash escapes work in link destinations and titles. A backslash followed by ASCII punctuation is replaced with the literal char. Parameters Name Type Description text str Raw text that may contain backslash escapes Returns str _unescape_label 1 str ▼ Unescape label-specific escapes (backslash, [, ]). CommonMark: Backslash escap… def _unescape_label(label: str) -> str Unescape label-specific escapes (backslash, [, ]). CommonMark: Backslash escapes are allowed in labels but only matter for backslash and bracket characters. Other escapes remain literal so that labels like [foo\!] do not match [foo!] (spec example 545). Parameters Name Type Description label str Returns str _normalize_label 1 str ▼ Normalize a link reference label for matching. CommonMark 4.7: "Label matching… def _normalize_label(label: str) -> str Normalize a link reference label for matching. CommonMark 4.7: "Label matching is case-insensitive and Unicode case fold equivalent. Spaces, tabs, and line endings are normalized to single space." Parameters Name Type Description label str Raw label text Returns str _parse_link_destination 2 tuple[str, int] | None ▼ Parse a link destination starting at pos. CommonMark 6.5: Link destination is … def _parse_link_destination(text: str, pos: int) -> tuple[str, int] | None Parse a link destination starting at pos. CommonMark 6.5: Link destination is either: Angle-bracket delimited: (can contain spaces, no newlines or unescaped </>) Raw URL: sequence of non-space chars with balanced parens Parameters Name Type Description text str The full text being parsed pos int Position after the opening ( Returns tuple[str, int] | None _parse_link_title 2 tuple[str | None, int] ▼ Parse an optional link title starting at pos. CommonMark: Title is enclosed in… def _parse_link_title(text: str, pos: int) -> tuple[str | None, int] Parse an optional link title starting at pos. CommonMark: Title is enclosed in ", ', or () Can span lines but opening/closing delimiters must match. Parameters Name Type Description text str The full text being parsed pos int Position to start looking for title Returns tuple[str | None, int] _parse_inline_link 2 tuple[str, str | None, i… ▼ Parse an inline link destination and optional title. Format: (url) or (url "ti… def _parse_inline_link(text: str, pos: int) -> tuple[str, str | None, int] | None Parse an inline link destination and optional title. Format: (url) or (url "title") or ( 'title') Parameters Name Type Description text str Full text being parsed pos int Position at the opening ( Returns tuple[str, str | None, int] | None _skip_html_tag 2 int ▼ Skip over an HTML tag starting at pos. Handles open tags, close tags, and self… def _skip_html_tag(text: str, pos: int) -> int Skip over an HTML tag starting at pos. Handles open tags, close tags, and self-closing tags. Properly handles quoted attribute values that may contain special chars. Parameters Name Type Description text str Full text to search pos int Position at the opening < Returns int _find_closing_bracket 2 int ▼ Find closing bracket ] while respecting code spans, HTML tags, and nested brack… def _find_closing_bracket(text: str, start: int) -> int Find closing bracket ] while respecting code spans, HTML tags, and nested brackets. CommonMark: Code spans have higher precedence than link text brackets. A code span inside link text means the ] inside the code span doesn't count. HTML tags protect their contents - ] inside HTML attribute values doesn't count. Nested brackets [ ] are allowed inside link text. Parameters Name Type Description text str Full text to search start int Position to start searching (should be after opening [) Returns int _extract_plain_text 1 str ▼ Extract plain text from inline content for image alt text. CommonMark: Image a… def _extract_plain_text(text: str) -> str Extract plain text from inline content for image alt text. CommonMark: Image alt text is the plain text content with formatting stripped. E.g., "foo bar" becomes "foo bar". Parameters Name Type Description text str Raw inline content that may contain formatting Returns str _contains_link 1 bool ▼ Check if children contain a Link node at any nesting level. CommonMark: Links … def _contains_link(children: tuple) -> bool Check if children contain a Link node at any nesting level. CommonMark: Links may not contain other links, at any level of nesting. If parsing link text produces a link, the outer link is invalid. Parameters Name Type Description children tuple Tuple of inline nodes Returns bool ← Previous inline Next → match_registry List © 2026 Patitas built in ᓚᘏᗢ { "linkPreviews": { "enabled": true, "hoverDelay": 200, "hideDelay": 150, "showSection": true, "showReadingTime": true, "showWordCount": true, "showDate": true, "showTags": true, "maxTags": 3, "includeSelectors": [".prose"], "excludeSelectors": ["nav", ".toc", ".breadcrumb", ".pagination", ".card", "[class*='-card']", ".tab-nav", "[class*='-widget']", ".child-items", ".content-tiles"], "allowedHosts": [], "allowedSchemes": ["https"], "hostFailureThreshold": 3 } } window.BENGAL_LAZY_ASSETS = { tabulator: '/patitas/assets/js/tabulator.min.js', dataTable: '/patitas/assets/js/data-table.js', mermaidToolbar: '/patitas/assets/js/mermaid-toolbar.9de5abba.js', mermaidTheme: '/patitas/assets/js/mermaid-theme.344822c5.js', graphMinimap: '/patitas/assets/js/graph-minimap.ff04e939.js', graphContextual: '/patitas/assets/js/graph-contextual.355458ba.js' }; window.BENGAL_ICONS = { close: '/patitas/assets/icons/close.911d4fe1.svg', enlarge: '/patitas/assets/icons/enlarge.652035e5.svg', copy: '/patitas/assets/icons/copy.3d56e945.svg', 'download-svg': '/patitas/assets/icons/download.04f07e1b.svg', 'download-png': '/patitas/assets/icons/image.c34dfd40.svg', 'zoom-in': '/patitas/assets/icons/zoom-in.237b4a83.svg', 'zoom-out': '/patitas/assets/icons/zoom-out.38857c77.svg', reset: '/patitas/assets/icons/reset.d26dba29.svg' }; Arrow Up -------------------------------------------------------------------------------- Metadata: - Word Count: 1617 - Reading Time: 8 minutes