|
| 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 [email protected].' |
| 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 | + |
| 79 | + children : [{type : 'text', value : '[email protected]'}] |
| 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 < [email protected]>. |
| 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