mdast-util-gfm-task-list-item
Advanced tools
Comparing version 1.0.2 to 2.0.0
/** | ||
* Extension for `mdast-util-from-markdown` to enable GFM task list items. | ||
* Create an extension for `mdast-util-from-markdown` to enable GFM task | ||
* list items in markdown. | ||
* | ||
* @type {FromMarkdownExtension} | ||
* @returns {FromMarkdownExtension} | ||
* Extension for `mdast-util-from-markdown` to enable GFM task list items. | ||
*/ | ||
export const gfmTaskListItemFromMarkdown: FromMarkdownExtension | ||
export function gfmTaskListItemFromMarkdown(): FromMarkdownExtension | ||
/** | ||
* Extension for `mdast-util-to-markdown` to enable GFM task list items. | ||
* Create an extension for `mdast-util-to-markdown` to enable GFM task list | ||
* items in markdown. | ||
* | ||
* @type {ToMarkdownExtension} | ||
* @returns {ToMarkdownExtension} | ||
* Extension for `mdast-util-to-markdown` to enable GFM task list items. | ||
*/ | ||
export const gfmTaskListItemToMarkdown: ToMarkdownExtension | ||
export type Content = import('mdast').Content | ||
export function gfmTaskListItemToMarkdown(): ToMarkdownExtension | ||
export type ListItem = import('mdast').ListItem | ||
export type Paragraph = import('mdast').Paragraph | ||
export type Parent = import('mdast').Parent | ||
export type Root = import('mdast').Root | ||
export type CompileContext = import('mdast-util-from-markdown').CompileContext | ||
@@ -23,2 +24,1 @@ export type FromMarkdownExtension = import('mdast-util-from-markdown').Extension | ||
export type ToMarkdownHandle = import('mdast-util-to-markdown').Handle | ||
export type Parents = Extract<Root | Content, Parent> |
/** | ||
* @typedef {import('mdast').Content} Content | ||
* @typedef {import('mdast').ListItem} ListItem | ||
* @typedef {import('mdast').Paragraph} Paragraph | ||
* @typedef {import('mdast').Parent} Parent | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('mdast-util-from-markdown').CompileContext} CompileContext | ||
@@ -14,24 +11,19 @@ * @typedef {import('mdast-util-from-markdown').Extension} FromMarkdownExtension | ||
/** | ||
* @typedef {Extract<Root | Content, Parent>} Parents | ||
*/ | ||
import {ok as assert} from 'devlop' | ||
import {defaultHandlers} from 'mdast-util-to-markdown' | ||
import {listItem} from 'mdast-util-to-markdown/lib/handle/list-item.js' | ||
import {track} from 'mdast-util-to-markdown/lib/util/track.js' | ||
// To do: next major: rename `context` -> `state`, `safeOptions` -> `info`, use | ||
// `track` from `state`. | ||
// To do: next major: replace exports with functions. | ||
// To do: next major: use `defaulthandlers.listItem`. | ||
/** | ||
* Extension for `mdast-util-from-markdown` to enable GFM task list items. | ||
* Create an extension for `mdast-util-from-markdown` to enable GFM task | ||
* list items in markdown. | ||
* | ||
* @type {FromMarkdownExtension} | ||
* @returns {FromMarkdownExtension} | ||
* Extension for `mdast-util-from-markdown` to enable GFM task list items. | ||
*/ | ||
export const gfmTaskListItemFromMarkdown = { | ||
exit: { | ||
taskListCheckValueChecked: exitCheck, | ||
taskListCheckValueUnchecked: exitCheck, | ||
paragraph: exitParagraphWithTaskListItem | ||
export function gfmTaskListItemFromMarkdown() { | ||
return { | ||
exit: { | ||
taskListCheckValueChecked: exitCheck, | ||
taskListCheckValueUnchecked: exitCheck, | ||
paragraph: exitParagraphWithTaskListItem | ||
} | ||
} | ||
@@ -41,9 +33,13 @@ } | ||
/** | ||
* Extension for `mdast-util-to-markdown` to enable GFM task list items. | ||
* Create an extension for `mdast-util-to-markdown` to enable GFM task list | ||
* items in markdown. | ||
* | ||
* @type {ToMarkdownExtension} | ||
* @returns {ToMarkdownExtension} | ||
* Extension for `mdast-util-to-markdown` to enable GFM task list items. | ||
*/ | ||
export const gfmTaskListItemToMarkdown = { | ||
unsafe: [{atBreak: true, character: '-', after: '[:|-]'}], | ||
handlers: {listItem: listItemWithTaskListItem} | ||
export function gfmTaskListItemToMarkdown() { | ||
return { | ||
unsafe: [{atBreak: true, character: '-', after: '[:|-]'}], | ||
handlers: {listItem: listItemWithTaskListItem} | ||
} | ||
} | ||
@@ -56,4 +52,5 @@ | ||
function exitCheck(token) { | ||
const node = /** @type {ListItem} */ (this.stack[this.stack.length - 2]) | ||
// We’re always in a paragraph, in a list item. | ||
const node = this.stack[this.stack.length - 2] | ||
assert(node.type === 'listItem') | ||
node.checked = token.type === 'taskListCheckValueChecked' | ||
@@ -67,3 +64,3 @@ } | ||
function exitParagraphWithTaskListItem(token) { | ||
const parent = /** @type {Parents} */ (this.stack[this.stack.length - 2]) | ||
const parent = this.stack[this.stack.length - 2] | ||
@@ -75,3 +72,4 @@ if ( | ||
) { | ||
const node = /** @type {Paragraph} */ (this.stack[this.stack.length - 1]) | ||
const node = this.stack[this.stack.length - 1] | ||
assert(node.type === 'paragraph') | ||
const head = node.children[0] | ||
@@ -119,3 +117,3 @@ | ||
*/ | ||
function listItemWithTaskListItem(node, parent, context, safeOptions) { | ||
function listItemWithTaskListItem(node, parent, state, info) { | ||
const head = node.children[0] | ||
@@ -125,3 +123,3 @@ const checkable = | ||
const checkbox = '[' + (node.checked ? 'x' : ' ') + '] ' | ||
const tracker = track(safeOptions) | ||
const tracker = state.createTracker(info) | ||
@@ -132,4 +130,4 @@ if (checkable) { | ||
let value = listItem(node, parent, context, { | ||
...safeOptions, | ||
let value = defaultHandlers.listItem(node, parent, state, { | ||
...info, | ||
...tracker.current() | ||
@@ -136,0 +134,0 @@ }) |
{ | ||
"name": "mdast-util-gfm-task-list-item", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "mdast extension to parse and serialize GFM task list items", | ||
@@ -34,4 +34,3 @@ "license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
@@ -43,10 +42,11 @@ "lib/", | ||
"dependencies": { | ||
"@types/mdast": "^3.0.0", | ||
"mdast-util-to-markdown": "^1.3.0" | ||
"@types/mdast": "^4.0.0", | ||
"devlop": "^1.0.0", | ||
"mdast-util-from-markdown": "^2.0.0", | ||
"mdast-util-to-markdown": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"c8": "^7.0.0", | ||
"mdast-util-from-markdown": "^1.0.0", | ||
"micromark-extension-gfm-task-list-item": "^1.0.0", | ||
"@types/node": "^20.0.0", | ||
"c8": "^8.0.0", | ||
"micromark-extension-gfm-task-list-item": "^2.0.0", | ||
"prettier": "^2.0.0", | ||
@@ -56,5 +56,5 @@ "remark-cli": "^11.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"unist-util-remove-position": "^4.0.0", | ||
"xo": "^0.53.0" | ||
"typescript": "^5.0.0", | ||
"unist-util-remove-position": "^5.0.0", | ||
"xo": "^0.54.0" | ||
}, | ||
@@ -65,20 +65,19 @@ "scripts": { | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test-api-prod": "node --conditions production test.js", | ||
"test-api-dev": "node --conditions development test.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 | ||
}, | ||
"xo": { | ||
"prettier": true | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -89,5 +88,8 @@ }, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"prettier": true | ||
} | ||
} |
@@ -20,4 +20,4 @@ # mdast-util-gfm-task-list-item | ||
* [API](#api) | ||
* [`gfmTaskListItemFromMarkdown`](#gfmtasklistitemfrommarkdown) | ||
* [`gfmTaskListItemToMarkdown`](#gfmtasklistitemtomarkdown) | ||
* [`gfmTaskListItemFromMarkdown()`](#gfmtasklistitemfrommarkdown) | ||
* [`gfmTaskListItemToMarkdown()`](#gfmtasklistitemtomarkdown) | ||
* [HTML](#html) | ||
@@ -69,3 +69,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][]: | ||
@@ -79,3 +79,3 @@ ```sh | ||
```js | ||
import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'https://esm.sh/mdast-util-gfm-task-list-item@1' | ||
import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'https://esm.sh/mdast-util-gfm-task-list-item@2' | ||
``` | ||
@@ -87,3 +87,3 @@ | ||
<script type="module"> | ||
import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'https://esm.sh/mdast-util-gfm-task-list-item@1?bundle' | ||
import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'https://esm.sh/mdast-util-gfm-task-list-item@2?bundle' | ||
</script> | ||
@@ -108,6 +108,6 @@ ``` | ||
import fs from 'node:fs/promises' | ||
import {gfmTaskListItem} from 'micromark-extension-gfm-task-list-item' | ||
import {fromMarkdown} from 'mdast-util-from-markdown' | ||
import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'mdast-util-gfm-task-list-item' | ||
import {toMarkdown} from 'mdast-util-to-markdown' | ||
import {gfmTaskListItem} from 'micromark-extension-gfm-task-list-item' | ||
import {gfmTaskListItemFromMarkdown, gfmTaskListItemToMarkdown} from 'mdast-util-gfm-task-list-item' | ||
@@ -197,16 +197,26 @@ const doc = await fs.readFile('example.md') | ||
This package exports the identifiers | ||
[`gfmTaskListItemFromMarkdown`][api-gfmtasklistitemfrommarkdown] and | ||
[`gfmTaskListItemToMarkdown`][api-gfmtasklistitemtomarkdown]. | ||
[`gfmTaskListItemFromMarkdown`][api-gfm-task-list-item-from-markdown] and | ||
[`gfmTaskListItemToMarkdown`][api-gfm-task-list-item-to-markdown]. | ||
There is no default export. | ||
### `gfmTaskListItemFromMarkdown` | ||
### `gfmTaskListItemFromMarkdown()` | ||
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] | ||
to enable GFM task lists ([`FromMarkdownExtension`][frommarkdownextension]). | ||
Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] | ||
to enable GFM task list items in markdown. | ||
### `gfmTaskListItemToMarkdown` | ||
###### Returns | ||
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] | ||
to enable GFM task lists ([`ToMarkdownExtension`][tomarkdownextension]). | ||
Extension for `mdast-util-from-markdown` to enable GFM task list items | ||
([`FromMarkdownExtension`][frommarkdownextension]). | ||
### `gfmTaskListItemToMarkdown()` | ||
Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to | ||
enable GFM task list items in markdown. | ||
###### Returns | ||
Extension for `mdast-util-to-markdown` to enable GFM task list items | ||
([`ToMarkdownExtension`][tomarkdownextension]). | ||
## HTML | ||
@@ -256,9 +266,9 @@ | ||
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-task-list-item@^2`, compatible with Node.js 16. | ||
@@ -303,5 +313,5 @@ ## Related | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-gfm-task-list-item.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-task-list-item | ||
[size]: https://bundlephobia.com/result?p=mdast-util-gfm-task-list-item | ||
[size]: https://bundlejs.com/?q=mdast-util-gfm-task-list-item | ||
@@ -362,4 +372,4 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[api-gfmtasklistitemfrommarkdown]: #gfmtasklistitemfrommarkdown | ||
[api-gfm-task-list-item-from-markdown]: #gfmtasklistitemfrommarkdown | ||
[api-gfmtasklistitemtomarkdown]: #gfmtasklistitemtomarkdown | ||
[api-gfm-task-list-item-to-markdown]: #gfmtasklistitemtomarkdown |
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
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
18341
10
367
0
4
+ Addeddevlop@^1.0.0
+ Added@types/debug@4.1.12(transitive)
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/ms@0.7.34(transitive)
+ Added@types/unist@3.0.3(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddequal@2.0.3(transitive)
+ Addeddevlop@1.1.0(transitive)
+ Addedmdast-util-from-markdown@2.0.1(transitive)
+ Addedmdast-util-phrasing@4.1.0(transitive)
+ Addedmdast-util-to-markdown@2.1.0(transitive)
+ Addedmdast-util-to-string@4.0.0(transitive)
+ Addedmicromark@4.0.0(transitive)
+ Addedmicromark-core-commonmark@2.0.1(transitive)
+ Addedmicromark-factory-destination@2.0.0(transitive)
+ Addedmicromark-factory-label@2.0.0(transitive)
+ Addedmicromark-factory-space@2.0.0(transitive)
+ Addedmicromark-factory-title@2.0.0(transitive)
+ Addedmicromark-factory-whitespace@2.0.0(transitive)
+ Addedmicromark-util-character@2.1.0(transitive)
+ Addedmicromark-util-chunked@2.0.0(transitive)
+ Addedmicromark-util-classify-character@2.0.0(transitive)
+ Addedmicromark-util-combine-extensions@2.0.0(transitive)
+ Addedmicromark-util-decode-numeric-character-reference@2.0.1(transitive)
+ Addedmicromark-util-decode-string@2.0.0(transitive)
+ Addedmicromark-util-encode@2.0.0(transitive)
+ Addedmicromark-util-html-tag-name@2.0.0(transitive)
+ Addedmicromark-util-normalize-identifier@2.0.0(transitive)
+ Addedmicromark-util-resolve-all@2.0.0(transitive)
+ Addedmicromark-util-sanitize-uri@2.0.0(transitive)
+ Addedmicromark-util-subtokenize@2.0.1(transitive)
+ Addedmicromark-util-symbol@2.0.0(transitive)
+ Addedmicromark-util-types@2.0.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedunist-util-visit@5.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(transitive)
- Removed@types/mdast@3.0.15(transitive)
- Removed@types/unist@2.0.11(transitive)
- Removedmdast-util-phrasing@3.0.1(transitive)
- Removedmdast-util-to-markdown@1.5.0(transitive)
- Removedmdast-util-to-string@3.2.0(transitive)
- Removedmicromark-util-character@1.2.0(transitive)
- Removedmicromark-util-decode-numeric-character-reference@1.1.0(transitive)
- Removedmicromark-util-decode-string@1.1.0(transitive)
- Removedmicromark-util-symbol@1.1.0(transitive)
- Removedmicromark-util-types@1.1.0(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
Updated@types/mdast@^4.0.0