This commit is contained in:
157
node_modules/mdast-util-gfm-autolink-literal/from-markdown.js
generated
vendored
Normal file
157
node_modules/mdast-util-gfm-autolink-literal/from-markdown.js
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
var ccount = require('ccount')
|
||||
var findAndReplace = require('mdast-util-find-and-replace')
|
||||
var unicodePunctuation = require('micromark/dist/character/unicode-punctuation')
|
||||
var unicodeWhitespace = require('micromark/dist/character/unicode-whitespace')
|
||||
|
||||
exports.transforms = [transformGfmAutolinkLiterals]
|
||||
exports.enter = {
|
||||
literalAutolink: enterLiteralAutolink,
|
||||
literalAutolinkEmail: enterLiteralAutolinkValue,
|
||||
literalAutolinkHttp: enterLiteralAutolinkValue,
|
||||
literalAutolinkWww: enterLiteralAutolinkValue
|
||||
}
|
||||
exports.exit = {
|
||||
literalAutolink: exitLiteralAutolink,
|
||||
literalAutolinkEmail: exitLiteralAutolinkEmail,
|
||||
literalAutolinkHttp: exitLiteralAutolinkHttp,
|
||||
literalAutolinkWww: exitLiteralAutolinkWww
|
||||
}
|
||||
|
||||
function enterLiteralAutolink(token) {
|
||||
this.enter({type: 'link', title: null, url: '', children: []}, token)
|
||||
}
|
||||
|
||||
function enterLiteralAutolinkValue(token) {
|
||||
this.config.enter.autolinkProtocol.call(this, token)
|
||||
}
|
||||
|
||||
function exitLiteralAutolinkHttp(token) {
|
||||
this.config.exit.autolinkProtocol.call(this, token)
|
||||
}
|
||||
|
||||
function exitLiteralAutolinkWww(token) {
|
||||
this.config.exit.data.call(this, token)
|
||||
this.stack[this.stack.length - 1].url = 'http://' + this.sliceSerialize(token)
|
||||
}
|
||||
|
||||
function exitLiteralAutolinkEmail(token) {
|
||||
this.config.exit.autolinkEmail.call(this, token)
|
||||
}
|
||||
|
||||
function exitLiteralAutolink(token) {
|
||||
this.exit(token)
|
||||
}
|
||||
|
||||
function transformGfmAutolinkLiterals(tree) {
|
||||
findAndReplace(
|
||||
tree,
|
||||
[
|
||||
[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/i, findUrl],
|
||||
[/([-.\w+]+)@([-\w]+(?:\.[-\w]+)+)/, findEmail]
|
||||
],
|
||||
{ignore: ['link', 'linkReference']}
|
||||
)
|
||||
}
|
||||
|
||||
function findUrl($0, protocol, domain, path, match) {
|
||||
var prefix = ''
|
||||
var parts
|
||||
var result
|
||||
|
||||
// Not an expected previous character.
|
||||
if (!previous(match)) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Treat `www` as part of the domain.
|
||||
if (/^w/i.test(protocol)) {
|
||||
domain = protocol + domain
|
||||
protocol = ''
|
||||
prefix = 'http://'
|
||||
}
|
||||
|
||||
if (!isCorrectDomain(domain)) {
|
||||
return false
|
||||
}
|
||||
|
||||
parts = splitUrl(domain + path)
|
||||
|
||||
if (!parts[0]) return false
|
||||
|
||||
result = {
|
||||
type: 'link',
|
||||
title: null,
|
||||
url: prefix + protocol + parts[0],
|
||||
children: [{type: 'text', value: protocol + parts[0]}]
|
||||
}
|
||||
|
||||
if (parts[1]) {
|
||||
result = [result, {type: 'text', value: parts[1]}]
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function findEmail($0, atext, label, match) {
|
||||
// Not an expected previous character.
|
||||
if (!previous(match, true) || /[_-]$/.test(label)) {
|
||||
return false
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'link',
|
||||
title: null,
|
||||
url: 'mailto:' + atext + '@' + label,
|
||||
children: [{type: 'text', value: atext + '@' + label}]
|
||||
}
|
||||
}
|
||||
|
||||
function isCorrectDomain(domain) {
|
||||
var parts = domain.split('.')
|
||||
|
||||
if (
|
||||
parts.length < 2 ||
|
||||
(parts[parts.length - 1] &&
|
||||
(/_/.test(parts[parts.length - 1]) ||
|
||||
!/[a-zA-Z\d]/.test(parts[parts.length - 1]))) ||
|
||||
(parts[parts.length - 2] &&
|
||||
(/_/.test(parts[parts.length - 2]) ||
|
||||
!/[a-zA-Z\d]/.test(parts[parts.length - 2])))
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
function splitUrl(url) {
|
||||
var trail = /[!"&'),.:;<>?\]}]+$/.exec(url)
|
||||
var closingParenIndex
|
||||
var openingParens
|
||||
var closingParens
|
||||
|
||||
if (trail) {
|
||||
url = url.slice(0, trail.index)
|
||||
trail = trail[0]
|
||||
closingParenIndex = trail.indexOf(')')
|
||||
openingParens = ccount(url, '(')
|
||||
closingParens = ccount(url, ')')
|
||||
|
||||
while (closingParenIndex !== -1 && openingParens > closingParens) {
|
||||
url += trail.slice(0, closingParenIndex + 1)
|
||||
trail = trail.slice(closingParenIndex + 1)
|
||||
closingParenIndex = trail.indexOf(')')
|
||||
closingParens++
|
||||
}
|
||||
}
|
||||
|
||||
return [url, trail]
|
||||
}
|
||||
|
||||
function previous(match, email) {
|
||||
var code = match.input.charCodeAt(match.index - 1)
|
||||
return (
|
||||
(code !== code || unicodeWhitespace(code) || unicodePunctuation(code)) &&
|
||||
(!email || code !== 47)
|
||||
)
|
||||
}
|
||||
2
node_modules/mdast-util-gfm-autolink-literal/index.js
generated
vendored
Normal file
2
node_modules/mdast-util-gfm-autolink-literal/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
exports.fromMarkdown = require('./from-markdown')
|
||||
exports.toMarkdown = require('./to-markdown')
|
||||
22
node_modules/mdast-util-gfm-autolink-literal/license
generated
vendored
Normal file
22
node_modules/mdast-util-gfm-autolink-literal/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
90
node_modules/mdast-util-gfm-autolink-literal/package.json
generated
vendored
Normal file
90
node_modules/mdast-util-gfm-autolink-literal/package.json
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
{
|
||||
"name": "mdast-util-gfm-autolink-literal",
|
||||
"version": "0.1.3",
|
||||
"description": "mdast extension to parse and serialize GFM autolink literals",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"mdast",
|
||||
"mdast-util",
|
||||
"util",
|
||||
"utility",
|
||||
"markdown",
|
||||
"markup",
|
||||
"autolink",
|
||||
"auto",
|
||||
"link",
|
||||
"literal",
|
||||
"url",
|
||||
"raw",
|
||||
"gfm"
|
||||
],
|
||||
"repository": "syntax-tree/mdast-util-gfm-autolink-literal",
|
||||
"bugs": "https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/issues",
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/unified"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"files": [
|
||||
"from-markdown.js",
|
||||
"index.js",
|
||||
"to-markdown.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"ccount": "^1.0.0",
|
||||
"mdast-util-find-and-replace": "^1.1.0",
|
||||
"micromark": "^2.11.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"hast-util-to-html": "^7.0.0",
|
||||
"mdast-util-from-markdown": "^0.8.5",
|
||||
"mdast-util-to-hast": "^10.0.0",
|
||||
"mdast-util-to-markdown": "^0.6.0",
|
||||
"micromark-extension-gfm-autolink-literal": "^0.5.6",
|
||||
"nyc": "^15.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"xo": "^0.37.0"
|
||||
},
|
||||
"scripts": {
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test/index.js",
|
||||
"test": "npm run format && npm run test-coverage"
|
||||
},
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"rules": {
|
||||
"max-params": "off",
|
||||
"no-self-compare": "off",
|
||||
"unicorn/prefer-includes": "off",
|
||||
"unicorn/prefer-optional-catch-binding": "off"
|
||||
}
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
}
|
||||
}
|
||||
188
node_modules/mdast-util-gfm-autolink-literal/readme.md
generated
vendored
Normal file
188
node_modules/mdast-util-gfm-autolink-literal/readme.md
generated
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
# mdast-util-gfm-autolink-literal
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
[![Sponsors][sponsors-badge]][collective]
|
||||
[![Backers][backers-badge]][collective]
|
||||
[![Chat][chat-badge]][chat]
|
||||
|
||||
Extension for [`mdast-util-from-markdown`][from-markdown] and/or
|
||||
[`mdast-util-to-markdown`][to-markdown] to support GitHub flavored markdown
|
||||
autolink literals in **[mdast][]**.
|
||||
When parsing (`from-markdown`), must be combined with
|
||||
[`micromark-extension-gfm-autolink-literal`][extension].
|
||||
|
||||
You might want to use this package through [`remark-gfm`][remark-gfm] with
|
||||
**[remark][]**.
|
||||
|
||||
## Install
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install mdast-util-gfm-autolink-literal
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
Say our script, `example.js`, looks as follows:
|
||||
|
||||
```js
|
||||
var fromMarkdown = require('mdast-util-from-markdown')
|
||||
var toMarkdown = require('mdast-util-to-markdown')
|
||||
var syntax = require('micromark-extension-gfm-autolink-literal')
|
||||
var autolinkLiteral = require('mdast-util-gfm-autolink-literal')
|
||||
|
||||
var doc = 'www.example.com, https://example.com, and contact@example.com.'
|
||||
|
||||
var tree = fromMarkdown(doc, {
|
||||
extensions: [syntax],
|
||||
mdastExtensions: [autolinkLiteral.fromMarkdown]
|
||||
})
|
||||
|
||||
console.log(tree)
|
||||
|
||||
var out = toMarkdown(tree, {extensions: [autolinkLiteral.toMarkdown]})
|
||||
|
||||
console.log(out)
|
||||
```
|
||||
|
||||
Now, running `node example` yields:
|
||||
|
||||
```js
|
||||
{
|
||||
type: 'root',
|
||||
children: [
|
||||
{
|
||||
type: 'paragraph',
|
||||
children: [
|
||||
{
|
||||
type: 'link',
|
||||
title: null,
|
||||
url: 'http://www.example.com',
|
||||
children: [{type: 'text', value: 'www.example.com'}]
|
||||
},
|
||||
{type: 'text', value: ', '},
|
||||
{
|
||||
type: 'link',
|
||||
title: null,
|
||||
url: 'https://example.com',
|
||||
children: [{type: 'text', value: 'https://example.com'}]
|
||||
},
|
||||
{type: 'text', value: ', and '},
|
||||
{
|
||||
type: 'link',
|
||||
title: null,
|
||||
url: 'mailto:contact@example.com',
|
||||
children: [{type: 'text', value: 'contact@example.com'}]
|
||||
},
|
||||
{type: 'text', value: '.'}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
```markdown
|
||||
[www.example.com](http://www.example.com), <https://example.com>, and <contact@example.com>.
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `autolinkLiteral.fromMarkdown`
|
||||
|
||||
### `autolinkLiteral.toMarkdown`
|
||||
|
||||
> Note: the separate extensions are also available at
|
||||
> `mdast-util-gfm-autolink-literal/from-markdown` and
|
||||
> `mdast-util-gfm-autolink-literal/to-markdown`.
|
||||
|
||||
Support literal autolinks.
|
||||
The exports are extensions, respectively
|
||||
for [`mdast-util-from-markdown`][from-markdown] and
|
||||
[`mdast-util-to-markdown`][to-markdown].
|
||||
|
||||
## Related
|
||||
|
||||
* [`remarkjs/remark`][remark]
|
||||
— markdown processor powered by plugins
|
||||
* [`remarkjs/remark-gfm`][remark-gfm]
|
||||
— remark plugin to support GFM
|
||||
* [`micromark/micromark`][micromark]
|
||||
— the smallest commonmark-compliant markdown parser that exists
|
||||
* [`micromark/micromark-extension-gfm-autolink-literal`][extension]
|
||||
— micromark extension to parse GFM autolink literals
|
||||
* [`syntax-tree/mdast-util-from-markdown`][from-markdown]
|
||||
— mdast parser using `micromark` to create mdast from markdown
|
||||
* [`syntax-tree/mdast-util-to-markdown`][to-markdown]
|
||||
— mdast serializer to create markdown from mdast
|
||||
|
||||
## Contribute
|
||||
|
||||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
|
||||
started.
|
||||
See [`support.md`][support] for ways to get help.
|
||||
|
||||
This project has a [code of conduct][coc].
|
||||
By interacting with this repository, organization, or community you agree to
|
||||
abide by its terms.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-gfm-autolink-literal.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-gfm-autolink-literal
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-gfm-autolink-literal.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/mdast-util-gfm-autolink-literal
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-gfm-autolink-literal.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=mdast-util-gfm-autolink-literal
|
||||
|
||||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
|
||||
|
||||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
|
||||
|
||||
[collective]: https://opencollective.com/unified
|
||||
|
||||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
|
||||
|
||||
[chat]: https://github.com/syntax-tree/unist/discussions
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
|
||||
|
||||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
|
||||
|
||||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
|
||||
|
||||
[mdast]: https://github.com/syntax-tree/mdast
|
||||
|
||||
[remark]: https://github.com/remarkjs/remark
|
||||
|
||||
[remark-gfm]: https://github.com/remarkjs/remark-gfm
|
||||
|
||||
[from-markdown]: https://github.com/syntax-tree/mdast-util-from-markdown
|
||||
|
||||
[to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown
|
||||
|
||||
[micromark]: https://github.com/micromark/micromark
|
||||
|
||||
[extension]: https://github.com/micromark/micromark-extension-gfm-autolink-literal
|
||||
26
node_modules/mdast-util-gfm-autolink-literal/to-markdown.js
generated
vendored
Normal file
26
node_modules/mdast-util-gfm-autolink-literal/to-markdown.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var inConstruct = 'phrasing'
|
||||
var notInConstruct = ['autolink', 'link', 'image', 'label']
|
||||
|
||||
exports.unsafe = [
|
||||
{
|
||||
character: '@',
|
||||
before: '[+\\-.\\w]',
|
||||
after: '[\\-.\\w]',
|
||||
inConstruct: inConstruct,
|
||||
notInConstruct: notInConstruct
|
||||
},
|
||||
{
|
||||
character: '.',
|
||||
before: '[Ww]',
|
||||
after: '[\\-.\\w]',
|
||||
inConstruct: inConstruct,
|
||||
notInConstruct: notInConstruct
|
||||
},
|
||||
{
|
||||
character: ':',
|
||||
before: '[ps]',
|
||||
after: '\\/',
|
||||
inConstruct: inConstruct,
|
||||
notInConstruct: notInConstruct
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user