Parsing helpers for markdown instruction files: extracts @file references and !`shell` directives from templates and parses YAML frontmatter (with a permissive fallback for malformed YAML).
Members
(static, constant) FILE_REGEX
Matches @path file references in a template (not preceded by a word char or backtick).
(static, constant) FrontmatterError
Error thrown when a markdown file's YAML frontmatter cannot be parsed.
(static, constant) SHELL_REGEX
Matches !`command` shell directives in a template.
Methods
(static) fallbackSanitization(content) → {string}
Sanitize a document's YAML frontmatter so a stricter parser can read it. Leaves comments, blank lines, indented continuations, empty/quoted/block-scalar values untouched, and converts key: value pairs whose value contains a colon into a block scalar (key: |-) so the inner colon does not break YAML parsing.
| Name | Type | Description |
|---|---|---|
content | string | The full document text (frontmatter plus body). |
The document with its frontmatter sanitized, or the original content unchanged when no frontmatter block is present.
- Type:
- string
(static) files(template) → {Array}
Find all @path file references in a template.
| Name | Type | Description |
|---|---|---|
template | string | The template text to scan. |
An array of RegExp match objects, one per file reference.
- Type:
- Array
(static) parse(filePath) → {Promise.<Object>}
Read and parse a markdown instruction file, returning its frontmatter and body. Attempts a strict parse first, then retries through fallbackSanitization for files with malformed YAML frontmatter.
| Name | Type | Description |
|---|---|---|
filePath | string | Absolute path to the markdown file. |
When the frontmatter cannot be parsed even after sanitization.
- Type
- FrontmatterError
The parsed gray-matter result ({ data, content, ... }).
- Type:
- Promise.<Object>
(static) shell(template) → {Array}
Find all !`command` shell directives in a template.
| Name | Type | Description |
|---|---|---|
template | string | The template text to scan. |
An array of RegExp match objects, one per shell directive.
- Type:
- Array