Code Blocks
Fenced code blocks can be validated for both their language specifier and content.
Literal Matching
Section titled “Literal Matching”Code blocks match literally by default - both language and content must be identical. This is similar to how literal matchers in general work.
```rustfn main() {}``````rustfn main() {}``````rustfn main() {}``````pythonfn main() {}``````rustfn main() {}``````rustprint('hello')```Language Matcher
Section titled “Language Matcher”Use {label:/pattern/} in the language position to match language specifiers:
```{lang:/w+/}fn main() {}``````rustfn main() {}```{"lang":"rust"}```{lang:/w+/}fn main() {}``````javascriptfn main() {}```{"lang":"javascript"}```{lang:/w+/}fn main() {}``````rustprint('hello')```Content Capture
Section titled “Content Capture”Use {id} in the code content to capture the entire code block without validation:
```rust{code}``````rustprint('hello')```{"code":"print('hello')"}Content Validation
Section titled “Content Validation”You can validate code block content by specifying an executable to run. The code content is passed via stdin to the executable.
Use the syntax {id:!executable} to validate and capture code content:
```python{code:!python -m py_compile -}``````pythonprint('hello')```{"code":"print('hello')"}```python{code:!python -m py_compile -}``````pythonthis is invalid python```The executable receives the code content via stdin. If the executable exits with code 0, the validation passes. Any other exit code indicates validation failure.
Combined Language and Content
Section titled “Combined Language and Content”Match language with a pattern and capture content:
```{lang:/w+/}{code}``````pythonprint('hello')```{"lang":"python","code":"print('hello')"}```{lang:/w+/}{code}``````rustfn main() {}```{"lang":"rust","code":"fn main() {}"}Execution Validation
Section titled “Execution Validation”You can validate code block content using the same execution validation pattern as inline matchers. Use {id:!executable}:
```python{code:!python -m py_compile -}``````pythonprint('hello')```{"code":"print('hello')"}```python{code:!python -m py_compile -}``````pythonthis is invalid python```The code content is passed via stdin to the executable. Exit code 0 means validation passes.
- Language matchers support the same regex patterns as inline matchers
- Content can only be captured with
{id}, not validated with regex - Both language and content are optional in the schema and input