-
Notifications
You must be signed in to change notification settings - Fork 6
✨ feat: add frontmatter extraction examples and documentation #1384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Closes #1359
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||
|
||||||
| import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title) | |
| mq 'import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title)' data.md |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||
|
||||||
| import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title) | |
| import "yaml" | if (.yaml): do yaml::yaml_parse() | get(:title) end |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||
|
||||||
| import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title) | |
| import "yaml" | if (.yaml): do yaml::yaml_parse() | get(:title) end |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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)`, | ||||||
|
||||||
| code: `import "yaml" | if (.yaml): yaml::yaml_parse() | get(:title)`, | |
| code: `import "yaml" | if (.yaml): do yaml::yaml_parse() | get(:title) end`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README’s mq query uses
if (.yaml): yaml::yaml_parse() | get(:title), which is parsed as(if (.yaml): yaml::yaml_parse()) | get(:title);get(:title)still runs for non-frontmatter nodes and relies onget(None, …) -> None. For a clearer copy/paste example, consider wrapping the piped expressions indo ... endinside theif(in addition to making it a runnablemq '…' file.mdcommand).