10
10
11
11
[ ** remark** ] [ remark ] plugin to support frontmatter (YAML, TOML, and more).
12
12
13
+ ## Important!
14
+
15
+ This plugin is affected by the new parser in remark
16
+ ([ ` micromark ` ] ( https://github.com/micromark/micromark ) ,
17
+ see [ ` remarkjs/remark#536 ` ] ( https://github.com/remarkjs/remark/pull/536 ) ).
18
+ Use version 2 while you’re still on remark 12.
19
+ Use version 3 for remark 13+.
20
+
13
21
## Install
14
22
15
23
[ npm] [ ] :
@@ -45,9 +53,9 @@ unified()
45
53
.use (stringify)
46
54
.use (frontmatter, [' yaml' , ' toml' ])
47
55
.use (logger)
48
- .process (vfile .readSync (' example.md' ), function (err , file ) {
49
- console .log (String (file))
56
+ .process (vfile .readSync (' example.md' ), function (err , file ) {
50
57
console .error (report (err || file))
58
+ console .log (String (file))
51
59
})
52
60
53
61
function logger () {
@@ -58,16 +66,17 @@ function logger() {
58
66
Now, running ` node example ` yields:
59
67
60
68
``` js
61
- { type: ' root' ,
62
- children:
63
- [ { type: ' toml' ,
64
- value: ' title = "New Website"' ,
65
- position: [Object ] },
66
- { type: ' heading' ,
67
- depth: 1 ,
68
- children: [Array ],
69
- position: [Object ] } ],
70
- position: [Object ] }
69
+ {
70
+ type: ' root' ,
71
+ children: [
72
+ {type: ' toml' , value: ' title = "New Website"' , position: [Object ]},
73
+ {type: ' heading' , depth: 1 , children: [Array ], position: [Object ]}
74
+ ],
75
+ position: {
76
+ start: {line: 1 , column: 1 , offset: 0 },
77
+ end: {line: 6 , column: 1 , offset: 48 }
78
+ }
79
+ }
71
80
```
72
81
73
82
``` markdown
@@ -83,117 +92,12 @@ title = "New Website"
83
92
84
93
### ` remark().use(frontmatter[, options]) `
85
94
86
- Support frontmatter (YAML, TOML, and more).
87
- Adds [ tokenizers] [ ] if the [ processor] [ ] is configured with
88
- [ ` remark-parse ` ] [ parse ] , and [ visitors] [ ] if configured with
89
- [ ` remark-stringify ` ] [ stringify ] .
90
-
91
- If you are parsing from a different syntax, or compiling to a different syntax
92
- (such as, [ ` remark-man ` ] [ man ] ) your custom nodes may not be supported.
95
+ Configures remark so that it can parse and serialize frontmatter (YAML, TOML,
96
+ and more).
93
97
94
98
##### ` options `
95
99
96
- One [ ` preset ` ] [ preset ] or [ ` Matter ` ] [ matter ] , or an array of them, defining all
97
- the supported frontmatters (default: ` 'yaml' ` ).
98
-
99
- ##### ` preset `
100
-
101
- Either ` 'yaml' ` or ` 'toml' ` :
102
-
103
- * ` 'yaml' ` — [ ` matter ` ] [ matter ] defined as ` {type: 'yaml', marker: '-'} `
104
- * ` 'toml' ` — [ ` matter ` ] [ matter ] defined as ` {type: 'toml', marker: '+'} `
105
-
106
- ##### ` Matter `
107
-
108
- An object with a ` type ` and either a ` marker ` or a ` fence ` :
109
-
110
- * ` type ` (` string ` )
111
- — Node type to parse to in [ mdast] [ ] and compile from
112
- * ` marker ` (` string ` or ` {open: string, close: string} ` )
113
- — Character used to construct fences.
114
- By providing an object with ` open ` and ` close ` .
115
- different characters can be used for opening and closing fences.
116
- For example the character ` '-' ` will result in ` '---' ` being used as the
117
- fence
118
- * ` fence ` (` string ` or ` {open: string, close: string} ` )
119
- — String used as the complete fence.
120
- By providing an object with ` open ` and ` close ` different values can be used
121
- for opening and closing fences.
122
- This can be used too if fences contain different characters or lengths other
123
- than 3
124
- * ` anywhere ` (` boolean ` , default: ` false ` )
125
- – if ` true ` , matter can be found anywhere in the document.
126
- If ` false ` (default), only matter at the start of the document is recognized
127
-
128
- ###### Example
129
-
130
- For ` {type: 'yaml', marker: '-'} ` :
131
-
132
- ``` yaml
133
- ---
134
- key : value
135
- ---
136
- ```
137
-
138
- Yields:
139
-
140
- ``` json
141
- {
142
- "type" : " yaml" ,
143
- "value" : " key: value"
144
- }
145
- ```
146
-
147
- For ` {type: 'custom', marker: {open: '<', close: '>'}} ` :
148
-
149
- ``` text
150
- <<<
151
- data
152
- >>>
153
- ```
154
-
155
- Yields:
156
-
157
- ``` json
158
- {
159
- "type" : " custom" ,
160
- "value" : " data"
161
- }
162
- ```
163
-
164
- For ` {type: 'custom', fence: '+=+=+=+'} ` :
165
-
166
- ``` text
167
- +=+=+=+
168
- data
169
- +=+=+=+
170
- ```
171
-
172
- Yields:
173
-
174
- ``` json
175
- {
176
- "type" : " custom" ,
177
- "value" : " data"
178
- }
179
- ```
180
-
181
- For ` {type: 'json', fence: {open: '{', close: '}'}} ` :
182
-
183
- ``` json
184
- {
185
- "key" : " value"
186
- }
187
- ```
188
-
189
- Yields:
190
-
191
- ``` json
192
- {
193
- "type" : " json" ,
194
- "value" : " \" key\" : \" value\" "
195
- }
196
- ```
100
+ See [ ` micromark-extension-frontmatter ` ] [ options ] for a description of ` options ` .
197
101
198
102
## Security
199
103
@@ -203,10 +107,14 @@ Use of `remark-frontmatter` does not involve [**rehype**][rehype]
203
107
204
108
## Related
205
109
110
+ * [ ` remark-gfm ` ] ( https://github.com/remarkjs/remark-gfm )
111
+ — GitHub Flavored Markdown
112
+ * [ ` remark-footnotes ` ] ( https://github.com/remarkjs/remark-footnotes )
113
+ — Footnotes
114
+ * [ ` remark-math ` ] ( https://github.com/remarkjs/remark-math )
115
+ — Math
206
116
* [ ` remark-github ` ] ( https://github.com/remarkjs/remark-github )
207
117
— Auto-link references like in GitHub issues, PRs, and comments
208
- * [ ` remark-math ` ] ( https://github.com/rokt33r/remark-math )
209
- — Math support
210
118
* [ ` remark-yaml-config ` ] ( https://github.com/remarkjs/remark-yaml-config )
211
119
— Configure remark from YAML configuration
212
120
@@ -268,26 +176,10 @@ abide by its terms.
268
176
269
177
[ remark ] : https://github.com/remarkjs/remark
270
178
271
- [ parse ] : https://github.com/remarkjs/remark/tree/HEAD/packages/remark-parse
272
-
273
- [ tokenizers ] : https://github.com/remarkjs/remark/tree/HEAD/packages/remark-parse#parserblocktokenizers
274
-
275
- [ stringify ] : https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify
276
-
277
- [ visitors ] : https://github.com/remarkjs/remark/tree/HEAD/packages/remark-stringify#compilervisitors
278
-
279
- [ processor ] : https://github.com/unifiedjs/unified#processor
280
-
281
- [ mdast ] : https://github.com/syntax-tree/mdast
282
-
283
- [ man ] : https://github.com/remarkjs/remark-man
284
-
285
- [ preset ] : #preset
286
-
287
- [ matter ] : #matter
288
-
289
179
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
290
180
291
181
[ rehype ] : https://github.com/rehypejs/rehype
292
182
293
183
[ hast ] : https://github.com/syntax-tree/hast
184
+
185
+ [ options ] : https://github.com/micromark/micromark-extension-frontmatter#options
0 commit comments