Socket
Socket
Sign inDemoInstall

mdast-util-gfm-task-list-item

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mdast-util-gfm-task-list-item - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

4

index.d.ts

@@ -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": {

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc