You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .verb.md
+16-19Lines changed: 16 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -10,9 +10,9 @@ Please see the [changelog](CHANGELOG.md) to learn about breaking changes that we
10
10
Add the HTML in the following example to `example.html`, then add the following code to `example.js` and run `$ node example` (without the `$`):
11
11
12
12
```js
13
-
var fs =require('fs');
14
-
var matter =require('gray-matter');
15
-
var str =fs.readFileSync('example.html', 'utf8');
13
+
constfs=require('fs');
14
+
constmatter=require('gray-matter');
15
+
conststr=fs.readFileSync('example.html', 'utf8');
16
16
console.log(matter(str));
17
17
```
18
18
@@ -72,10 +72,10 @@ Some libraries met most of the requirements, but _none met all of them_.
72
72
* Have no problem with complex content, including **non-front-matter** fenced code blocks that contain examples of YAML front matter. Other parsers fail on this.
73
73
* Support stringifying back to front-matter. This is useful for linting, updating properties, etc.
74
74
* Allow custom delimiters, when it's necessary for avoiding delimiter collision.
75
-
* Should return an object with at least these three properties (for debugging):
75
+
* Should return an object with at least these three properties:
76
76
-`data`: the parsed YAML front matter, as a JSON object
77
77
-`content`: the contents as a string, without the front matter
78
-
-`orig`: the "original" content
78
+
-`orig`: the "original" content (for debugging)
79
79
80
80
</details>
81
81
@@ -85,7 +85,7 @@ Some libraries met most of the requirements, but _none met all of them_.
85
85
Using Node's `require()` system:
86
86
87
87
```js
88
-
var matter =require('gray-matter');
88
+
constmatter=require('gray-matter');
89
89
```
90
90
91
91
Or with [typescript](https://www.typescriptlang.org)
@@ -126,6 +126,7 @@ gray-matter returns a `file` object with the following properties.
126
126
-`file.data`**{Object}**: the object created by parsing front-matter
127
127
-`file.content`**{String}**: the input string, with `matter` stripped
128
128
-`file.excerpt`**{String}**: an excerpt, if [defined on the options](#optionsexcerpt)
129
+
-`file.empty`**{String}**: when the front-matter is "empty" (either all whitespace, nothing at all, or just comments and no data), the original string is set on this property. See [#65](https://github.com/jonschlinkert/gray-matter/issues/65) for details regarding use case.
129
130
130
131
**Non-enumerable**
131
132
@@ -134,7 +135,7 @@ In addition, the following non-enumberable properties are added to the object to
134
135
-`file.orig`**{Buffer}**: the original input string (or buffer)
135
136
-`file.language`**{String}**: the front-matter language that was parsed. `yaml` is the default
136
137
-`file.matter`**{String}**: the _raw_, un-parsed front-matter string
137
-
-`file.stringify`**{Function}**: [stringify](#stringify) the file by converting `file.data` to a string in the given language, wrapping it in delimiters and appending it to `file.content`.
138
+
-`file.stringify`**{Function}**: [stringify](#stringify) the file by converting `file.data` to a string in the given language, wrapping it in delimiters and prepending it to `file.content`.
138
139
139
140
140
141
## Run the examples
@@ -157,6 +158,8 @@ Then run any of the [examples](./examples) to see how gray-matter works:
157
158
$ node examples/<example_name>
158
159
```
159
160
161
+
**Links to examples**
162
+
160
163
{%= examples() %}
161
164
162
165
@@ -179,14 +182,8 @@ If set to `excerpt: true`, it will look for the frontmatter delimiter, `---` by
179
182
**Example**
180
183
181
184
```js
182
-
var file =matter([
183
-
'---',
184
-
'foo: bar',
185
-
'---',
186
-
'This is an excerpt.',
187
-
'---',
188
-
'This is content'
189
-
].join('\n'), {excerpt:true});
185
+
conststr='---\nfoo: bar\n---\nThis is an excerpt.\n---\nThis is content';
186
+
constfile=matter(str, { excerpt:true });
190
187
```
191
188
192
189
Results in:
@@ -209,7 +206,7 @@ function firstFourLines(file, options) {
*`toml`, `coffee` and `cson` are no longer supported by default. Please see [`options.engines`](README.md#optionsengines) and the [examples](./examples) to learn how to add engines.
13
+
14
+
-`toml`, `coffee` and `cson` are no longer supported by default. Please see [`options.engines`](README.md#optionsengines) and the [examples](./examples) to learn how to add engines.
8
15
9
16
### Added
10
-
* Support for [excerpts](README.md#optionsexcerpt).
11
-
* The returned object now has non-enumerable `matter` and `stringify` properties.
17
+
18
+
- Support for [excerpts](README.md#optionsexcerpt).
19
+
- The returned object now has non-enumerable `matter` and `stringify` properties.
12
20
13
21
### Changed
14
-
* Refactored engines (parsers), so that it's easier to add parsers and stringifiers.
15
-
*`options.parsers` was renamed to [`options.engines`](README.md#optionsengines)
22
+
23
+
- Refactored engines (parsers), so that it's easier to add parsers and stringifiers.
24
+
-`options.parsers` was renamed to [`options.engines`](README.md#optionsengines)
0 commit comments