Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

micromark-extension-gfm-task-list-item

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micromark-extension-gfm-task-list-item - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

7

dev/lib/html.d.ts
/**
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
*/
/** @type {HtmlExtension} */
/**
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GFM task list items when serializing to HTML.
*
* @type {HtmlExtension}
*/
export const gfmTaskListItemHtml: HtmlExtension
export type HtmlExtension = import('micromark-util-types').HtmlExtension

@@ -5,3 +5,10 @@ /**

/** @type {HtmlExtension} */
// To do: next major: expose function to make extension.
/**
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GFM task list items when serializing to HTML.
*
* @type {HtmlExtension}
*/
export const gfmTaskListItemHtml = {

@@ -8,0 +15,0 @@ enter: {

28

dev/lib/syntax.d.ts

@@ -1,21 +0,11 @@

export namespace gfmTaskListItem {
const text: {
[x: number]: {
tokenize: typeof tokenizeTasklistCheck
}
}
}
/**
* Extension for `micromark` that can be passed in `extensions`, to
* enable GFM task list items syntax.
*
* @type {Extension}
*/
export const gfmTaskListItem: Extension
export type Extension = import('micromark-util-types').Extension
export type ConstructRecord = import('micromark-util-types').ConstructRecord
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer
export type Previous = import('micromark-util-types').Previous
export type State = import('micromark-util-types').State
export type Event = import('micromark-util-types').Event
export type Code = import('micromark-util-types').Code
/** @type {Tokenizer} */
declare function tokenizeTasklistCheck(
effects: import('micromark-util-types').Effects,
ok: import('micromark-util-types').State,
nok: import('micromark-util-types').State
): import('micromark-util-types').State
export {}
/**
* @typedef {import('micromark-util-types').Extension} Extension
* @typedef {import('micromark-util-types').ConstructRecord} ConstructRecord
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
* @typedef {import('micromark-util-types').Previous} Previous
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').Code} Code
*/

@@ -15,3 +12,4 @@

markdownLineEndingOrSpace,
markdownLineEnding
markdownLineEnding,
markdownSpace
} from 'micromark-util-character'

@@ -23,2 +21,10 @@ import {codes} from 'micromark-util-symbol/codes.js'

// To do: next major: expose function to make extension.
/**
* Extension for `micromark` that can be passed in `extensions`, to
* enable GFM task list items syntax.
*
* @type {Extension}
*/
export const gfmTaskListItem = {

@@ -28,3 +34,6 @@ text: {[codes.leftSquareBracket]: tasklistCheck}

/** @type {Tokenizer} */
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeTasklistCheck(effects, ok, nok) {

@@ -35,3 +44,12 @@ const self = this

/** @type {State} */
/**
* At start of task list item check.
*
* ```markdown
* > | * [x] y.
* ^
* ```
*
* @type {State}
*/
function open(code) {

@@ -57,6 +75,16 @@ assert(code === codes.leftSquareBracket, 'expected `[`')

/** @type {State} */
/**
* In task list item check.
*
* ```markdown
* > | * [x] y.
* ^
* ```
*
* @type {State}
*/
function inside(code) {
// To match how GH works in comments, use `markdownSpace` (`[ \t]`) instead
// of `markdownLineEndingOrSpace` (`[ \t\r\n]`).
// Currently we match how GH works in files.
// To match how GH works in comments, use `markdownSpace` (`[\t ]`) instead
// of `markdownLineEndingOrSpace` (`[\t\n\r ]`).
if (markdownLineEndingOrSpace(code)) {

@@ -79,3 +107,12 @@ effects.enter('taskListCheckValueUnchecked')

/** @type {State} */
/**
* At close of task list item check.
*
* ```markdown
* > | * [x] y.
* ^
* ```
*
* @type {State}
*/
function close(code) {

@@ -87,3 +124,3 @@ if (code === codes.rightSquareBracket) {

effects.exit('taskListCheck')
return effects.check({tokenize: spaceThenNonSpace}, ok, nok)
return after
}

@@ -93,26 +130,47 @@

}
/**
* @type {State}
*/
function after(code) {
// EOL in paragraph means there must be something else after it.
if (markdownLineEnding(code)) {
return ok(code)
}
// Space or tab?
// Check what comes after.
if (markdownSpace(code)) {
return effects.check({tokenize: spaceThenNonSpace}, ok, nok)(code)
}
// EOF, or non-whitespace, both wrong.
return nok(code)
}
}
/** @type {Tokenizer} */
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function spaceThenNonSpace(effects, ok, nok) {
const self = this
return factorySpace(effects, after, types.whitespace)
/** @type {State} */
/**
* After whitespace, after task list item check.
*
* ```markdown
* > | * [x] y.
* ^
* ```
*
* @type {State}
*/
function after(code) {
const tail = self.events[self.events.length - 1]
return (
// We either found spaces…
((tail && tail[1].type === types.whitespace) ||
// …or it was followed by a line ending, in which case, there has to be
// non-whitespace after that line ending, because otherwise we’d get an
// EOF as the content is closed with blank lines.
markdownLineEnding(code)) &&
code !== codes.eof
? ok(code)
: nok(code)
)
// EOF means there was nothing, so bad.
// EOL means there’s content after it, so good.
// Impossible to have more spaces.
// Anything else is good.
return code === codes.eof ? nok(code) : ok(code)
}
}
/**
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension
*/
/** @type {HtmlExtension} */
/**
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GFM task list items when serializing to HTML.
*
* @type {HtmlExtension}
*/
export const gfmTaskListItemHtml: HtmlExtension
export type HtmlExtension = import('micromark-util-types').HtmlExtension

@@ -5,3 +5,10 @@ /**

/** @type {HtmlExtension} */
// To do: next major: expose function to make extension.
/**
* Extension for `micromark` that can be passed in `htmlExtensions` to
* support GFM task list items when serializing to HTML.
*
* @type {HtmlExtension}
*/
export const gfmTaskListItemHtml = {

@@ -17,3 +24,2 @@ enter: {

},
taskListCheckValueChecked() {

@@ -20,0 +26,0 @@ this.tag('checked="" ')

@@ -1,21 +0,11 @@

export namespace gfmTaskListItem {
const text: {
[x: number]: {
tokenize: typeof tokenizeTasklistCheck
}
}
}
/**
* Extension for `micromark` that can be passed in `extensions`, to
* enable GFM task list items syntax.
*
* @type {Extension}
*/
export const gfmTaskListItem: Extension
export type Extension = import('micromark-util-types').Extension
export type ConstructRecord = import('micromark-util-types').ConstructRecord
export type State = import('micromark-util-types').State
export type TokenizeContext = import('micromark-util-types').TokenizeContext
export type Tokenizer = import('micromark-util-types').Tokenizer
export type Previous = import('micromark-util-types').Previous
export type State = import('micromark-util-types').State
export type Event = import('micromark-util-types').Event
export type Code = import('micromark-util-types').Code
/** @type {Tokenizer} */
declare function tokenizeTasklistCheck(
effects: import('micromark-util-types').Effects,
ok: import('micromark-util-types').State,
nok: import('micromark-util-types').State
): import('micromark-util-types').State
export {}
/**
* @typedef {import('micromark-util-types').Extension} Extension
* @typedef {import('micromark-util-types').ConstructRecord} ConstructRecord
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext
* @typedef {import('micromark-util-types').Tokenizer} Tokenizer
* @typedef {import('micromark-util-types').Previous} Previous
* @typedef {import('micromark-util-types').State} State
* @typedef {import('micromark-util-types').Event} Event
* @typedef {import('micromark-util-types').Code} Code
*/
import {factorySpace} from 'micromark-factory-space'
import {
markdownLineEndingOrSpace,
markdownLineEnding
markdownLineEnding,
markdownSpace
} from 'micromark-util-character'

@@ -18,2 +17,11 @@ const tasklistCheck = {

}
// To do: next major: expose function to make extension.
/**
* Extension for `micromark` that can be passed in `extensions`, to
* enable GFM task list items syntax.
*
* @type {Extension}
*/
export const gfmTaskListItem = {

@@ -24,13 +32,26 @@ text: {

}
/** @type {Tokenizer} */
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeTasklistCheck(effects, ok, nok) {
const self = this
return open
/** @type {State} */
/**
* At start of task list item check.
*
* ```markdown
* > | * [x] y.
* ^
* ```
*
* @type {State}
*/
function open(code) {
if (
// Exit if there’s stuff before.
self.previous !== null || // Exit if not in the first content that is the first child of a list
self.previous !== null ||
// Exit if not in the first content that is the first child of a list
// item.

@@ -41,3 +62,2 @@ !self._gfmTasklistFirstContentOfListItem

}
effects.enter('taskListCheck')

@@ -49,7 +69,17 @@ effects.enter('taskListCheckMarker')

}
/** @type {State} */
/**
* In task list item check.
*
* ```markdown
* > | * [x] y.
* ^
* ```
*
* @type {State}
*/
function inside(code) {
// To match how GH works in comments, use `markdownSpace` (`[ \t]`) instead
// of `markdownLineEndingOrSpace` (`[ \t\r\n]`).
// Currently we match how GH works in files.
// To match how GH works in comments, use `markdownSpace` (`[\t ]`) instead
// of `markdownLineEndingOrSpace` (`[\t\n\r ]`).
if (markdownLineEndingOrSpace(code)) {

@@ -61,3 +91,2 @@ effects.enter('taskListCheckValueUnchecked')

}
if (code === 88 || code === 120) {

@@ -69,7 +98,15 @@ effects.enter('taskListCheckValueChecked')

}
return nok(code)
}
/** @type {State} */
/**
* At close of task list item check.
*
* ```markdown
* > | * [x] y.
* ^
* ```
*
* @type {State}
*/
function close(code) {

@@ -81,2 +118,19 @@ if (code === 93) {

effects.exit('taskListCheck')
return after
}
return nok(code)
}
/**
* @type {State}
*/
function after(code) {
// EOL in paragraph means there must be something else after it.
if (markdownLineEnding(code)) {
return ok(code)
}
// Space or tab?
// Check what comes after.
if (markdownSpace(code)) {
return effects.check(

@@ -88,28 +142,34 @@ {

nok
)
)(code)
}
// EOF, or non-whitespace, both wrong.
return nok(code)
}
}
/** @type {Tokenizer} */
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function spaceThenNonSpace(effects, ok, nok) {
const self = this
return factorySpace(effects, after, 'whitespace')
/** @type {State} */
/**
* After whitespace, after task list item check.
*
* ```markdown
* > | * [x] y.
* ^
* ```
*
* @type {State}
*/
function after(code) {
const tail = self.events[self.events.length - 1]
return (
// We either found spaces…
((tail && tail[1].type === 'whitespace') || // …or it was followed by a line ending, in which case, there has to be
// non-whitespace after that line ending, because otherwise we’d get an
// EOF as the content is closed with blank lines.
markdownLineEnding(code)) &&
code !== null
? ok(code)
: nok(code)
)
// EOF means there was nothing, so bad.
// EOL means there’s content after it, so good.
// Impossible to have more spaces.
// Anything else is good.
return code === null ? nok(code) : ok(code)
}
}
{
"name": "micromark-extension-gfm-task-list-item",
"version": "1.0.3",
"version": "1.0.4",
"description": "micromark extension to support GFM task list items",

@@ -51,3 +51,3 @@ "license": "MIT",

"devDependencies": {
"@types/tape": "^4.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",

@@ -59,15 +59,16 @@ "control-pictures": "^2.0.0",

"prettier": "^2.0.0",
"remark-cli": "^10.0.0",
"remark-cli": "^11.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",
"xo": "^0.47.0"
"typescript": "^5.0.0",
"xo": "^0.53.0"
},
"scripts": {
"build": "rimraf \"dev/**/*.d.ts\" \"test/**/*.d.ts\" && tsc && type-coverage && micromark-build",
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage && micromark-build",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node --conditions development test/index.js",
"test-api-prod": "node --conditions production test/index.js",
"test-api-dev": "node --conditions development test/index.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"

@@ -86,9 +87,19 @@ },

"rules": {
"node/file-extension-in-import": "off",
"n/file-extension-in-import": "off",
"unicorn/no-this-assignment": "off"
}
},
"overrides": [
{
"files": [
"test/**/*.js"
],
"rules": {
"no-await-in-loop": 0
}
}
]
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]

@@ -95,0 +106,0 @@ },

@@ -11,4 +11,3 @@ # micromark-extension-gfm-task-list-item

**[micromark][]** extension to support GitHub flavored markdown (GFM) [task list
items][].
[micromark][] extensions to support GFM [task list items][].

@@ -24,2 +23,6 @@ ## Contents

* [`gfmTaskListItemHtml`](#gfmtasklistitemhtml)
* [Authoring](#authoring)
* [HTML](#html)
* [CSS](#css)
* [Syntax](#syntax)
* [Types](#types)

@@ -34,3 +37,4 @@ * [Compatibility](#compatibility)

This package is a micromark extension to add support for GFM task list items.
This package contains extensions that add support for task lists as enabled by
GFM to [`micromark`][micromark].
It matches how task list items work on `github.com`.

@@ -40,18 +44,18 @@

In many cases, when working with micromark, you’d want to use
[`micromark-extension-gfm`][micromark-extension-gfm] instead, which combines
this package with other GFM features.
This project is useful when you want to support task lists in markdown.
When working with syntax trees, you’d want to combine this package with
[`mdast-util-gfm-task-list-item`][mdast-util-gfm-task-list-item] (or
[`mdast-util-gfm`][mdast-util-gfm] when using `micromark-extension-gfm`).
You can use these extensions when you are working with [`micromark`][micromark].
To support all GFM features, use
[`micromark-extension-gfm`][micromark-extension-gfm].
These tools are all rather low-level.
In most cases, you’d instead want to use [`remark-gfm`][remark-gfm] with
[remark][].
When you need a syntax tree, you can combine this package with
[`mdast-util-gfm-task-list-item`][mdast-util-gfm-task-list-item].
All these packages are used [`remark-gfm`][remark-gfm], which focusses on making
it easier to transform content by abstracting these internals away.
## Install
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+), install with [npm][]:

@@ -62,13 +66,13 @@ ```sh

In Deno with [Skypack][]:
In Deno with [`esm.sh`][esmsh]:
```js
import {gfmTaskListItem, gfmTaskListItemHtml} from 'https://cdn.skypack.dev/micromark-extension-gfm-task-list-item@1?dts'
import {gfmTaskListItem, gfmTaskListItemHtml} from 'https://esm.sh/micromark-extension-gfm-task-list-item@1'
```
In browsers with [Skypack][]:
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {gfmTaskListItem, gfmTaskListItemHtml} from 'https://cdn.skypack.dev/micromark-extension-gfm-task-list-item@1?min'
import {gfmTaskListItem, gfmTaskListItemHtml} from 'https://esm.sh/micromark-extension-gfm-task-list-item@1?bundle'
</script>

@@ -105,8 +109,7 @@ ```

This package exports the following identifiers: `gfmTaskListItem`,
`gfmTaskListItemHtml`.
This package exports the identifiers [`gfmTaskListItem`][api-gfm-task-list-item]
and [`gfmTaskListItemHtml`][api-gfm-task-list-item-html].
There is no default export.
The export map supports the endorsed
[`development` condition](https://nodejs.org/api/packages.html#packages_resolving_user_conditions).
The export map supports the [`development` condition][development].
Run `node --conditions development module.js` to get instrumented dev code.

@@ -117,20 +120,81 @@ Without this condition, production code is loaded.

An extension for micromark to parse GFM task list items (can be passed in
`extensions`).
Extension for `micromark` that can be passed in `extensions`, to enable GFM
task list items syntax ([`Extension`][micromark-extension]).
### `gfmTaskListItemHtml`
An extension to compile them to HTML (can be passed in `htmlExtensions`).
Extension for `micromark` that can be passed in `htmlExtensions` to support GFM
task list items when serializing to HTML
([`HtmlExtension`][micromark-html-extension]).
## Authoring
It is recommended to use lowercase `x` (instead of uppercase `X`), because in
markdown, it is more common to use lowercase in places where casing does not
matter.
It is also recommended to use a space (instead of a tab), as there is no benefit
of using tabs in this case.
## HTML
Checks relate to the `<input>` element, in the checkbox state (`type=checkbox`),
in HTML.
See [*§ 4.10.5.1.15 Checkbox state (`type=checkbox`)*][html-input-checkbox]
in the HTML spec for more info.
```html
<!--…-->
<li><input type="checkbox" disabled="" /> foo</li>
<li><input type="checkbox" disabled="" checked="" /> bar</li>
<!--…-->
```
## CSS
GitHub itself uses slightly different markup for task list items than they
define in their spec.
When following the spec, as this extension does, only inputs are added.
They can be styled with the following CSS:
```css
input[type="checkbox"] {
margin: 0 .2em .25em -1.6em;
vertical-align: middle;
}
input[type="checkbox"]:dir(rtl) {
margin: 0 -1.6em .25em .2em;
}
```
For the complete actual CSS see
[`sindresorhus/github-markdown-css`][github-markdown-css].
## Syntax
Checks form with the following BNF:
```bnf
gfm_task_list_item_check ::= '[' (0x09 | ' ' | 'X' | 'x') ']'
```
The check is only allowed at the start of the first paragraph, optionally
following zero or more definitions or a blank line, in a list item.
The check must be followed by whitespace (`[\t\n\r ]*`), which is in turn
followed by non-whitespace.
## Types
This package is fully typed with [TypeScript][].
There are no additional exported types.
It exports no additional types.
## Compatibility
This package is at least compatible with all maintained versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
It also works in Deno and modern browsers.
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+.
Our projects sometimes work with older versions, but this is not guaranteed.
These extensions work with `micromark` version 3+.
## Security

@@ -142,8 +206,10 @@

* [`syntax-tree/mdast-util-gfm-task-list-item`][mdast-util-gfm-task-list-item]
— support GFM task list items in mdast
* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm]
— support GFM in mdast
* [`remarkjs/remark-gfm`][remark-gfm]
— support GFM in remark
* [`micromark-extension-gfm`][micromark-extension-gfm]
— support all of GFM
* [`mdast-util-gfm-task-list-item`][mdast-util-gfm-task-list-item]
— support all of GFM in mdast
* [`mdast-util-gfm`][mdast-util-gfm]
— support all of GFM in mdast
* [`remark-gfm`][remark-gfm]
— support all of GFM in remark

@@ -194,3 +260,3 @@ ## Contribute

[skypack]: https://www.skypack.dev
[esmsh]: https://esm.sh

@@ -211,6 +277,10 @@ [license]: license

[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions
[micromark]: https://github.com/micromark/micromark
[remark]: https://github.com/remarkjs/remark
[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension
[micromark-extension]: https://github.com/micromark/micromark#syntaxextension
[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm

@@ -225,1 +295,9 @@

[task list items]: https://github.github.com/gfm/#task-list-items-extension-
[github-markdown-css]: https://github.com/sindresorhus/github-markdown-css
[html-input-checkbox]: https://html.spec.whatwg.org/multipage/input.html#checkbox-state-\(type=checkbox\)
[api-gfm-task-list-item]: #gfmtasklistitem
[api-gfm-task-list-item-html]: #gfmtasklistitemhtml
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