mdast-util-gfm-strikethrough
Advanced tools
Comparing version 0.2.3 to 1.0.0
52
index.js
@@ -1,2 +0,50 @@ | ||
exports.fromMarkdown = require('./from-markdown') | ||
exports.toMarkdown = require('./to-markdown') | ||
/** | ||
* @typedef {import('mdast').Delete} Delete | ||
* @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension | ||
* @typedef {import('mdast-util-from-markdown').Handle} FromMarkdownHandle | ||
* @typedef {import('mdast-util-to-markdown').Options} ToMarkdownExtension | ||
* @typedef {import('mdast-util-to-markdown').Handle} ToMarkdownHandle | ||
*/ | ||
import {containerPhrasing} from 'mdast-util-to-markdown/lib/util/container-phrasing.js' | ||
/** @type {FromMarkdownExtension} */ | ||
export const gfmStrikethroughFromMarkdown = { | ||
canContainEols: ['delete'], | ||
enter: {strikethrough: enterStrikethrough}, | ||
exit: {strikethrough: exitStrikethrough} | ||
} | ||
/** @type {ToMarkdownExtension} */ | ||
export const gfmStrikethroughToMarkdown = { | ||
unsafe: [{character: '~', inConstruct: 'phrasing'}], | ||
handlers: {delete: handleDelete} | ||
} | ||
handleDelete.peek = peekDelete | ||
/** @type {FromMarkdownHandle} */ | ||
function enterStrikethrough(token) { | ||
this.enter({type: 'delete', children: []}, token) | ||
} | ||
/** @type {FromMarkdownHandle} */ | ||
function exitStrikethrough(token) { | ||
this.exit(token) | ||
} | ||
/** | ||
* @type {ToMarkdownHandle} | ||
* @param {Delete} node | ||
*/ | ||
function handleDelete(node, _, context) { | ||
const exit = context.enter('emphasis') | ||
const value = containerPhrasing(node, context, {before: '~', after: '~'}) | ||
exit() | ||
return '~~' + value + '~~' | ||
} | ||
/** @type {ToMarkdownHandle} */ | ||
function peekDelete() { | ||
return '~' | ||
} |
{ | ||
"name": "mdast-util-gfm-strikethrough", | ||
"version": "0.2.3", | ||
"version": "1.0.0", | ||
"description": "mdast extension to parse and serialize GFM strikethrough", | ||
@@ -32,33 +32,36 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"from-markdown.js", | ||
"index.js", | ||
"to-markdown.js" | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"mdast-util-to-markdown": "^0.6.0" | ||
"@types/mdast": "^3.0.3", | ||
"mdast-util-to-markdown": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"mdast-util-from-markdown": "^0.8.0", | ||
"micromark-extension-gfm-strikethrough": "^0.6.0", | ||
"nyc": "^15.0.0", | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"mdast-util-from-markdown": "^1.0.0", | ||
"micromark-extension-gfm-strikethrough": "^1.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.2", | ||
"tape": "^5.0.0", | ||
"unist-util-remove-position": "^3.0.0", | ||
"xo": "^0.36.0" | ||
"type-coverage": "^2.17.5", | ||
"typescript": "^4.3.4", | ||
"unist-util-remove-position": "^4.0.0", | ||
"xo": "^0.39.0" | ||
}, | ||
"scripts": { | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run test-coverage" | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test.js", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -73,4 +76,3 @@ "tabWidth": 2, | ||
"xo": { | ||
"prettier": true, | ||
"esnext": false | ||
"prettier": true | ||
}, | ||
@@ -81,3 +83,9 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
@@ -17,7 +17,14 @@ # mdast-util-gfm-strikethrough | ||
You probably shouldn’t use this package directly, but instead use | ||
[`remark-gfm`][remark-gfm] with **[remark][]**. | ||
## When to use this | ||
Use this if you’re dealing with the AST manually. | ||
It’s might be better to use [`remark-gfm`][remark-gfm] with **[remark][]**, | ||
which includes this but provides a nicer interface and makes it easier to | ||
combine with hundreds of plugins. | ||
## Install | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -31,15 +38,15 @@ | ||
Say our script, `example.js`, looks as follows: | ||
Say our module, `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-strikethrough') | ||
var strikethrough = require('mdast-util-gfm-strikethrough') | ||
import {fromMarkdown} from 'mdast-util-from-markdown' | ||
import {toMarkdown} from 'mdast-util-to-markdown' | ||
import {gfmStrikethrough} from 'micromark-extension-gfm-strikethrough' | ||
import {gfmStrikethroughFromMarkdown, gfmStrikethroughToMarkdown} from 'mdast-util-gfm-strikethrough' | ||
var doc = '*Emphasis*, **importance**, and ~~strikethrough~~.' | ||
const doc = '*Emphasis*, **importance**, and ~~strikethrough~~.' | ||
var tree = fromMarkdown(doc, { | ||
extensions: [syntax()], | ||
mdastExtensions: [strikethrough.fromMarkdown] | ||
const tree = fromMarkdown(doc, { | ||
extensions: [gfmStrikethrough()], | ||
mdastExtensions: [gfmStrikethroughFromMarkdown] | ||
}) | ||
@@ -49,3 +56,3 @@ | ||
var out = toMarkdown(tree, {extensions: [strikethrough.toMarkdown]}) | ||
const out = toMarkdown(tree, {extensions: [gfmStrikethroughToMarkdown]}) | ||
@@ -82,9 +89,9 @@ console.log(out) | ||
### `strikethrough.fromMarkdown` | ||
This package exports the following identifier: `gfmStrikethroughFromMarkdown`, | ||
`gfmStrikethroughToMarkdown`. | ||
There is no default export. | ||
### `strikethrough.toMarkdown` | ||
### `gfmStrikethroughFromMarkdown` | ||
> Note: the separate extensions are also available at | ||
> `mdast-util-gfm-strikethrough/from-markdown` and | ||
> `mdast-util-gfm-strikethrough/to-markdown`. | ||
### `gfmStrikethroughToMarkdown` | ||
@@ -91,0 +98,0 @@ Support strikethrough. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
10758
51
1
181
Yes
2
13
5
+ Added@types/mdast@^3.0.3
+ Added@types/mdast@3.0.15(transitive)
+ Addedcharacter-entities@2.0.2(transitive)
+ Addeddecode-named-character-reference@1.0.2(transitive)
+ Addedlongest-streak@3.1.0(transitive)
+ Addedmdast-util-phrasing@3.0.1(transitive)
+ Addedmdast-util-to-markdown@1.5.0(transitive)
+ Addedmdast-util-to-string@3.2.0(transitive)
+ Addedmicromark-util-character@1.2.0(transitive)
+ Addedmicromark-util-decode-numeric-character-reference@1.1.0(transitive)
+ Addedmicromark-util-decode-string@1.1.0(transitive)
+ Addedmicromark-util-symbol@1.1.0(transitive)
+ Addedmicromark-util-types@1.1.0(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-visit@4.1.2(transitive)
+ Addedunist-util-visit-parents@5.1.3(transitive)
+ Addedzwitch@2.0.4(transitive)
- Removedcharacter-entities@1.2.4(transitive)
- Removedcharacter-entities-legacy@1.1.4(transitive)
- Removedcharacter-reference-invalid@1.1.4(transitive)
- Removedis-alphabetical@1.0.4(transitive)
- Removedis-alphanumerical@1.0.4(transitive)
- Removedis-decimal@1.0.4(transitive)
- Removedis-hexadecimal@1.0.4(transitive)
- Removedlongest-streak@2.0.4(transitive)
- Removedmdast-util-to-markdown@0.6.5(transitive)
- Removedmdast-util-to-string@2.0.0(transitive)
- Removedparse-entities@2.0.0(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedzwitch@1.0.5(transitive)