Skip to content

Commit b6423c9

Browse files
committed
.
0 parents  commit b6423c9

File tree

12 files changed

+1650
-0
lines changed

12 files changed

+1650
-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: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
var decode = require('parse-entities/decode-entity')
2+
3+
exports.canContainEols = ['textDirective']
4+
exports.enter = {
5+
directiveContainer: enterContainer,
6+
directiveContainerAttributes: enterAttributes,
7+
directiveContainerLabel: enterContainerLabel,
8+
9+
directiveLeaf: enterLeaf,
10+
directiveLeafAttributes: enterAttributes,
11+
12+
directiveText: enterText,
13+
directiveTextAttributes: enterAttributes
14+
}
15+
exports.exit = {
16+
directiveContainer: exit,
17+
directiveContainerAttributeClassValue: exitAttributeClassValue,
18+
directiveContainerAttributeIdValue: exitAttributeIdValue,
19+
directiveContainerAttributeName: exitAttributeName,
20+
directiveContainerAttributeValue: exitAttributeValue,
21+
directiveContainerAttributes: exitAttributes,
22+
directiveContainerLabel: exitContainerLabel,
23+
directiveContainerName: exitName,
24+
25+
directiveLeaf: exit,
26+
directiveLeafAttributeClassValue: exitAttributeClassValue,
27+
directiveLeafAttributeIdValue: exitAttributeIdValue,
28+
directiveLeafAttributeName: exitAttributeName,
29+
directiveLeafAttributeValue: exitAttributeValue,
30+
directiveLeafAttributes: exitAttributes,
31+
directiveLeafName: exitName,
32+
33+
directiveText: exit,
34+
directiveTextAttributeClassValue: exitAttributeClassValue,
35+
directiveTextAttributeIdValue: exitAttributeIdValue,
36+
directiveTextAttributeName: exitAttributeName,
37+
directiveTextAttributeValue: exitAttributeValue,
38+
directiveTextAttributes: exitAttributes,
39+
directiveTextName: exitName
40+
}
41+
42+
function enterContainer(token) {
43+
enter.call(this, 'containerDirective', token)
44+
}
45+
46+
function enterLeaf(token) {
47+
enter.call(this, 'leafDirective', token)
48+
}
49+
50+
function enterText(token) {
51+
enter.call(this, 'textDirective', token)
52+
}
53+
54+
function enter(type, token) {
55+
this.enter({type: type, name: '', attributes: {}, children: []}, token)
56+
}
57+
58+
function exitName(token) {
59+
this.stack[this.stack.length - 1].name = this.sliceSerialize(token)
60+
}
61+
62+
function enterContainerLabel(token) {
63+
this.enter(
64+
{type: 'paragraph', data: {directiveLabel: true}, children: []},
65+
token
66+
)
67+
}
68+
69+
function exitContainerLabel(token) {
70+
this.exit(token)
71+
}
72+
73+
function enterAttributes() {
74+
this.setData('directiveAttributes', [])
75+
this.buffer() // Capture EOLs
76+
}
77+
78+
function exitAttributeIdValue(token) {
79+
this.getData('directiveAttributes').push([
80+
'id',
81+
decodeLight(this.sliceSerialize(token))
82+
])
83+
}
84+
85+
function exitAttributeClassValue(token) {
86+
this.getData('directiveAttributes').push([
87+
'class',
88+
decodeLight(this.sliceSerialize(token))
89+
])
90+
}
91+
92+
function exitAttributeValue(token) {
93+
var attributes = this.getData('directiveAttributes')
94+
attributes[attributes.length - 1][1] = decodeLight(this.sliceSerialize(token))
95+
}
96+
97+
function exitAttributeName(token) {
98+
// Attribute names in CommonMark are significantly limited, so character
99+
// references can’t exist.
100+
this.getData('directiveAttributes').push([this.sliceSerialize(token), ''])
101+
}
102+
103+
function exitAttributes() {
104+
var attributes = this.getData('directiveAttributes')
105+
var cleaned = {}
106+
var index = -1
107+
var attribute
108+
109+
while (++index < attributes.length) {
110+
attribute = attributes[index]
111+
112+
if (attribute[0] === 'class' && cleaned.class) {
113+
cleaned.class += ' ' + attribute[1]
114+
} else {
115+
cleaned[attribute[0]] = attribute[1]
116+
}
117+
}
118+
119+
this.setData('directiveAttributes')
120+
this.resume() // Drop EOLs
121+
this.stack[this.stack.length - 1].attributes = cleaned
122+
}
123+
124+
function exit(token) {
125+
this.exit(token)
126+
}
127+
128+
function decodeLight(value) {
129+
return value.replace(
130+
/&(#(\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi,
131+
decodeIfPossible
132+
)
133+
}
134+
135+
function decodeIfPossible($0, $1) {
136+
return decode($1) || $0
137+
}

index.js

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

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 <[email protected]>
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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"name": "mdast-util-directive",
3+
"version": "0.0.0",
4+
"description": "mdast extension to parse and serialize generic directives (`:cite[smith04]`)",
5+
"license": "MIT",
6+
"keywords": [
7+
"unist",
8+
"mdast",
9+
"mdast-util",
10+
"util",
11+
"utility",
12+
"markdown",
13+
"markup",
14+
"generic",
15+
"directive",
16+
"container",
17+
"extension"
18+
],
19+
"repository": "syntax-tree/mdast-util-directive",
20+
"bugs": "https://github.com/syntax-tree/mdast-util-directive/issues",
21+
"funding": {
22+
"type": "opencollective",
23+
"url": "https://opencollective.com/unified"
24+
},
25+
"author": "Titus Wormer <[email protected]> (https://wooorm.com)",
26+
"contributors": [
27+
"Titus Wormer <[email protected]> (https://wooorm.com)"
28+
],
29+
"files": [
30+
"from-markdown.js",
31+
"index.js",
32+
"to-markdown.js"
33+
],
34+
"dependencies": {
35+
"mdast-util-to-markdown": "^0.5.0",
36+
"parse-entities": "^2.0.0",
37+
"repeat-string": "^1.0.0",
38+
"stringify-entities": "^3.1.0",
39+
"unist-util-visit-parents": "^3.0.0"
40+
},
41+
"devDependencies": {
42+
"mdast-util-from-markdown": "^0.8.0",
43+
"micromark-extension-directive": "^1.0.0",
44+
"nyc": "^15.0.0",
45+
"prettier": "^2.0.0",
46+
"remark-cli": "^9.0.0",
47+
"remark-preset-wooorm": "^8.0.0",
48+
"tape": "^5.0.0",
49+
"unist-util-remove-position": "^3.0.0",
50+
"xo": "^0.34.0"
51+
},
52+
"scripts": {
53+
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
54+
"test-api": "node test",
55+
"test-coverage": "nyc --reporter lcov tape test.js",
56+
"test": "npm run format && npm run test-coverage"
57+
},
58+
"nyc": {
59+
"check-coverage": true,
60+
"lines": 100,
61+
"functions": 100,
62+
"branches": 100
63+
},
64+
"prettier": {
65+
"tabWidth": 2,
66+
"useTabs": false,
67+
"singleQuote": true,
68+
"bracketSpacing": false,
69+
"semi": false,
70+
"trailingComma": "none"
71+
},
72+
"xo": {
73+
"prettier": true,
74+
"esnext": false,
75+
"rules": {
76+
"unicorn/explicit-length-check": "off",
77+
"no-eq-null": "off",
78+
"eqeqeq": "off"
79+
}
80+
},
81+
"remarkConfig": {
82+
"plugins": [
83+
"preset-wooorm"
84+
]
85+
}
86+
}

0 commit comments

Comments
 (0)