Skip to main content

Module shortcode_extract

Module shortcode_extract 

Source
Expand description

Pre-parse extraction of :::shortcode blocks from markdown source.

Walks the markdown line-by-line, skipping the inert lines crate::inert_regions reports (so :::buttons inside a code fence, an indented code block, an inline code span or an HTML comment stays literal text) and recognizing :::name ...args / ::: openers/closers. Each block is replaced with a sentinel HTML comment (<!--MOSS_SC_{nonce}_N-->) that pulldown-cmark emits as a Block::Other raw HTML; the final parser pass walks the AST and substitutes the sentinels with typed Shortcode variants.

Why this design:

  • ::: block syntax is not standard CommonMark; pulldown-cmark sees it as plain text inside a paragraph. Post-parse text-matching is fragile (works only when the shortcode is the entire paragraph).
  • Pre-parse extraction with a sentinel is the same pattern Zola uses and preserves parsing correctness for adjacent content.
  • The sentinel is an HTML comment so it survives pulldown-cmark intact (pulldown-cmark passes HTML comments through Event::Html as Block::HtmlBlock).

Structs§

ExtractedShortcode
One extracted shortcode block, with its body parsed into a typed variant.
ExtractionResult
Result of pre-parse extraction.

Functions§

extract_shortcodes
Walk the markdown line-by-line, replace :::name blocks with sentinels.
extract_shortcodes_with_config
extract_shortcodes, parsing shortcode bodies with the caller’s ParseConfig.
parse_apply_args
Parse :::apply {placeholder="..." button="..."} into a typed struct.
parse_placeholder
Try to interpret a Block::Other payload as a shortcode placeholder matching the given nonce. Returns the index if it matches.
parse_recent_args
Parse :::recent {since=... last=... count=...} body into a typed struct.
placeholder_for
The sentinel HTML comment used to mark an extracted shortcode in the markdown source. Pulldown-cmark emits these as [Event::Html] inside a [Tag::HtmlBlock], which surfaces as Block::Other in our AST.
shortcode_asset_spans
Byte-offset asset paths inside :::gallery / :::hero blocks.