Skip to content

Commit 7b884ef

Browse files
committed
.
0 parents  commit 7b884ef

12 files changed

+591
-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: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
exports.enter = {
2+
literalAutolink: enterLiteralAutolink,
3+
literalAutolinkEmail: enterLiteralAutolinkValue,
4+
literalAutolinkHttp: enterLiteralAutolinkValue,
5+
literalAutolinkWww: enterLiteralAutolinkValue
6+
}
7+
exports.exit = {
8+
literalAutolink: exitLiteralAutolink,
9+
literalAutolinkEmail: exitLiteralAutolinkEmail,
10+
literalAutolinkHttp: exitLiteralAutolinkHttp,
11+
literalAutolinkWww: exitLiteralAutolinkWww
12+
}
13+
14+
function enterLiteralAutolink(token) {
15+
this.enter({type: 'link', title: null, url: '', children: []}, token)
16+
}
17+
18+
function enterLiteralAutolinkValue(token) {
19+
this.config.enter.autolinkProtocol.call(this, token)
20+
}
21+
22+
function exitLiteralAutolinkHttp(token) {
23+
this.config.exit.autolinkProtocol.call(this, token)
24+
}
25+
26+
function exitLiteralAutolinkWww(token) {
27+
this.config.exit.data.call(this, token)
28+
this.stack[this.stack.length - 1].url = 'http://' + this.sliceSerialize(token)
29+
}
30+
31+
function exitLiteralAutolinkEmail(token) {
32+
this.config.exit.autolinkEmail.call(this, token)
33+
}
34+
35+
function exitLiteralAutolink(token) {
36+
this.exit(token)
37+
}

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: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "mdast-util-gfm-autolink-literal",
3+
"version": "0.0.0",
4+
"description": "mdast extension to parse and serialize GFM autolink literals",
5+
"license": "MIT",
6+
"keywords": [
7+
"unist",
8+
"mdast",
9+
"mdast-util",
10+
"util",
11+
"utility",
12+
"markdown",
13+
"markup",
14+
"autolink",
15+
"auto",
16+
"link",
17+
"literal",
18+
"url",
19+
"raw",
20+
"gfm"
21+
],
22+
"repository": "syntax-tree/mdast-util-gfm-autolink-literal",
23+
"bugs": "https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/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+
"devDependencies": {
39+
"mdast-util-from-markdown": "^0.4.0",
40+
"mdast-util-to-markdown": "^0.3.0",
41+
"micromark-extension-gfm-autolink-literal": "^0.1.0",
42+
"nyc": "^15.0.0",
43+
"prettier": "^2.0.0",
44+
"remark-cli": "^8.0.0",
45+
"remark-preset-wooorm": "^7.0.0",
46+
"tape": "^5.0.0",
47+
"xo": "^0.33.0"
48+
},
49+
"scripts": {
50+
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
51+
"test-api": "node test",
52+
"test-coverage": "nyc --reporter lcov tape test.js",
53+
"test": "npm run format && npm run test-coverage"
54+
},
55+
"nyc": {
56+
"check-coverage": true,
57+
"lines": 100,
58+
"functions": 100,
59+
"branches": 100
60+
},
61+
"prettier": {
62+
"tabWidth": 2,
63+
"useTabs": false,
64+
"singleQuote": true,
65+
"bracketSpacing": false,
66+
"semi": false,
67+
"trailingComma": "none"
68+
},
69+
"xo": {
70+
"prettier": true,
71+
"esnext": false
72+
},
73+
"remarkConfig": {
74+
"plugins": [
75+
"preset-wooorm"
76+
]
77+
}
78+
}

