Skip to content

Commit a301eaa

Browse files
committed
✨ feat: add frontmatter extraction examples and documentation
Closes #1359
1 parent 3849289 commit a301eaa

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ mq 'select(.h1 || .h2)' example.html
329329

330330
# Extract specific cell from a Markdown table
331331
mq '.[1][2] | to_text()' data.md
332+
333+
# Extract frontmatter metadata from markdown files:
334+
import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title)
332335
```
333336
334337
### Using with markitdown

docs/books/src/start/example.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,13 @@ $ mq -A 'let headers = count_by(fn(x): x | select(.h);)
461461
| let anchor = downcase(replace(text, " ", "-"))
462462
| if (!is_empty(text)): s"${indent}- [${text}](#${anchor})"
463463
```
464+
465+
## Frontmatter Operations
466+
467+
Extract frontmatter metadata from markdown files:
468+
469+
```mq
470+
import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title)
471+
```
472+
473+

editors/vscode/src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def snake_to_camel(x):
3939
4040
# CSV parse
4141
include "csv" | csv_parse("a,b,c\n1,2,3\n4,5,6", true) | csv_to_markdown_table()
42+
43+
# Extract Front Matter
44+
import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title)
4245
`;
4346

4447
let client: lc.LanguageClient | null = null;

packages/mq-playground/src/examples.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ end
254254
- [Chapter2](Chapter2.md)
255255
- [Chapter3](Chapter3.md)
256256
- [Chapter4](Chapter4.md)
257+
`,
258+
isUpdate: false,
259+
format: "markdown",
260+
},
261+
{
262+
name: "Extract frontmatter data",
263+
code: `import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title)`,
264+
markdown: `---
265+
title: "Sample Document"
266+
author: "John Doe"
267+
date: "2024-01-01"
268+
---
269+
270+
# Sample Document
271+
272+
This is a sample document with frontmatter.
273+
257274
`,
258275
isUpdate: false,
259276
format: "markdown",

0 commit comments

Comments
 (0)