micromark-extension-gfm
Advanced tools
Comparing version 2.0.1 to 2.0.2
/** | ||
* Support GFM or markdown on github.com. | ||
* Add support for parsing GFM in markdown. | ||
* | ||
* Function that can be called to get a syntax extension for micromark (passed | ||
* in `extensions`). | ||
* | ||
* @param {Options} [options] | ||
* Configuration (optional). | ||
* Passed to `micromark-extens-gfm-strikethrough`. | ||
* @returns {Extension} | ||
* Syntax extension for micromark (passed in `extensions`). | ||
*/ | ||
@@ -13,6 +19,12 @@ export function gfm( | ||
/** | ||
* Support to compile GFM to HTML. | ||
* Add support for turning GFM in markdown to HTML. | ||
* | ||
* Function that can be called to get an HTML extension for micromark (passed | ||
* in `htmlExtensions`). | ||
* | ||
* @param {HtmlOptions} [options] | ||
* Configuration (optional). | ||
* Passed to `micromark-extens-gfm-footnote`. | ||
* @returns {HtmlExtension} | ||
* HTML extension for micromark (passed in `htmlExtensions`). | ||
*/ | ||
@@ -19,0 +31,0 @@ export function gfmHtml( |
22
index.js
/** | ||
* @typedef {import('micromark-extension-gfm-footnote').HtmlOptions} HtmlOptions | ||
* @typedef {import('micromark-extension-gfm-strikethrough').Options} Options | ||
* @typedef {import('micromark-util-types').Extension} Extension | ||
* @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension | ||
* @typedef {import('micromark-extension-gfm-strikethrough').Options} Options | ||
* @typedef {import('micromark-extension-gfm-footnote').HtmlOptions} HtmlOptions | ||
*/ | ||
@@ -29,6 +29,11 @@ | ||
/** | ||
* Support GFM or markdown on github.com. | ||
* Create an extension for `micromark` to enable GFM syntax. | ||
* | ||
* @param {Options} [options] | ||
* @param {Options | null | undefined} [options] | ||
* Configuration (optional). | ||
* | ||
* Passed to `micromark-extens-gfm-strikethrough`. | ||
* @returns {Extension} | ||
* Extension for `micromark` that can be passed in `extensions` to enable GFM | ||
* syntax. | ||
*/ | ||
@@ -46,6 +51,11 @@ export function gfm(options) { | ||
/** | ||
* Support to compile GFM to HTML. | ||
* Create an extension for `micromark` to support GFM when serializing to HTML. | ||
* | ||
* @param {HtmlOptions} [options] | ||
* @param {HtmlOptions | null | undefined} [options] | ||
* Configuration. | ||
* | ||
* Passed to `micromark-extens-gfm-footnote`. | ||
* @returns {HtmlExtension} | ||
* Extension for `micromark` that can be passed in `htmlExtensions` to | ||
* support GFM when serializing to HTML. | ||
*/ | ||
@@ -52,0 +62,0 @@ export function gfmHtml(options) { |
{ | ||
"name": "micromark-extension-gfm", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "micromark extension to support GFM (GitHub Flavored Markdown)", | ||
@@ -49,28 +49,27 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/node-fetch": "^3.0.0", | ||
"@types/tape": "^4.0.0", | ||
"@types/node": "^20.0.0", | ||
"c8": "^7.0.0", | ||
"create-gfm-fixtures": "^1.0.0", | ||
"hast-util-from-html": "^1.0.0", | ||
"hast-util-select": "^5.0.0", | ||
"hast-util-to-text": "^3.0.0", | ||
"micromark": "^3.0.0", | ||
"node-fetch": "^3.0.0", | ||
"prettier": "^2.0.0", | ||
"rehype": "^12.0.0", | ||
"rehype-parse": "^8.0.0", | ||
"rehype-sort-attributes": "^4.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", | ||
"unified": "^10.0.0", | ||
"xo": "^0.47.0" | ||
"typescript": "^5.0.0", | ||
"undici": "^5.0.0", | ||
"xo": "^0.54.0" | ||
}, | ||
"scripts": { | ||
"build": "rimraf \"*.d.ts\" \"script/**/*.d.ts\" \"test/**/*.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/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" | ||
@@ -77,0 +76,0 @@ }, |
270
readme.md
@@ -11,3 +11,3 @@ # micromark-extension-gfm | ||
**[micromark][]** extension to support GitHub flavored markdown ([GFM][]). | ||
[micromark][] extensions to support [GitHub flavored markdown][gfm] (GFM). | ||
@@ -22,7 +22,13 @@ ## Contents | ||
* [`gfm(options?)`](#gfmoptions) | ||
* [`gfmHtml(htmlOptions?)`](#gfmhtmlhtmloptions) | ||
* [`gfmHtml(options?)`](#gfmhtmloptions) | ||
* [`Options`](#options) | ||
* [`HtmlOptions`](#htmloptions) | ||
* [Bugs](#bugs) | ||
* [Authoring](#authoring) | ||
* [HTML](#html) | ||
* [CSS](#css) | ||
* [Syntax](#syntax) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
* [Related](#related) | ||
* [Contribute](#contribute) | ||
@@ -33,35 +39,37 @@ * [License](#license) | ||
This package is a micromark extension to add support for all GFM features: | ||
autolink literals, footnotes, strikethrough, tables, tagfilter, and tasklists. | ||
This package contains extensions that add support for all features enabled by | ||
GFM to [`micromark`][micromark]. | ||
It supports autolink literals, footnotes, strikethrough, tables, tagfilter, and | ||
tasklists. | ||
## When to use this | ||
You probably should use this package if you use micromark and want to enable | ||
GFM. | ||
When working with syntax trees, you’d want to combine this package with | ||
[`mdast-util-gfm`][mdast-util-gfm]. | ||
This project is useful when you want to support GFM in markdown. | ||
You can also use the underlying features separately: | ||
You can use these extensions when you are working with [`micromark`][micromark]. | ||
Alternatively, you can also use the underlying features separately: | ||
* [`micromark/micromark-extension-gfm-autolink-literal`][gfm-autolink-literal] | ||
* [`micromark-extension-gfm-autolink-literal`][gfm-autolink-literal] | ||
— support GFM [autolink literals][] | ||
* [`micromark/micromark-extension-gfm-footnote`][gfm-footnote] | ||
— support GFM footnotes | ||
* [`micromark/micromark-extension-gfm-strikethrough`][gfm-strikethrough] | ||
* [`micromark-extension-gfm-footnote`][gfm-footnote] | ||
— support GFM [footnotes][] | ||
* [`micromark-extension-gfm-strikethrough`][gfm-strikethrough] | ||
— support GFM [strikethrough][] | ||
* [`micromark/micromark-extension-gfm-table`][gfm-table] | ||
* [`micromark-extension-gfm-table`][gfm-table] | ||
— support GFM [tables][] | ||
* [`micromark/micromark-extension-gfm-tagfilter`][gfm-tagfilter] | ||
* [`micromark-extension-gfm-tagfilter`][gfm-tagfilter] | ||
— support GFM [tagfilter][] | ||
* [`micromark/micromark-extension-gfm-task-list-item`][gfm-task-list-item] | ||
* [`micromark-extension-gfm-task-list-item`][gfm-task-list-item] | ||
— support GFM [tasklists][] | ||
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, combine this package with | ||
[`mdast-util-gfm`][mdast-util-gfm]. | ||
All these packages are used in [`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 16+), install with [npm][]: | ||
@@ -72,13 +80,13 @@ ```sh | ||
In Deno with [Skypack][]: | ||
In Deno with [`esm.sh`][esmsh]: | ||
```js | ||
import {gfm, gfmHtml} from 'https://cdn.skypack.dev/micromark-extension-gfm@2?dts' | ||
import {gfm, gfmHtml} from 'https://esm.sh/micromark-extension-gfm@2' | ||
``` | ||
In browsers with [Skypack][]: | ||
In browsers with [`esm.sh`][esmsh]: | ||
```html | ||
<script type="module"> | ||
import {gfm, gfmHtml} from 'https://cdn.skypack.dev/micromark-extension-gfm@2?min' | ||
import {gfm, gfmHtml} from 'https://esm.sh/micromark-extension-gfm@2?bundle' | ||
</script> | ||
@@ -89,3 +97,3 @@ ``` | ||
Say we have the following file `example.md`: | ||
Say our document `example.md` contains: | ||
@@ -124,10 +132,10 @@ ```markdown | ||
And our module `example.js` looks as follows: | ||
…and our module `example.js` looks as follows: | ||
```js | ||
import fs from 'node:fs' | ||
import fs from 'node:fs/promises' | ||
import {micromark} from 'micromark' | ||
import {gfm, gfmHtml} from 'micromark-extension-gfm' | ||
const output = micromark(fs.readFileSync('example.md'), { | ||
const output = micromark(await fs.readFile('example.md'), { | ||
allowDangerousHtml: true, | ||
@@ -141,3 +149,3 @@ extensions: [gfm()], | ||
Now, running `node example` yields: | ||
…now running `node example.js` yields: | ||
@@ -181,6 +189,7 @@ ```html | ||
This package exports the following identifiers: `gfm`, `gfmHtml`. | ||
This package exports the identifiers [`gfm`][api-gfm] and | ||
[`gfmHtml`][api-gfm-html]. | ||
There is no default export. | ||
This extensions supports the endorsed [`development` condition][dev]. | ||
The separate extensions support the [`development` condition][development]. | ||
Run `node --conditions development module.js` to get instrumented dev code. | ||
@@ -191,81 +200,132 @@ Without this condition, production code is loaded. | ||
A function that can be called to get an extension for micromark to parse GFM | ||
(can be passed in `extensions`). | ||
Create an extension for `micromark` to enable GFM syntax. | ||
##### `options` | ||
###### Parameters | ||
Configuration (optional). | ||
* `options` ([`Options`][api-options], optional) | ||
— configuration; passed to | ||
[`micromark-extens-gfm-strikethrough`][gfm-strikethrough-options] | ||
###### `options.singleTilde` | ||
###### Returns | ||
Whether to support strikethrough with a single tilde (`boolean`, default: | ||
`true`). | ||
Single tildes work on github.com, but are technically prohibited by GFM. | ||
Passed as [`singleTilde`][single-tilde] in | ||
[`micromark-extension-gfm-strikethrough`][gfm-strikethrough]. | ||
Extension for `micromark` that can be passed in `extensions` to enable GFM | ||
syntax ([`Extension`][micromark-extension]). | ||
### `gfmHtml(htmlOptions?)` | ||
### `gfmHtml(options?)` | ||
A function that can be called to get an extension to compile GFM to HTML (can be | ||
passed in `htmlExtensions`). | ||
Create an extension for `micromark` to support GFM when serializing to HTML. | ||
##### `htmlOptions` | ||
###### Parameters | ||
Configuration (optional). | ||
* `options` ([`HtmlOptions`][api-html-options], optional) | ||
— configuration; passed to | ||
[`micromark-extens-gfm-footnote`][gfm-footnote-html-options] | ||
###### `htmlOptions.clobberPrefix` | ||
###### Returns | ||
Prefix to use before the `id` attribute to prevent it from *clobbering* | ||
attributes (`string`, default: `'user-content-'`). | ||
Passed as [`clobberPrefix`][clobber-prefix] in | ||
[`micromark-extension-gfm-footnote`][gfm-footnote]. | ||
Extension for `micromark` that can be passed in `htmlExtensions` to support GFM | ||
when serializing to HTML ([`HtmlExtension`][micromark-html-extension]). | ||
###### `htmlOptions.label` | ||
### `Options` | ||
Label to use for the footnotes section (`string`, default: `'Footnotes'`). | ||
Passed as [`label`][label] in | ||
[`micromark-extension-gfm-footnote`][gfm-footnote]. | ||
Configuration for syntax (TypeScript type). | ||
###### `htmlOptions.backLabel` | ||
###### Type | ||
Label to use from backreferences back to their footnote call (`string`, default: | ||
`'Back to content'`). | ||
Passed as [`backLabel`][backlabel] in | ||
[`micromark-extension-gfm-footnote`][gfm-footnote]. | ||
```ts | ||
export type {Options} from 'micromark-extension-gfm-strikethrough' | ||
``` | ||
[See `Options`][gfm-strikethrough-options]. | ||
### `HtmlOptions` | ||
Configuration for HTML (TypeScript type). | ||
###### Type | ||
```ts | ||
export type {HtmlOptions} from 'micromark-extension-gfm-footnote' | ||
``` | ||
[See `HtmlOptions`][gfm-footnote-html-options]. | ||
## Bugs | ||
For bugs present in GFM but not here, or other peculiarities that are | ||
supported, see each corresponding readme: | ||
* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#bugs) | ||
* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#bugs) | ||
* strikethrough: n/a | ||
* [table](https://github.com/micromark/micromark-extension-gfm-table#bugs) | ||
* tagfilter: n/a | ||
* tasklists: n/a | ||
## Authoring | ||
For recommendations on how to author GFM, see each corresponding readme: | ||
* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#authoring) | ||
* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#authoring) | ||
* [strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough#authoring) | ||
* [table](https://github.com/micromark/micromark-extension-gfm-table#authoring) | ||
* tagfilter: n/a | ||
* [tasklists](https://github.com/micromark/micromark-extension-gfm-task-list-item#authoring) | ||
## HTML | ||
For info on what HTML features GFM relates to, see each corresponding readme: | ||
* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#html) | ||
* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#html) | ||
* [strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough#html) | ||
* [table](https://github.com/micromark/micromark-extension-gfm-table#html) | ||
* [tagfilter](https://github.com/micromark/micromark-extension-gfm-tagfilter#html) | ||
* [tasklists](https://github.com/micromark/micromark-extension-gfm-task-list-item#html) | ||
## CSS | ||
For info on how GitHub styles these features, see each corresponding readme: | ||
* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#css) | ||
* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#css) | ||
* [strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough#css) | ||
* [table](https://github.com/micromark/micromark-extension-gfm-table#css) | ||
* tagfilter: n/a | ||
* [tasklists](https://github.com/micromark/micromark-extension-gfm-task-list-item#css) | ||
## Syntax | ||
For info on the syntax of these features, see each corresponding readme: | ||
* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#syntax) | ||
* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#syntax) | ||
* [strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough#syntax) | ||
* [table](https://github.com/micromark/micromark-extension-gfm-table#syntax) | ||
* tagfilter: n/a | ||
* [tasklists](https://github.com/micromark/micromark-extension-gfm-task-list-item#syntax) | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
It exports additional `Options` and `HtmlOptions` types that model their | ||
respective interfaces. | ||
It exports the additional types [`HtmlOptions`][api-html-options] and | ||
[`Options`][api-options]. | ||
## 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 16+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
These extensions work with `micromark` version 3+. | ||
## Security | ||
This package is safe by default. | ||
This package is safe. | ||
Setting `clobberPrefix = ''` is dangerous, it opens you up to DOM clobbering. | ||
The `labelTagName` and `labelAttributes` options are unsafe when used with user | ||
content, they allow defining arbitrary HTML. | ||
## Related | ||
* [`syntax-tree/mdast-util-gfm`][mdast-util-gfm] | ||
— support GFM in mdast | ||
* [`remarkjs/remark-gfm`][remark-gfm] | ||
— support GFM in remark | ||
* [`micromark/micromark-extension-gfm-autolink-literal`][gfm-autolink-literal] | ||
— support GFM [autolink literals][] | ||
* [`micromark/micromark-extension-gfm-footnote`][gfm-footnote] | ||
— support GFM footnotes | ||
* [`micromark/micromark-extension-gfm-strikethrough`][gfm-strikethrough] | ||
— support GFM [strikethrough][] | ||
* [`micromark/micromark-extension-gfm-table`][gfm-table] | ||
— support GFM [tables][] | ||
* [`micromark/micromark-extension-gfm-tagfilter`][gfm-tagfilter] | ||
— support GFM [tagfilter][] | ||
* [`micromark/micromark-extension-gfm-task-list-item`][gfm-task-list-item] | ||
— support GFM [tasklists][] | ||
## Contribute | ||
@@ -315,3 +375,3 @@ | ||
[skypack]: https://www.skypack.dev | ||
[esmsh]: https://esm.sh | ||
@@ -322,20 +382,14 @@ [license]: license | ||
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md | ||
[contributing]: https://github.com/micromark/.github/blob/main/contributing.md | ||
[support]: https://github.com/micromark/.github/blob/HEAD/support.md | ||
[support]: https://github.com/micromark/.github/blob/main/support.md | ||
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md | ||
[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[dev]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions | ||
[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions | ||
[typescript]: https://www.typescriptlang.org | ||
[micromark]: https://github.com/micromark/micromark | ||
[remark]: https://github.com/remarkjs/remark | ||
[remark-gfm]: https://github.com/remarkjs/remark-gfm | ||
[gfm]: https://github.github.com/gfm/ | ||
@@ -353,12 +407,14 @@ | ||
[single-tilde]: https://github.com/micromark/micromark-extension-gfm-strikethrough#optionssingletilde | ||
[footnotes]: https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/ | ||
[clobber-prefix]: https://github.com/micromark/micromark-extension-gfm-footnote#htmloptionsclobberprefix | ||
[micromark]: https://github.com/micromark/micromark | ||
[label]: https://github.com/micromark/micromark-extension-gfm-footnote#htmloptionslabel | ||
[micromark-extension]: https://github.com/micromark/micromark#syntaxextension | ||
[backlabel]: https://github.com/micromark/micromark-extension-gfm-footnote#htmloptionsbacklabel | ||
[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension | ||
[gfm-strikethrough]: https://github.com/micromark/micromark-extension-gfm-strikethrough | ||
[gfm-strikethrough-options]: https://github.com/micromark/micromark-extension-gfm-strikethrough#options | ||
[gfm-autolink-literal]: https://github.com/micromark/micromark-extension-gfm-autolink-literal | ||
@@ -368,2 +424,4 @@ | ||
[gfm-footnote-html-options]: https://github.com/micromark/micromark-extension-gfm-footnote#htmloptions | ||
[gfm-table]: https://github.com/micromark/micromark-extension-gfm-table | ||
@@ -375,2 +433,12 @@ | ||
[remark-gfm]: https://github.com/remarkjs/remark-gfm | ||
[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm | ||
[api-gfm]: #gfmoptions | ||
[api-gfm-html]: #gfmhtmloptions | ||
[api-options]: #options | ||
[api-html-options]: #htmloptions |
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
20306
16
104
431