readme.md

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
# mdast-util-gfm-autolink-literal
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+
autolink literals in **[mdast][]**.
14+
When parsing (`from-markdown`), must be combined with
15+
[`micromark-extension-gfm-autolink-literal`][syntax].
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-autolink-literal
26+
```
27+
28+
## Use
29+
30+
Say our script, `example.js`, looks as follows:
31+
32+
```js
33+
var fromMarkdown = require('mdast-util-from-markdown')
34+
var toMarkdown = require('mdast-util-to-markdown')
35+
var autolinkLiteralSyntax = require('micromark-extension-gfm-autolink-literal')
36+
var autolinkLiteral = require('mdast-util-gfm-autolink-literal')
37+
38+
var doc = 'www.example.com, https://example.com, and contact@example.com.'
39+
40+
var tree = fromMarkdown(doc, {
41+
extensions: [autolinkLiteralSyntax],
42+
mdastExtensions: [autolinkLiteral.fromMarkdown]
43+
})
44+
45+
console.log(tree)
46+
47+
var out = toMarkdown(tree, {extensions: [autolinkLiteral.toMarkdown]})
48+
49+
console.log(out)
50+
```
51+
52+
Now, running `node example` yields:
53+
54+
```js
55+
{
56+
type: 'root',
57+
children: [
58+
{
59+
type: 'paragraph',
60+
children: [
61+
{
62+
type: 'link',
63+
title: null,
64+
url: 'http://www.example.com',
65+
children: [{type: 'text', value: 'www.example.com'}]
66+
},
67+
{type: 'text', value: ', '},
68+
{
69+
type: 'link',
70+
title: null,
71+
url: 'https://example.com',
72+
children: [{type: 'text', value: 'https://example.com'}]
73+
},
74+
{type: 'text', value: ', and '},
75+
{
76+
type: 'link',
77+
title: null,
78+
url: 'mailto:contact@example.com',
79+
children: [{type: 'text', value: 'contact@example.com'}]
80+
},
81+
{type: 'text', value: '.'}
82+
]
83+
}
84+
]
85+
}
86+
```
87+
88+
```markdown
89+
[www.example.com](http://www.example.com), <https://example.com>, and <contact@example.com>.
90+
```
91+
92+
## API
93+
94+
### `autolinkLiteral.fromMarkdown`
95+
96+
### `autolinkLiteral.toMarkdown`
97+
98+
> Note: the separate extensions are also available at
99+
> `mdast-util-gfm-autolink-literal/from-markdown` and
100+
> `mdast-util-gfm-autolink-literal/to-markdown`.
101+
102+
Support literal autolinks.
103+
The exports are extensions, respectively
104+
for [`mdast-util-from-markdown`][from-markdown] and
105+
[`mdast-util-to-markdown`][to-markdown].
106+
107+
## Related
108+
109+
* [`remarkjs/remark`][remark]
110+
— markdown processor powered by plugins
111+
* `remarkjs/remark-gfm`
112+
— remark plugin to support GFM
113+
* [`micromark/micromark`][micromark]
114+
— the smallest commonmark-compliant markdown parser that exists
115+
* [`micromark/micromark-extension-gfm-autolink-literal`][syntax]
116+
— micromark extension to parse GFM autolink literals
117+
* [`syntax-tree/mdast-util-from-markdown`][from-markdown]
118+
— mdast parser using `micromark` to create mdast from markdown
119+
* [`syntax-tree/mdast-util-to-markdown`][to-markdown]
120+
— mdast serializer to create markdown from mdast
121+
122+
## Contribute
123+
124+
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
125+
started.
126+
See [`support.md`][support] for ways to get help.
127+
128+
This project has a [code of conduct][coc].
129+
By interacting with this repository, organization, or community you agree to
130+
abide by its terms.
131+
132+
## License
133+
134+
[MIT][license] © [Titus Wormer][author]
135+
136+
<!-- Definitions -->
137+
138+
[build-badge]: https://img.shields.io/travis/syntax-tree/mdast-util-gfm-autolink-literal.svg
139+
140+
[build]: https://travis-ci.org/syntax-tree/mdast-util-gfm-autolink-literal
141+
142+
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-autolink-literal.svg
143+
144+
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-autolink-literal
145+
146+
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-autolink-literal.svg
147+
148+
[downloads]: https://www.npmjs.com/package/mdast-util-gfm-autolink-literal
149+
150+
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-gfm-autolink-literal.svg
151+
152+
[size]: https://bundlephobia.com/result?p=mdast-util-gfm-autolink-literal
153+
154+
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
155+
156+
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
157+
158+
[collective]: https://opencollective.com/unified
159+
160+
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
161+
162+
[chat]: https://github.com/syntax-tree/unist/discussions
163+
164+
[npm]: https://docs.npmjs.com/cli/install
165+
166+
[license]: license
167+
168+
[author]: https://wooorm.com
169+
170+
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
171+
172+
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
173+
174+
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
175+
176+
[mdast]: https://github.com/syntax-tree/mdast
177+
178+
[remark]: https://github.com/remarkjs/remark
179+
180+
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
181+
182+
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
183+
184+
[micromark]: https://github.com/micromark/micromark
185+
186+
[syntax]: https://github.com/micromark/micromark-extension-gfm-autolink-literal

0 commit comments

Comments
 (0)