Skip to content

Commit

Permalink
Add support for passing a single preset or matter
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 1, 2017
1 parent 3fc848b commit 9db1f5c
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/matters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ var markers = {

function matters(options) {
var results = [];
var length = options.length;
var index = -1;
var length;

/* One preset or matter. */
if (typeof options === 'string' || !('length' in options)) {
options = [options];
}

length = options.length;

while (++index < length) {
results[index] = matter(options[index]);
Expand Down
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ If you are parsing from a different syntax, or compiling to a different syntax

###### `options`

An optional configuration array defining all the supported frontmatters
(`Array.<preset|Matter>?`, default: `['yaml']`).
One [`preset`][preset] or [`Matter`][matter], or an array of them, defining all
the supported frontmatters (default: `'yaml'`).

###### `preset`

Expand Down Expand Up @@ -148,6 +148,8 @@ An object with a `type` and a `marker`:

[mdast]: https://github.com/syntax-tree/mdast

[preset]: #preset

[matter]: #matter

[man]: https://github.com/wooorm/remark-man
1 change: 1 addition & 0 deletions test/fixtures/config-options-as-matter/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "jsonml", "marker": "*"}
4 changes: 4 additions & 0 deletions test/fixtures/config-options-as-matter/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
***
***

# Empty
72 changes: 72 additions & 0 deletions test/fixtures/config-options-as-matter/tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"type": "root",
"children": [
{
"type": "jsonml",
"value": "",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 2,
"column": 4,
"offset": 7
},
"indent": [
1
]
}
},
{
"type": "heading",
"depth": 1,
"children": [
{
"type": "text",
"value": "Empty",
"position": {
"start": {
"line": 4,
"column": 3,
"offset": 11
},
"end": {
"line": 4,
"column": 8,
"offset": 16
},
"indent": []
}
}
],
"position": {
"start": {
"line": 4,
"column": 1,
"offset": 9
},
"end": {
"line": 4,
"column": 8,
"offset": 16
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 5,
"column": 1,
"offset": 17
}
}
}
1 change: 1 addition & 0 deletions test/fixtures/config-options-as-string/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"yaml"
4 changes: 4 additions & 0 deletions test/fixtures/config-options-as-string/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

# Empty
72 changes: 72 additions & 0 deletions test/fixtures/config-options-as-string/tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"type": "root",
"children": [
{
"type": "yaml",
"value": "",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 2,
"column": 4,
"offset": 7
},
"indent": [
1
]
}
},
{
"type": "heading",
"depth": 1,
"children": [
{
"type": "text",
"value": "Empty",
"position": {
"start": {
"line": 4,
"column": 3,
"offset": 11
},
"end": {
"line": 4,
"column": 8,
"offset": 16
},
"indent": []
}
}
],
"position": {
"start": {
"line": 4,
"column": 1,
"offset": 9
},
"end": {
"line": 4,
"column": 8,
"offset": 16
},
"indent": []
}
}
],
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
"end": {
"line": 5,
"column": 1,
"offset": 17
}
}
}

0 comments on commit 9db1f5c

Please sign in to comment.