Skip to content

Commit

Permalink
Add support for optional mid-matter parsing
Browse files Browse the repository at this point in the history
Closes GH-6.

Reviewed-by: Titus Wormer <[email protected]>
  • Loading branch information
trieloff authored and wooorm committed Sep 23, 2018
1 parent df849b7 commit 003b02a
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ function create(matter) {
var open = fence(matter, 'open')
var close = fence(matter, 'close')
var newline = '\n'
var anywhere = matter.anywhere

frontmatter.displayName = name
frontmatter.onlyAtStart = true
frontmatter.onlyAtStart = typeof anywhere === 'boolean' ? !anywhere : true

return [name, frontmatter]

Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ An object with a `type` and either a `marker` or a `fence`:
the complete fence. By providing an object with `open` and `close`
different values can be used for opening and closing fences. This can be
used too if fences contain different characters or lengths other than 3
* `anywhere` (`boolean`, default: `false`) – if `true`, matter can be
found anywhere in the document. If `false` (default), only matter at the
start of the document is recognised.

###### Example

Expand Down
1 change: 1 addition & 0 deletions test/fixtures/custom-yaml-anywhere/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "yaml", "marker": "-", "anywhere": true}
7 changes: 7 additions & 0 deletions test/fixtures/custom-yaml-anywhere/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# YAML not at the top

---
title: post
---

some text
7 changes: 7 additions & 0 deletions test/fixtures/custom-yaml-anywhere/output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# YAML not at the top

---
title: post
---

some text
108 changes: 108 additions & 0 deletions test/fixtures/custom-yaml-anywhere/tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"type": "root",
"children": [
{
"type": "heading",
"depth": 1,
"children": [
{
"type": "text",
"value": "YAML not at the top",
"position": {
"start": {
"line": 1,
"column": 3,
"offset": 2
},
"end": {
"line": 1,
"column": 22,
"offset": 21
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 1,
"column": 22,
"offset": 21
},
"indent": []
}
},
{
"type": "yaml",
"value": "title: post",
"position": {
"start": {
"line": 3,
"column": 1,
"offset": 23
},
"end": {
"line": 5,
"column": 4,
"offset": 42
},
"indent": [
1,
1
]
}
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "some text",
"position": {
"start": {
"line": 7,
"column": 1,
"offset": 44
},
"end": {
"line": 7,
"column": 10,
"offset": 53
},
"indent": []
}
}
],
"position": {
"start": {
"line": 7,
"column": 1,
"offset": 44
},
"end": {
"line": 7,
"column": 10,
"offset": 53
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 8,
"column": 1,
"offset": 54
}
}
}

0 comments on commit 003b02a

Please sign in to comment.