Socket
Socket
Sign inDemoInstall

mdast-util-gfm-autolink-literal

Package Overview
Dependencies
12
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 2.0.0

20

lib/index.d.ts
/**
* Extension for `mdast-util-from-markdown` to enable GFM autolink literals.
* Create an extension for `mdast-util-from-markdown` to enable GFM autolink
* literals in markdown.
*
* @type {FromMarkdownExtension}
* @returns {FromMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable GFM autolink literals.
*/
export const gfmAutolinkLiteralFromMarkdown: FromMarkdownExtension
export function gfmAutolinkLiteralFromMarkdown(): FromMarkdownExtension
/**
* Extension for `mdast-util-to-markdown` to enable GFM autolink literals.
* Create an extension for `mdast-util-to-markdown` to enable GFM autolink
* literals in markdown.
*
* @type {ToMarkdownExtension}
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable GFM autolink literals.
*/
export const gfmAutolinkLiteralToMarkdown: ToMarkdownExtension
export function gfmAutolinkLiteralToMarkdown(): ToMarkdownExtension
export type Link = import('mdast').Link

@@ -21,5 +25,5 @@ export type PhrasingContent = import('mdast').PhrasingContent

export type ToMarkdownExtension = import('mdast-util-to-markdown').Options
export type RegExpMatchObject =
import('mdast-util-find-and-replace').RegExpMatchObject
export type ReplaceFunction =
import('mdast-util-find-and-replace').ReplaceFunction
export type RegExpMatchObject =
import('mdast-util-find-and-replace').RegExpMatchObject

96

lib/index.js

@@ -13,9 +13,10 @@ /**

*
* @typedef {import('mdast-util-find-and-replace').RegExpMatchObject} RegExpMatchObject
* @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
* @typedef {import('mdast-util-find-and-replace').RegExpMatchObject} RegExpMatchObject
*/
import {ccount} from 'ccount'
import {ok as assert} from 'devlop'
import {unicodePunctuation, unicodeWhitespace} from 'micromark-util-character'
import {findAndReplace} from 'mdast-util-find-and-replace'
import {unicodePunctuation, unicodeWhitespace} from 'micromark-util-character'

@@ -27,22 +28,24 @@ /** @type {ConstructName} */

