diff --git a/README.md b/README.md index 026c1ac72..5cf420e9d 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,9 @@ mq 'select(.h1 || .h2)' example.html # Extract specific cell from a Markdown table mq '.[1][2] | to_text()' data.md + +# Extract frontmatter metadata from markdown files: +import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title) ``` ### Using with markitdown diff --git a/docs/books/src/start/example.md b/docs/books/src/start/example.md index 98fdaa2b9..38a9fb9ea 100644 --- a/docs/books/src/start/example.md +++ b/docs/books/src/start/example.md @@ -461,3 +461,13 @@ $ mq -A 'let headers = count_by(fn(x): x | select(.h);) | let anchor = downcase(replace(text, " ", "-")) | if (!is_empty(text)): s"${indent}- [${text}](#${anchor})" ``` + +## Frontmatter Operations + +Extract frontmatter metadata from markdown files: + +```mq +import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title) +``` + + diff --git a/editors/vscode/src/extension.ts b/editors/vscode/src/extension.ts index a108d706e..802ac124f 100644 --- a/editors/vscode/src/extension.ts +++ b/editors/vscode/src/extension.ts @@ -39,6 +39,9 @@ def snake_to_camel(x): # CSV parse include "csv" | csv_parse("a,b,c\n1,2,3\n4,5,6", true) | csv_to_markdown_table() + +# Extract Front Matter +import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title) `; let client: lc.LanguageClient | null = null; diff --git a/packages/mq-playground/src/examples.ts b/packages/mq-playground/src/examples.ts index c39888cb8..1c69d07f9 100644 --- a/packages/mq-playground/src/examples.ts +++ b/packages/mq-playground/src/examples.ts @@ -254,6 +254,23 @@ end - [Chapter2](Chapter2.md) - [Chapter3](Chapter3.md) - [Chapter4](Chapter4.md) +`, + isUpdate: false, + format: "markdown", + }, + { + name: "Extract frontmatter data", + code: `import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title)`, + markdown: `--- +title: "Sample Document" +author: "John Doe" +date: "2024-01-01" +--- + +# Sample Document + +This is a sample document with frontmatter. + `, isUpdate: false, format: "markdown",