Skip to content

Commit 7746646

Browse files
committed
.
0 parents  commit 7746646

12 files changed

+613
-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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
exports.exit = {
2+
taskListCheckValueChecked: exitCheck,
3+
taskListCheckValueUnchecked: exitCheck,
4+
paragraph: exitParagraphWithTaskListItem
5+
}
6+
7+
function exitCheck(token) {
8+
// We’re always in a paragraph, in a list item.
9+
this.stack[this.stack.length - 2].checked =
10+
token.type === 'taskListCheckValueChecked'
11+
}
12+
13+
function exitParagraphWithTaskListItem(token) {
14+
var node = this.stack[this.stack.length - 1]
15+
var parent = this.stack[this.stack.length - 2]
16+
var head = node.children[0]
17+
18+
if (
19+
parent.type === 'listItem' &&
20+
typeof parent.checked === 'boolean' &&
21+
head &&
22+
head.type === 'text'
23+
) {
24+
// Must start with a space or a tab.
25+
head.value = head.value.slice(1)
26+
}
27+
28+
this.exit(token)
29+
}

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

readme.md

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
# mdast-util-gfm-task-list-item
2+
3+
[![Build][build-badge]][build]
4+
[![Coverage][coverage-badge]][coverage]
5+
[![Downloads][downloads-badge]][downloads]
6+
[![Size][size-badge]][size]
7+
[![Sponsors][sponsors-badge]][collective]
8+
[![Backers][backers-badge]][collective]
9+
[![Chat][chat-badge]][chat]
10+
11+
Extension for [`mdast-util-from-markdown`][from-markdown] and/or
12+
[`mdast-util-to-markdown`][to-markdown] to support GitHub flavored markdown
13+
task list items in **[mdast][]**.
14+
When parsing (`from-markdown`), must be combined with
15+
[`micromark-extension-gfm-task-list-item`][extension].
16+
17+
You probably shouldn’t use this package directly, but instead use `remark-gfm`
18+
with **[remark][]**.
19+
20+
## Install
21+
22+
[npm][]:
23+
24+
```sh
25+
npm install mdast-util-gfm-task-list-item
26+
```
27+
28+
## Use
29+
30+
Say we have the following file, `example.md`:
31+
32+
```markdown
33+
* [ ] To do
34+
* [x] Done
35+
36+
1. Mixed…
37+
2. [x] …messages
38+
```
39+
40+
And our script, `example.js`, looks as follows:
41+
42+
```js
43+
var fs = require('fs')
44+
var fromMarkdown = require('mdast-util-from-markdown')
45+
var toMarkdown = require('mdast-util-to-markdown')
46+
var syntax = require('micromark-extension-gfm-task-list-item')
47+
var taskListItem = require('mdast-util-gfm-task-list-item')
48+
49+
var doc = fs.readFileSync('example.md')
50+
51+
var tree = fromMarkdown(doc, {
52+
extensions: [syntax],
53+
mdastExtensions: [taskListItem.fromMarkdown]
54+
})
55+
56+
console.log(tree)
57+
58+
var out = toMarkdown(tree, {extensions: [taskListItem.toMarkdown]})
59+
60+
console.log(out)
61+
```
62+
63+
Now, running `node example` yields (positional info removed for the sake of
64+
brevity):
65+
66+
```js
67+
{
68+
type: 'root',
69+
children: [
70+
{
71+
type: 'list',
72+
ordered: false,
73+
start: null,
74+
spread: false,
75+
children: [
76+
{
77+
type: 'listItem',
78+
spread: false,
79+
checked: false,
80+
children: [
81+
{type: 'paragraph', children: [{type: 'text', value: 'To do'}]}
82+
]
83+
},
84+
{
85+
type: 'listItem',
86+
spread: false,
87+
checked: true,
88+
children: [
89+
{type: 'paragraph', children: [{type: 'text', value: 'Done'}]}
90+
]
91+
}
92+
]
93+
},
94+
{
95+
type: 'list',
96+
ordered: true,
97+
start: 1,
98+
spread: false,
99+
children: [
100+
{
101+
type: 'listItem',
102+
spread: false,
103+
checked: null,
104+
children: [
105+
{type: 'paragraph', children: [{type: 'text', value: 'Mixed…'}]}
106+
]
107+
},
108+
{
109+
type: 'listItem',
110+
spread: false,
111+
checked: true,
112+
children: [
113+
{type: 'paragraph', children: [{type: 'text', value: '…messages'}]}
114+
]
115+
}
116+
]
117+
}
118+
]
119+
}
120+
```
121+
122+
```markdown
123+
* [ ] To do
124+
* [x] Done
125+
126+
1. Mixed…
127+
2. [x] …messages
128+
```
129+
130+
## API
131+
132+
### `taskListItem.fromMarkdown`
133+
134+
### `taskListItem.toMarkdown`
135+
136+
> Note: the separate extensions are also available at
137+
> `mdast-util-gfm-task-list-item/from-markdown` and
138+
> `mdast-util-gfm-task-list-item/to-markdown`.
139+
140+
Support task list items.
141+
The exports are extensions, respectively
142+
for [`mdast-util-from-markdown`][from-markdown] and
143+
[`mdast-util-to-markdown`][to-markdown].
144+
145+
## Related
146+
147+
* [`remarkjs/remark`][remark]
148+
— markdown processor powered by plugins
149+
* `remarkjs/remark-gfm`
150+
— remark plugin to support GFM
151+
* [`micromark/micromark`][micromark]
152+
— the smallest commonmark-compliant markdown parser that exists
153+
* [`micromark/micromark-extension-gfm-task-list-item`][extension]
154+
— micromark extension to parse GFM task list items
155+
* [`syntax-tree/mdast-util-from-markdown`][from-markdown]
156+
— mdast parser using `micromark` to create mdast from markdown
157+
* [`syntax-tree/mdast-util-to-markdown`][to-markdown]
158+
— mdast serializer to create markdown from mdast
159+
160+
## Contribute
161+
162+
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
163+
started.
164+
See [`support.md`][support] for ways to get help.
165+
166+
This project has a [code of conduct][coc].
167+
By interacting with this repository, organization, or community you agree to
168+
abide by its terms.
169+
170+
## License
171+
172+
[MIT][license] © [Titus Wormer][author]
173+
174+
<!-- Definitions -->
175+
176+
[build-badge]: https://img.shields.io/travis/syntax-tree/mdast-util-gfm-task-list-item.svg
177+
178+
[build]: https://travis-ci.org/syntax-tree/mdast-util-gfm-task-list-item
179+
180+
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-task-list-item.svg
181+
182+
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-task-list-item
183+
184+
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-task-list-item.svg
185+
186+
[downloads]: https://www.npmjs.com/package/mdast-util-gfm-task-list-item
187+
188+
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-gfm-task-list-item.svg
189+
190+
[size]: https://bundlephobia.com/result?p=mdast-util-gfm-task-list-item
191+
192+
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
193+
194+
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
195+
196+
[collective]: https://opencollective.com/unified
197+
198+
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
199+
200+
[chat]: https://github.com/syntax-tree/unist/discussions
201+
202+
[npm]: https://docs.npmjs.com/cli/install
203+
204+
[license]: license
205+
206+
[author]: https://wooorm.com
207+
208+
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
209+
210+
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
211+
212+
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
213+
214+
[mdast]: https://github.com/syntax-tree/mdast
215+
216+
[remark]: https://github.com/remarkjs/remark
217+
218+
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
219+
220+
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
221+
222+
[micromark]: https://github.com/micromark/micromark
223+
224+
[extension]: https://github.com/micromark/micromark-extension-gfm-task-list-item

0 commit comments

Comments
 (0)