Matchers
Matchers allow you to validate dynamic content in your Markdown documents. There are two types of matchers: regex matchers that match patterns using regular expressions, and all matchers that match everything as an identity function.
Matcher Types
Section titled “Matcher Types”Regex Matchers
Section titled “Regex Matchers”A regex matcher is defined using inline code syntax with a specific format: `label:/pattern/`
`label:/regex-pattern/`- label: An identifier for the matched value (used in validation output)
- pattern: A regular expression that matches the content
The pattern is automatically anchored to the start (as if prefixed with ^), so it matches from the beginning of the available text.
Simple Examples
Section titled “Simple Examples”`name:/\w+/`Alice{"name": "Alice"}`age:/\d+/`42{"age": "42"}`name:/\w+/`123`age:/\d+/`not a numberAll Matchers
Section titled “All Matchers”All matchers act as an identity function - they always match and return exactly what was passed to them. If a matcher has no regex pattern (just a label in backticks), it becomes an all matcher that accepts all available content in the current context.
The syntax is simply `label` without a regex pattern.
`foo`anything goes here{"foo":"anything goes here"}`data`@*&^R special chars{"data":"@*&^R special chars"}All matchers accept any input including special characters, spaces, and other spanning (inline) nodes:
`text`hello *world* 123!{"text":"hello *world* 123!"}`content`*italic text* and regular text{"content":"*italic text* and regular text"}Prefix: `data`Prefix: *some italic* and more{"data":"*some italic* and more"}Matchers with Surrounding Text
Section titled “Matchers with Surrounding Text”Both regex matchers and all matchers can be combined with literal text as prefixes and suffixes:
Name: `name:/w+/`Name: Alice{"name":"Alice"}`count:/d+/` items42 items{"count":"42"}User `id:/d+/` logged inUser 123 logged in{"id":"123"}Name: `name:/w+/`Name:`count:/d+/` items42 thingsSpanning Multiple Node Types
Section titled “Spanning Multiple Node Types”Matchers can work across different spanning node types, like italics and subsequent code spans:
User `id:/d+/` logged in *this is italic*)User 123 logged in{"id":"123"}*test*test`foo:/bar/`wolf*test*testbarwolf{"foo":"bar"}Label Naming Rules
Section titled “Label Naming Rules”Matcher labels (for both regex matchers and all matchers) must follow these rules:
- Must contain only alphanumeric characters (a-z, A-Z, 0-9), hyphens (
-), and underscores (_) - Cannot contain spaces or other special characters
- Valid examples:
user_name,item-count,id123,MyData - Invalid examples:
user name(space),data@field(special char),item.count(period)
Empty Labels
Section titled “Empty Labels”To match without capturing a value, use an underscore (_) as the label:
`_:/w+/`hello{}Multiple Matchers
Section titled “Multiple Matchers”Right now, you can only have one matcher per paragraph (collection of spanning elements). So, for example, the following will not work:
`_:/w+/` `_:/w+/`helloRepeating Paragraphs
Section titled “Repeating Paragraphs”You can validate multiple paragraph nodes into an array by using a repeated matcher. The repeated matcher syntax is {min,max}, where min and max are optional.
Important: Repeating paragraph matchers must be all matchers (`label`), not regex matchers. This is because each paragraph can contain arbitrary content and structure.
`description`{2,3}First paragraph.
Second paragraph with *formatting*.
Third paragraph.{"description":["First paragraph.","Second paragraph with *formatting*.","Third paragraph."]}`content`{1,2}Only one paragraph here.{"content":["Only one paragraph here."]}`text`{3,3}First.
Second.Literal Code Blocks
Section titled “Literal Code Blocks”To match inline code blocks literally instead of treating them as matchers, add ! after the code block:
`test`!`test`The code is `example`! hereThe code is `example` here`test`!testEscaping the Exclamation Mark
Section titled “Escaping the Exclamation Mark”Use !! to match a literal exclamation mark after code:
`code`!!`code`!Execution Validation
Section titled “Execution Validation”You can validate content by running an executable. Use the syntax label:!command:
`number:!test $0 -gt 0`42{"number":"42"}The matched content is passed to the executable:
- As arguments (
$0,$1, etc.) - Via stdin (if command reads from stdin)
Exit code 0 means validation passes. Any other exit code indicates failure.