# pattern_parsers URL: /api/parsing/pattern_parsers/ Section: parsing -------------------------------------------------------------------------------- pattern_parsers - 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.736b857e.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.96c8880c.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.96620bcf.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 StartedCodeSyntaxDirectivesStarburstExtendingBookmarkReferenceInfoAboutWarningTroubleshootingReleasesDevGitHubPatitas API ReferenceForum 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 Warning Troubleshooting Releases Dev Caret Down GitHub Patitas API Reference Forum 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 fast_path indent item_blocks marker mixin nested trace types core directive footnote quote_fast_path quote_token_reuse table Caret Right Inline core emphasis links match_registry special tokens charsets compiled_dispatch containers dispatch pattern_parsers protocols shared_tokens token_nav ultra_fast Caret Right Plugins autolinks footnotes math strikethrough table task_lists Caret Right Renderers html llm protocol Caret Right Roles Caret Right Builtins formatting icons math reference protocol registry Caret Right Utils hashing logger text cache config context differ errors excerpt frontmatter highlighting icons incremental location nodes notebook parser patitas profiling protocols sanitize serialization stringbuilder text tokens visitor Patitas API ReferenceParsing ᗢ 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.pattern_parsers Pattern-specific optimized parsers. Each parser is tailored for a specific token pattern, eliminating unnecessary branching and checks. Top 10 patterns cover 79.1% of CommonMark spec: (PARAGRAPH_LINE,) 45.7% ← ultra_fast.py (BLANK_LINE, LINK_REFERENCE_DEF, PARAGRAPH_LINE) 10.7% ← parse_linkref_paragraphs (HTML_BLOCK,) 3.7% ← parse_html_only (LIST_ITEM_MARKER, PARAGRAPH_LINE) 3.5% ← parse_simple_flat_list (BLANK_LINE, INDENTED_CODE, LIST_ITEM_MARKER, ...) 3.1% ← (complex) (BLANK_LINE, PARAGRAPH_LINE) 3.1% ← parse_paragraphs_with_blanks (FENCED_CODE_CONTENT, FENCED_CODE_END, ...) 2.9% ← parse_fenced_code_only (BLANK_LINE, LIST_ITEM_MARKER, PARAGRAPH_LINE) 2.3% ← parse_simple_list_with_blanks (ATX_HEADING,) 2.1% ← parse_atx_only (INDENTED_CODE,) 2.0% ← parse_indented_only 8Functions Functions parse_html_only 2 tuple[Block, ...] ▼ Pattern 3: (HTML_BLOCK,) - 3.7% of examples. Just HTML blocks, no other conten… def parse_html_only(tokens: list, parse_inline_fn: Callable) -> tuple[Block, ...] Pattern 3: (HTML_BLOCK,) - 3.7% of examples. Just HTML blocks, no other content. Parameters Name Type Description tokens list parse_inline_fn Callable Returns tuple[Block, ...] parse_atx_only 2 tuple[Block, ...] ▼ Pattern 9: (ATX_HEADING,) - 2.1% of examples. Just ATX headings, no other cont… def parse_atx_only(tokens: list, parse_inline_fn: Callable) -> tuple[Block, ...] Pattern 9: (ATX_HEADING,) - 2.1% of examples. Just ATX headings, no other content. Parameters Name Type Description tokens list parse_inline_fn Callable Returns tuple[Block, ...] parse_indented_only 2 tuple[Block, ...] ▼ Pattern 10: (INDENTED_CODE,) - 2.0% of examples. Just indented code blocks, no… def parse_indented_only(tokens: list, parse_inline_fn: Callable) -> tuple[Block, ...] Pattern 10: (INDENTED_CODE,) - 2.0% of examples. Just indented code blocks, no other content. Parameters Name Type Description tokens list parse_inline_fn Callable Returns tuple[Block, ...] parse_fenced_code_only 2 tuple[Block, ...] ▼ Pattern 7: (FENCED_CODE_*) - 2.9% of examples. Just fenced code blocks, no oth… def parse_fenced_code_only(tokens: list, parse_inline_fn: Callable) -> tuple[Block, ...] Pattern 7: (FENCED_CODE_*) - 2.9% of examples. Just fenced code blocks, no other content. Parameters Name Type Description tokens list parse_inline_fn Callable Returns tuple[Block, ...] parse_paragraphs_with_blanks 2 tuple[Block, ...] ▼ Pattern 6: (BLANK_LINE, PARAGRAPH_LINE) - 3.1% of examples. Paragraphs separat… def parse_paragraphs_with_blanks(tokens: list, parse_inline_fn: Callable) -> tuple[Block, ...] Pattern 6: (BLANK_LINE, PARAGRAPH_LINE) - 3.1% of examples. Paragraphs separated by blank lines. Parameters Name Type Description tokens list parse_inline_fn Callable Returns tuple[Block, ...] parse_simple_flat_list 2 tuple[Block, ...] ▼ Pattern 4: (LIST_ITEM_MARKER, PARAGRAPH_LINE) - 3.5% of examples. Simple flat … def parse_simple_flat_list(tokens: list, parse_inline_fn: Callable) -> tuple[Block, ...] Pattern 4: (LIST_ITEM_MARKER, PARAGRAPH_LINE) - 3.5% of examples. Simple flat list with no nesting, no blank lines. Parameters Name Type Description tokens list parse_inline_fn Callable Returns tuple[Block, ...] parse_simple_list_with_blanks 2 tuple[Block, ...] ▼ Pattern 8: (BLANK_LINE, LIST_ITEM_MARKER, PARAGRAPH_LINE) - 2.3%. List with bl… def parse_simple_list_with_blanks(tokens: list, parse_inline_fn: Callable) -> tuple[Block, ...] Pattern 8: (BLANK_LINE, LIST_ITEM_MARKER, PARAGRAPH_LINE) - 2.3%. List with blank lines (loose list). Parameters Name Type Description tokens list parse_inline_fn Callable Returns tuple[Block, ...] get_pattern_parser 1 Callable | None ▼ Get specialized parser for token pattern if available. def get_pattern_parser(tokens: list) -> Callable | None Parameters Name Type Description tokens list Token list from lexer Returns Callable | None ← Previous parsing Next → protocols 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, "showDeadLinks": true } } 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: 1028 - Reading Time: 5 minutes