mdast-util-gfm-task-list-item
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,2 +5,6 @@ /** @type {FromMarkdownExtension} */ | ||
export const gfmTaskListItemToMarkdown: ToMarkdownExtension | ||
export type Parent = Extract< | ||
import('mdast').Root | import('mdast').Content, | ||
import('unist').Parent | ||
> | ||
export type ListItem = import('mdast').ListItem | ||
@@ -7,0 +11,0 @@ export type Paragraph = import('mdast').Paragraph |
43
index.js
/** | ||
* @typedef {Extract<import('mdast').Root|import('mdast').Content, import('unist').Parent>} Parent | ||
* @typedef {import('mdast').ListItem} ListItem | ||
@@ -12,2 +13,3 @@ * @typedef {import('mdast').Paragraph} Paragraph | ||
import {listItem} from 'mdast-util-to-markdown/lib/handle/list-item.js' | ||
import {track} from 'mdast-util-to-markdown/lib/util/track.js' | ||
@@ -31,5 +33,5 @@ /** @type {FromMarkdownExtension} */ | ||
function exitCheck(token) { | ||
const node = /** @type {ListItem} */ (this.stack[this.stack.length - 2]) | ||
// We’re always in a paragraph, in a list item. | ||
this.stack[this.stack.length - 2].checked = | ||
token.type === 'taskListCheckValueChecked' | ||
node.checked = token.type === 'taskListCheckValueChecked' | ||
} | ||
@@ -39,8 +41,4 @@ | ||
function exitParagraphWithTaskListItem(token) { | ||
const parent = this.stack[this.stack.length - 2] | ||
/** @type {Paragraph} */ | ||
// @ts-expect-error: must be true. | ||
const node = this.stack[this.stack.length - 1] | ||
/** @type {BlockContent[]} */ | ||
// @ts-expect-error: check whether `parent` is a `listItem` later. | ||
const parent = /** @type {Parent} */ (this.stack[this.stack.length - 2]) | ||
const node = /** @type {Paragraph} */ (this.stack[this.stack.length - 1]) | ||
const siblings = parent.children | ||
@@ -73,8 +71,9 @@ const head = node.children[0] | ||
node.children.shift() | ||
} else { | ||
// @ts-expect-error: must be true. | ||
} else if ( | ||
node.position && | ||
head.position && | ||
typeof head.position.start.offset === 'number' | ||
) { | ||
head.position.start.column++ | ||
// @ts-expect-error: must be true. | ||
head.position.start.offset++ | ||
// @ts-expect-error: must be true. | ||
node.position.start = Object.assign({}, head.position.start) | ||
@@ -92,7 +91,19 @@ } | ||
*/ | ||
function listItemWithTaskListItem(node, parent, context) { | ||
function listItemWithTaskListItem(node, parent, context, safeOptions) { | ||
const head = node.children[0] | ||
let value = listItem(node, parent, context) | ||
const checkable = | ||
typeof node.checked === 'boolean' && head && head.type === 'paragraph' | ||
const checkbox = '[' + (node.checked ? 'x' : ' ') + '] ' | ||
const tracker = track(safeOptions) | ||
if (typeof node.checked === 'boolean' && head && head.type === 'paragraph') { | ||
if (checkable) { | ||
tracker.move(checkbox) | ||
} | ||
let value = listItem(node, parent, context, { | ||
...safeOptions, | ||
...tracker.current() | ||
}) | ||
if (checkable) { | ||
value = value.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/, check) | ||
@@ -108,4 +119,4 @@ } | ||
function check($0) { | ||
return $0 + '[' + (node.checked ? 'x' : ' ') + '] ' | ||
return $0 + checkbox | ||
} | ||
} |
{ | ||
"name": "mdast-util-gfm-task-list-item", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "mdast extension to parse and serialize GFM task list items", | ||
@@ -41,4 +41,4 @@ "license": "MIT", | ||
"dependencies": { | ||
"@types/mdast": "^3.0.3", | ||
"mdast-util-to-markdown": "^1.0.0" | ||
"@types/mdast": "^3.0.0", | ||
"mdast-util-to-markdown": "^1.3.0" | ||
}, | ||
@@ -51,4 +51,4 @@ "devDependencies": { | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
@@ -59,3 +59,3 @@ "tape": "^5.0.0", | ||
"unist-util-remove-position": "^4.0.0", | ||
"xo": "^0.39.0" | ||
"xo": "^0.47.0" | ||
}, | ||
@@ -62,0 +62,0 @@ "scripts": { |
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
13668
116
0
Updated@types/mdast@^3.0.0