mdast-util-gfm-strikethrough
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,9 +0,20 @@ | ||
/** @type {FromMarkdownExtension} */ | ||
export const gfmStrikethroughFromMarkdown: FromMarkdownExtension | ||
/** @type {ToMarkdownExtension} */ | ||
export const gfmStrikethroughToMarkdown: ToMarkdownExtension | ||
export type Delete = import('mdast').Delete | ||
export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension | ||
export type FromMarkdownHandle = import('mdast-util-from-markdown').Handle | ||
export type ToMarkdownExtension = import('mdast-util-to-markdown').Options | ||
export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle | ||
export { | ||
gfmStrikethroughFromMarkdown, | ||
gfmStrikethroughToMarkdown | ||
} from './lib/index.js' | ||
// Add custom data tracked to turn a syntax tree into markdown. | ||
declare module 'mdast-util-to-markdown' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface ConstructNameMap { | ||
/** | ||
* Whole strikethrough. | ||
* | ||
* ```markdown | ||
* > | ~~a~~ | ||
* ^^^^^ | ||
* ``` | ||
*/ | ||
strikethrough: 'strikethrough' | ||
} | ||
} |
84
index.js
@@ -1,79 +0,5 @@ | ||
/** | ||
* @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' | ||
import {track} from 'mdast-util-to-markdown/lib/util/track.js' | ||
/** @type {FromMarkdownExtension} */ | ||
export const gfmStrikethroughFromMarkdown = { | ||
canContainEols: ['delete'], | ||
enter: {strikethrough: enterStrikethrough}, | ||
exit: {strikethrough: exitStrikethrough} | ||
} | ||
/** | ||
* List of constructs that occur in phrasing (paragraphs, headings), but cannot | ||
* contain strikethroughs. So they sort of cancel each other out. | ||
* | ||
* Note: keep in sync with: <https://github.com/syntax-tree/mdast-util-to-markdown/blob/c47743b/lib/unsafe.js#L11> | ||
*/ | ||
const constructsWithoutStrikethrough = [ | ||
'autolink', | ||
'destinationLiteral', | ||
'destinationRaw', | ||
'reference', | ||
'titleQuote', | ||
'titleApostrophe' | ||
] | ||
/** @type {ToMarkdownExtension} */ | ||
export const gfmStrikethroughToMarkdown = { | ||
unsafe: [ | ||
{ | ||
character: '~', | ||
inConstruct: 'phrasing', | ||
notInConstruct: constructsWithoutStrikethrough | ||
} | ||
], | ||
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, safeOptions) { | ||
const tracker = track(safeOptions) | ||
const exit = context.enter('emphasis') | ||
let value = tracker.move('~~') | ||
value += containerPhrasing(node, context, { | ||
...tracker.current(), | ||
before: value, | ||
after: '~' | ||
}) | ||
value += tracker.move('~~') | ||
exit() | ||
return value | ||
} | ||
/** @type {ToMarkdownHandle} */ | ||
function peekDelete() { | ||
return '~' | ||
} | ||
// Note: extra types in `index.d.ts`. | ||
export { | ||
gfmStrikethroughFromMarkdown, | ||
gfmStrikethroughToMarkdown | ||
} from './lib/index.js' |
{ | ||
"name": "mdast-util-gfm-strikethrough", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "mdast extension to parse and serialize GFM strikethrough", | ||
@@ -37,2 +37,3 @@ "license": "MIT", | ||
"files": [ | ||
"lib/", | ||
"index.d.ts", | ||
@@ -46,3 +47,3 @@ "index.js" | ||
"devDependencies": { | ||
"@types/tape": "^4.0.0", | ||
"@types/node": "^18.0.0", | ||
"c8": "^7.0.0", | ||
@@ -54,14 +55,13 @@ "mdast-util-from-markdown": "^1.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"unist-util-remove-position": "^4.0.0", | ||
"xo": "^0.52.0" | ||
"xo": "^0.53.0" | ||
}, | ||
"scripts": { | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"prepack": "npm run build && npm run format", | ||
"build": "tsc --build --clean && tsc --build && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"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-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
@@ -68,0 +68,0 @@ }, |
@@ -22,2 +22,4 @@ # mdast-util-gfm-strikethrough | ||
* [`gfmStrikethroughToMarkdown`](#gfmstrikethroughtomarkdown) | ||
* [HTML](#html) | ||
* [Syntax](#syntax) | ||
* [Syntax tree](#syntax-tree) | ||
@@ -34,16 +36,27 @@ * [Nodes](#nodes) | ||
This package contains extensions that add support for the strikethrough syntax | ||
enabled by GFM to [`mdast-util-from-markdown`][mdast-util-from-markdown] and | ||
[`mdast-util-to-markdown`][mdast-util-to-markdown]. | ||
This package contains two extensions that add support for GFM strikethrough | ||
syntax in markdown to [mdast][]. | ||
These extensions plug into | ||
[`mdast-util-from-markdown`][mdast-util-from-markdown] (to support parsing | ||
strikethrough in markdown into a syntax tree) and | ||
[`mdast-util-to-markdown`][mdast-util-to-markdown] (to support serializing | ||
strikethrough in syntax trees to markdown). | ||
## When to use this | ||
These tools are all rather low-level. | ||
In most cases, you’d want to use [`remark-gfm`][remark-gfm] with remark instead. | ||
You can use these extensions when you are working with | ||
`mdast-util-from-markdown` and `mdast-util-to-markdown` already. | ||
When working with `mdast-util-from-markdown`, you must combine this package | ||
with [`micromark-extension-gfm-strikethrough`][extension]. | ||
When you don’t need a syntax tree, you can use [`micromark`][micromark] | ||
directly with `micromark-extension-gfm-strikethrough`. | ||
When you are working with syntax trees and want all of GFM, use | ||
[`mdast-util-gfm`][mdast-util-gfm] instead. | ||
When working with `mdast-util-from-markdown`, you must combine this package with | ||
[`micromark-extension-gfm-strikethrough`][extension]. | ||
All these packages are used [`remark-gfm`][remark-gfm], which | ||
focusses on making it easier to transform content by abstracting these | ||
internals away. | ||
@@ -57,3 +70,3 @@ This utility does not handle how markdown is turned to HTML. | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
In Node.js (version 14.14+ and 16.0+), install with [npm][]: | ||
@@ -136,4 +149,5 @@ ```sh | ||
This package exports the identifiers `gfmStrikethroughFromMarkdown` and | ||
`gfmStrikethroughToMarkdown`. | ||
This package exports the identifiers | ||
[`gfmStrikethroughFromMarkdown`][api-gfm-strikethrough-from-markdown] and | ||
[`gfmStrikethroughToMarkdown`][api-gfm-strikethrough-to-markdown]. | ||
There is no default export. | ||
@@ -143,8 +157,20 @@ | ||
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown]. | ||
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable | ||
GFM strikethrough ([`FromMarkdownExtension`][from-markdown-extension]). | ||
### `gfmStrikethroughToMarkdown` | ||
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown]. | ||
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to enable | ||
GFM strikethrough ([`ToMarkdownExtension`][to-markdown-extension]). | ||
## HTML | ||
This utility does not handle how markdown is turned to HTML. | ||
That’s done by [`mdast-util-to-hast`][mdast-util-to-hast]. | ||
If you want a different element, you should configure that utility. | ||
## Syntax | ||
See [Syntax in `micromark-extension-gfm-strikethrough`][syntax]. | ||
## Syntax tree | ||
@@ -160,3 +186,3 @@ | ||
interface Delete <: Parent { | ||
type: "delete" | ||
type: 'delete' | ||
children: [TransparentContent] | ||
@@ -166,8 +192,8 @@ } | ||
**Delete** ([**Parent**][dfn-parent]) represents contents that are no longer | ||
**Delete** (**[Parent][dfn-parent]**) represents contents that are no longer | ||
accurate or no longer relevant. | ||
**Delete** can be used where [**static phrasing**][dfn-static-phrasing-content] | ||
**Delete** can be used where **[static phrasing][dfn-static-phrasing-content]** | ||
content is expected. | ||
Its content model is [**transparent**][dfn-transparent-content] content. | ||
Its content model is **[transparent][dfn-transparent-content]** content. | ||
@@ -202,3 +228,3 @@ For example, the following markdown: | ||
The `Delete` node type is supported in `@types/mdast` by default. | ||
The `Delete` type of the mdast node is exposed from `@types/mdast`. | ||
@@ -209,3 +235,3 @@ ## Compatibility | ||
versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
As of now, that is Node.js 14.14+ and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
@@ -298,4 +324,8 @@ | ||
[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension | ||
[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown | ||
[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options | ||
[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm | ||
@@ -305,6 +335,14 @@ | ||
[micromark]: https://github.com/micromark/micromark | ||
[extension]: https://github.com/micromark/micromark-extension-gfm-strikethrough | ||
[syntax]: https://github.com/micromark/micromark-extension-gfm-strikethrough#syntax | ||
[dfn-parent]: https://github.com/syntax-tree/mdast#parent | ||
[dfn-static-phrasing-content]: #staticphrasingcontent-gfm-strikethrough | ||
[api-gfm-strikethrough-from-markdown]: #gfmstrikethroughfrommarkdown | ||
[api-gfm-strikethrough-to-markdown]: #gfmstrikethroughtomarkdown |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
17080
11
7
137
338
1