Skip to content

Commit 6cc9071

Browse files
committed
.
0 parents  commit 6cc9071

14 files changed

+744
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.DS_Store
2+
*.log
3+
.nyc_output/
4+
coverage/
5+
node_modules/
6+
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
*.json
3+
*.md

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- lts/dubnium
4+
- node
5+
after_script: bash <(curl -s https://codecov.io/bash)

from-markdown.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/from-markdown')

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
exports.fromMarkdown = require('./lib/from-markdown')
2+
exports.toMarkdown = require('./lib/to-markdown')

lib/from-markdown.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
var matters = require('micromark-extension-frontmatter/lib/matters')
2+
3+
module.exports = createFromMarkdown
4+
5+
function createFromMarkdown(options) {
6+
var settings = matters(options)
7+
var length = settings.length
8+
var index = -1
9+
var enter = {}
10+
var exit = {}
11+
var matter
12+
13+
while (++index < length) {
14+
matter = settings[index]
15+
enter[matter.type] = opener(matter)
16+
exit[matter.type] = close
17+
exit[matter.type + 'Value'] = value
18+
}
19+
20+
return {enter: enter, exit: exit}
21+
}
22+
23+
function opener(matter) {
24+
return open
25+
function open(token) {
26+
this.enter({type: matter.type, value: ''}, token)
27+
this.buffer()
28+
}
29+
}
30+
31+
function close(token) {
32+
var data = this.resume()
33+
// Remove the initial and final eol.
34+
this.exit(token).value = data.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, '')
35+
}
36+
37+
function value(token) {
38+
this.handlers.enter.data.call(this, token)
39+
this.handlers.exit.data.call(this, token)
40+
}

lib/to-markdown.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
var matters = require('micromark-extension-frontmatter/lib/matters')
2+
3+
module.exports = createToMarkdown
4+
5+
function createToMarkdown(options) {
6+
var unsafe = []
7+
var handlers = {}
8+
var settings = matters(options)
9+
var length = settings.length
10+
var index = -1
11+
var matter
12+
13+
while (++index < length) {
14+
matter = settings[index]
15+
handlers[matter.type] = handler(matter)
16+
unsafe.push({atBreak: true, character: fence(matter, 'open').charAt(0)})
17+
}
18+
19+
return {unsafe: unsafe, handlers: handlers}
20+
}
21+
22+
function handler(matter) {
23+
var open = fence(matter, 'open')
24+
var close = fence(matter, 'close')
25+
26+
return handle
27+
28+
function handle(node) {
29+
return open + (node.value ? '\n' + node.value : '') + '\n' + close
30+
}
31+
}
32+
33+
function fence(matter, prop) {
34+
var marker
35+
36+
if (matter.marker) {
37+
marker = pick(matter.marker, prop)
38+
return marker + marker + marker
39+
}
40+
41+
return pick(matter.fence, prop)
42+
}
43+
44+
function pick(schema, prop) {
45+
return typeof schema === 'string' ? schema : schema[prop]
46+
}

license

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(The MIT License)
2+
3+
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
'Software'), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

package.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "mdast-util-frontmatter",
3+
"version": "0.0.0",
4+
"description": "mdast extension to parse and serialize frontmatter (YAML, TOML, etc)",
5+
"license": "MIT",
6+
"keywords": [
7+
"unist",
8+
"mdast",
9+
"mdast-util",
10+
"util",
11+
"utility",
12+
"markdown",
13+
"markup",
14+
"frontmatter",
15+
"yaml",
16+
"toml",
17+
"gfm"
18+
],
19+
"repository": "syntax-tree/mdast-util-frontmatter",
20+
"bugs": "https://github.com/syntax-tree/mdast-util-frontmatter/issues",
21+
"funding": {
22+
"type": "opencollective",
23+
"url": "https://opencollective.com/unified"
24+
},
25+
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
26+
"contributors": [
27+
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
28+
],
29+
"files": [
30+
"lib/",
31+
"from-markdown.js",
32+
"index.js",
33+
"to-markdown.js"
34+
],
35+
"dependencies": {
36+
"micromark-extension-frontmatter": "^0.1.0"
37+
},
38+
"devDependencies": {
39+
"mdast-util-from-markdown": "^0.2.0",
40+
"mdast-util-to-markdown": "^0.2.0",
41+
"nyc": "^15.0.0",
42+
"prettier": "^2.0.0",
43+
"remark-cli": "^8.0.0",
44+
"remark-preset-wooorm": "^7.0.0",
45+
"tape": "^5.0.0",
46+
"xo": "^0.33.0"
47+
},
48+
"scripts": {
49+
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
50+
"test-api": "node test",
51+
"test-coverage": "nyc --reporter lcov tape test.js",
52+
"test": "npm run format && npm run test-coverage"
53+
},
54+
"nyc": {
55+
"check-coverage": true,
56+
"lines": 100,
57+
"functions": 100,
58+
"branches": 100
59+
},
60+
"prettier": {
61+
"tabWidth": 2,
62+
"useTabs": false,
63+
"singleQuote": true,
64+
"bracketSpacing": false,
65+
"semi": false,
66+
"trailingComma": "none"
67+
},
68+
"xo": {
69+
"prettier": true,
70+
"esnext": false
71+
},
72+
"remarkConfig": {
73+
"plugins": [
74+
"preset-wooorm"
75+
]
76+
}
77+
}

0 commit comments

Comments
 (0)