// To do: next major: expose functions instead of extensions.
/**
* Extension for `mdast-util-from-markdown` to enable GFM autolink literals.
* Create an extension for `mdast-util-from-markdown` to enable GFM autolink
* literals in markdown.
*
* @type {FromMarkdownExtension}
* @returns {FromMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable GFM autolink literals.
*/
export const gfmAutolinkLiteralFromMarkdown = {
transforms: [transformGfmAutolinkLiterals],
enter: {
literalAutolink: enterLiteralAutolink,
literalAutolinkEmail: enterLiteralAutolinkValue,
literalAutolinkHttp: enterLiteralAutolinkValue,
literalAutolinkWww: enterLiteralAutolinkValue
},
exit: {
literalAutolink: exitLiteralAutolink,
literalAutolinkEmail: exitLiteralAutolinkEmail,
literalAutolinkHttp: exitLiteralAutolinkHttp,
literalAutolinkWww: exitLiteralAutolinkWww
export function gfmAutolinkLiteralFromMarkdown() {
return {
transforms: [transformGfmAutolinkLiterals],
enter: {
literalAutolink: enterLiteralAutolink,
literalAutolinkEmail: enterLiteralAutolinkValue,
literalAutolinkHttp: enterLiteralAutolinkValue,
literalAutolinkWww: enterLiteralAutolinkValue
},
exit: {
literalAutolink: exitLiteralAutolink,
literalAutolinkEmail: exitLiteralAutolinkEmail,
literalAutolinkHttp: exitLiteralAutolinkHttp,
literalAutolinkWww: exitLiteralAutolinkWww
}
}

@@ -52,24 +55,34 @@ }

/**
* Extension for `mdast-util-to-markdown` to enable GFM autolink literals.
* Create an extension for `mdast-util-to-markdown` to enable GFM autolink
* literals in markdown.
*
* @type {ToMarkdownExtension}
* @returns {ToMarkdownExtension}
* Extension for `mdast-util-to-markdown` to enable GFM autolink literals.
*/
export const gfmAutolinkLiteralToMarkdown = {
unsafe: [
{
character: '@',
before: '[+\\-.\\w]',
after: '[\\-.\\w]',
inConstruct,
notInConstruct
},
{
character: '.',
before: '[Ww]',
after: '[\\-.\\w]',
inConstruct,
notInConstruct
},
{character: ':', before: '[ps]', after: '\\/', inConstruct, notInConstruct}
]
export function gfmAutolinkLiteralToMarkdown() {
return {
unsafe: [
{
character: '@',
before: '[+\\-.\\w]',
after: '[\\-.\\w]',
inConstruct,
notInConstruct
},
{
character: '.',
before: '[Ww]',
after: '[\\-.\\w]',
inConstruct,
notInConstruct
},
{
character: ':',
before: '[ps]',
after: '\\/',
inConstruct,
notInConstruct
}
]
}
}

@@ -107,3 +120,4 @@

this.config.exit.data.call(this, token)
const node = /** @type {Link} */ (this.stack[this.stack.length - 1])
const node = this.stack[this.stack.length - 1]
assert(node.type === 'link')
node.url = 'http://' + this.sliceSerialize(token)

@@ -147,3 +161,3 @@ }

* @param {RegExpMatchObject} match
* @returns {Link | Array<PhrasingContent> | false}
* @returns {Array<PhrasingContent> | Link | false}
*/

@@ -150,0 +164,0 @@ // eslint-disable-next-line max-params

{
"name": "mdast-util-gfm-autolink-literal",
"version": "1.0.3",
"version": "2.0.0",
"description": "mdast extension to parse and serialize GFM autolink literals",

@@ -34,4 +34,3 @@ "license": "MIT",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [

@@ -43,15 +42,16 @@ "lib/",

"dependencies": {
"@types/mdast": "^3.0.0",
"@types/mdast": "^4.0.0",
"ccount": "^2.0.0",
"mdast-util-find-and-replace": "^2.0.0",
"micromark-util-character": "^1.0.0"
"devlop": "^1.0.0",
"mdast-util-find-and-replace": "^3.0.0",
"micromark-util-character": "^2.0.0"
},
"devDependencies": {
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"hast-util-to-html": "^8.0.0",
"mdast-util-from-markdown": "^1.0.0",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-to-hast": "^12.0.0",
"mdast-util-to-markdown": "^1.0.0",
"micromark-extension-gfm-autolink-literal": "^1.0.0",
"mdast-util-to-markdown": "^2.0.0",
"micromark-extension-gfm-autolink-literal": "^2.0.0",
"prettier": "^2.0.0",

@@ -61,4 +61,4 @@ "remark-cli": "^11.0.0",

"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
"typescript": "^5.0.0",
"xo": "^0.54.0"
},

@@ -69,19 +69,28 @@ "scripts": {

"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test-api-prod": "node --conditions production test/index.js",
"test-api-dev": "node --conditions development test/index.js",
"test-api": "npm run test-api-dev && npm run test-api-prod",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true,
"rules": {
"unicorn/prefer-code-point": "off"
},
"overrides": [

@@ -94,15 +103,8 @@ {

}
]
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
],
"prettier": true,
"rules": {
"unicorn/prefer-code-point": "off"
}
}
}

@@ -20,4 +20,4 @@ # mdast-util-gfm-autolink-literal

* [API](#api)
* [`gfmAutolinkLiteralFromMarkdown`](#gfmautolinkliteralfrommarkdown)
* [`gfmAutolinkLiteralToMarkdown`](#gfmautolinkliteraltomarkdown)
* [`gfmAutolinkLiteralFromMarkdown()`](#gfmautolinkliteralfrommarkdown)
* [`gfmAutolinkLiteralToMarkdown()`](#gfmautolinkliteraltomarkdown)
* [HTML](#html)

@@ -80,3 +80,3 @@ * [Syntax](#syntax)

This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
In Node.js (version 16+), install with [npm][]:

@@ -90,3 +90,3 @@ ```sh

```js
import {gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown} from 'https://esm.sh/mdast-util-gfm-autolink-literal@1'
import {gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown} from 'https://esm.sh/mdast-util-gfm-autolink-literal@2'
```

@@ -98,3 +98,3 @@

<script type="module">
import {gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown} from 'https://esm.sh/mdast-util-gfm-autolink-literal@1?bundle'
import {gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown} from 'https://esm.sh/mdast-util-gfm-autolink-literal@2?bundle'
</script>

@@ -115,6 +115,9 @@ ```

import fs from 'node:fs/promises'
import {gfmAutolinkLiteral} from 'micromark-extension-gfm-autolink-literal'
import {fromMarkdown} from 'mdast-util-from-markdown'
import {
gfmAutolinkLiteralFromMarkdown,
gfmAutolinkLiteralToMarkdown
} from 'mdast-util-gfm-autolink-literal'
import {toMarkdown} from 'mdast-util-to-markdown'
import {gfmAutolinkLiteral} from 'micromark-extension-gfm-autolink-literal'
import {gfmAutolinkLiteralFromMarkdown, gfmAutolinkLiteralToMarkdown} from 'mdast-util-gfm-autolink-literal'

@@ -124,4 +127,4 @@ const doc = await fs.readFile('example.md')

const tree = fromMarkdown(doc, {
extensions: [gfmAutolinkLiteral],
mdastExtensions: [gfmAutolinkLiteralFromMarkdown]
extensions: [gfmAutolinkLiteral()],
mdastExtensions: [gfmAutolinkLiteralFromMarkdown()]
})

@@ -131,3 +134,3 @@

const out = toMarkdown(tree, {extensions: [gfmAutolinkLiteralToMarkdown]})
const out = toMarkdown(tree, {extensions: [gfmAutolinkLiteralToMarkdown()]})

@@ -180,16 +183,26 @@ console.log(out)

This package exports the identifiers
[`gfmAutolinkLiteralFromMarkdown`][api-gfmautolinkliteralfrommarkdown] and
[`gfmAutolinkLiteralToMarkdown`][api-gfmautolinkliteraltomarkdown].
[`gfmAutolinkLiteralFromMarkdown`][api-gfm-autolink-literal-from-markdown] and
[`gfmAutolinkLiteralToMarkdown`][api-gfm-autolink-literal-to-markdown].
There is no default export.
### `gfmAutolinkLiteralFromMarkdown`
### `gfmAutolinkLiteralFromMarkdown()`
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable
GFM autolink literals ([`FromMarkdownExtension`][frommarkdownextension]).
Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown]
to enable GFM autolink literals in markdown.
### `gfmAutolinkLiteralToMarkdown`
###### Returns
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to enable
GFM autolink literals ([`ToMarkdownExtension`][tomarkdownextension]).
Extension for `mdast-util-to-markdown` to enable GFM autolink literals
([`FromMarkdownExtension`][from-markdown-extension]).
### `gfmAutolinkLiteralToMarkdown()`
Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to
enable GFM autolink literals in markdown.
###### Returns
Extension for `mdast-util-to-markdown` to enable GFM autolink literals
([`ToMarkdownExtension`][to-markdown-extension]).
## HTML

@@ -218,10 +231,13 @@

Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
This plugin works with `mdast-util-from-markdown` version 1+ and
`mdast-util-to-markdown` version 1+.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
`mdast-util-gfm-autolink-literal@^2`, compatible with Node.js 16.
This utility works with `mdast-util-from-markdown` version 2+ and
`mdast-util-to-markdown` version 2+.
## Related

@@ -265,5 +281,5 @@

[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-gfm-autolink-literal.svg
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-gfm-autolink-literal
[size]: https://bundlephobia.com/result?p=mdast-util-gfm-autolink-literal
[size]: https://bundlejs.com/?q=mdast-util-gfm-autolink-literal

@@ -322,8 +338,8 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension
[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension
[tomarkdownextension]: https://github.com/syntax-tree/mdast-util-to-markdown#options
[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options
[api-gfmautolinkliteralfrommarkdown]: #gfmautolinkliteralfrommarkdown
[api-gfm-autolink-literal-from-markdown]: #gfmautolinkliteralfrommarkdown
[api-gfmautolinkliteraltomarkdown]: #gfmautolinkliteraltomarkdown
[api-gfm-autolink-literal-to-markdown]: #gfmautolinkliteraltomarkdown
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc