(stephensugden.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------
The following NPM package may be included in this product:
- mermaid@9.4.3
This package contains the following license and notice below:
Mermaid
Generate diagrams from markdown-like text.
Live Editor!
📖 Documentation | 🚀 Getting Started | 🌐 CDN | 🙌 Join Us
简体中文
[](https://www.npmjs.com/package/mermaid)
[](https://github.com/mermaid-js/mermaid/actions/workflows/build.yml)
[](https://bundlephobia.com/package/mermaid)
[](https://coveralls.io/github/mermaid-js/mermaid?branch=master)
[](https://www.jsdelivr.com/package/npm/mermaid)
[](https://www.npmjs.com/package/mermaid)
[](https://join.slack.com/t/mermaid-talk/shared_invite/enQtNzc4NDIyNzk4OTAyLWVhYjQxOTI2OTg4YmE1ZmJkY2Y4MTU3ODliYmIwOTY3NDJlYjA0YjIyZTdkMDMyZTUwOGI0NjEzYmEwODcwOTE)
[](https://twitter.com/mermaidjs_)
:trophy: **Mermaid was nominated and won the [JS Open Source Awards (2019)](https://osawards.com/javascript/2019) in the category "The most exciting use of technology"!!!**
**Thanks to all involved, people committing pull requests, people answering questions! 🙏**
## About
Mermaid is a JavaScript-based diagramming and charting tool that uses Markdown-inspired text definitions and a renderer to create and modify complex diagrams. The main purpose of Mermaid is to help documentation catch up with development.
> Doc-Rot is a Catch-22 that Mermaid helps to solve.
Diagramming and documentation costs precious developer time and gets outdated quickly.
But not having diagrams or docs ruins productivity and hurts organizational learning.
Mermaid addresses this problem by enabling users to create easily modifiable diagrams. It can also be made part of production scripts (and other pieces of code).
Mermaid allows even non-programmers to easily create detailed diagrams through the [Mermaid Live Editor](https://mermaid.live/).
[Tutorials](./docs/config/Tutorials.md) has video tutorials.
Use Mermaid with your favorite applications, check out the list of [Integrations and Usages of Mermaid](./docs/ecosystem/integrations.md).
You can also use Mermaid within [GitHub](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/) as well many of your other favorite applications—check out the list of [Integrations and Usages of Mermaid](./docs/ecosystem/integrations.md).
For a more detailed introduction to Mermaid and some of its more basic uses, look to the [Beginner's Guide](./docs/community/n00b-overview.md), [Usage](./docs/config/usage.md) and [Tutorials](./docs/config/Tutorials.md).
In our release process we rely heavily on visual regression tests using [applitools](https://applitools.com/). Applitools is a great service which has been easy to use and integrate with our tests.
## Examples
**The following are some examples of the diagrams, charts and graphs that can be made using Mermaid. Click here to jump into the [text syntax](https://mermaid-js.github.io/mermaid/#/n00b-syntaxReference).**
### Flowchart [docs - live editor ]
```
flowchart LR
A[Hard] -->|Text| B(Round)
B --> C{Decision}
C -->|One| D[Result 1]
C -->|Two| E[Result 2]
```
```mermaid
flowchart LR
A[Hard] -->|Text| B(Round)
B --> C{Decision}
C -->|One| D[Result 1]
C -->|Two| E[Result 2]
```
### Sequence diagram [docs - live editor ]
```
sequenceDiagram
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
```
```mermaid
sequenceDiagram
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
```
### Gantt chart [docs - live editor ]
```
gantt
section Section
Completed :done, des1, 2014-01-06,2014-01-08
Active :active, des2, 2014-01-07, 3d
Parallel 1 : des3, after des1, 1d
Parallel 2 : des4, after des1, 1d
Parallel 3 : des5, after des3, 1d
Parallel 4 : des6, after des4, 1d
```
```mermaid
gantt
section Section
Completed :done, des1, 2014-01-06,2014-01-08
Active :active, des2, 2014-01-07, 3d
Parallel 1 : des3, after des1, 1d
Parallel 2 : des4, after des1, 1d
Parallel 3 : des5, after des3, 1d
Parallel 4 : des6, after des4, 1d
```
### Class diagram [docs - live editor ]
```
classDiagram
Class01 <|-- AveryLongClass : Cool
<> Class01
Class09 --> C2 : Where am I?
Class09 --* C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
class Class10 {
<>
int id
size()
}
```
```mermaid
classDiagram
Class01 <|-- AveryLongClass : Cool
<> Class01
Class09 --> C2 : Where am I?
Class09 --* C3
Class09 --|> Class07
Class07 : equals()
Class07 : Object[] elementData
Class01 : size()
Class01 : int chimp
Class01 : int gorilla
class Class10 {
<>
int id
size()
}
```
### State diagram [docs - live editor ]
```
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
```
```mermaid
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
```
### Pie chart [docs - live editor ]
```
pie
"Dogs" : 386
"Cats" : 85.9
"Rats" : 15
```
```mermaid
pie
"Dogs" : 386
"Cats" : 85.9
"Rats" : 15
```
### Git graph [experimental - live editor ]
### User Journey diagram [docs - live editor ]
```
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 3: Me
```
```mermaid
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 3: Me
```
### C4 diagram [docs ]
```
C4Context
title System Context diagram for Internet Banking System
Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
Person(customerB, "Banking Customer B")
Person_Ext(customerC, "Banking Customer C")
System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")
Person(customerD, "Banking Customer D", "A customer of the bank, with personal bank accounts.")
Enterprise_Boundary(b1, "BankBoundary") {
SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")
System_Boundary(b2, "BankBoundary2") {
System(SystemA, "Banking System A")
System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.")
}
System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.")
SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.")
Boundary(b3, "BankBoundary3", "boundary") {
SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.")
SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.")
}
}
BiRel(customerA, SystemAA, "Uses")
BiRel(SystemAA, SystemE, "Uses")
Rel(SystemAA, SystemC, "Sends e-mails", "SMTP")
Rel(SystemC, customerA, "Sends e-mails to")
```
```mermaid
C4Context
title System Context diagram for Internet Banking System
Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
Person(customerB, "Banking Customer B")
Person_Ext(customerC, "Banking Customer C")
System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.")
Person(customerD, "Banking Customer D", "A customer of the bank, with personal bank accounts.")
Enterprise_Boundary(b1, "BankBoundary") {
SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.")
System_Boundary(b2, "BankBoundary2") {
System(SystemA, "Banking System A")
System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts.")
}
System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.")
SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.")
Boundary(b3, "BankBoundary3", "boundary") {
SystemQueue(SystemF, "Banking System F Queue", "A system of the bank, with personal bank accounts.")
SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.")
}
}
BiRel(customerA, SystemAA, "Uses")
BiRel(SystemAA, SystemE, "Uses")
Rel(SystemAA, SystemC, "Sends e-mails", "SMTP")
Rel(SystemC, customerA, "Sends e-mails to")
```
## Release
For those who have the permission to do so:
Update version number in `package.json`.
```sh
npm publish
```
The above command generates files into the `dist` folder and publishes them to npmjs.org.
## Related projects
- [Command Line Interface](https://github.com/mermaid-js/mermaid-cli)
- [Live Editor](https://github.com/mermaid-js/mermaid-live-editor)
- [HTTP Server](https://github.com/TomWright/mermaid-server)
## Contributors [](https://github.com/mermaid-js/mermaid/issues?q=is%3Aissue+is%3Aopen+label%3A%22Good+first+issue%21%22) [](https://github.com/mermaid-js/mermaid/graphs/contributors) [](https://github.com/mermaid-js/mermaid/graphs/contributors)
Mermaid is a growing community and is always accepting new contributors. There's a lot of different ways to help out and we're always looking for extra hands! Look at [this issue](https://github.com/mermaid-js/mermaid/issues/866) if you want to know where to start helping out.
Detailed information about how to contribute can be found in the [contribution guide](CONTRIBUTING.md)
## Security and safe diagrams
For public sites, it can be precarious to retrieve text from users on the internet, storing that content for presentation in a browser at a later stage. The reason is that the user content can contain embedded malicious scripts that will run when the data is presented. For Mermaid this is a risk, specially as mermaid diagrams contain many characters that are used in html which makes the standard sanitation unusable as it also breaks the diagrams. We still make an effort to sanitise the incoming code and keep refining the process but it is hard to guarantee that there are no loop holes.
As an extra level of security for sites with external users we are happy to introduce a new security level in which the diagram is rendered in a sandboxed iframe preventing javascript in the code from being executed. This is a great step forward for better security.
_Unfortunately you can not have a cake and eat it at the same time which in this case means that some of the interactive functionality gets blocked along with the possible malicious code._
## Reporting vulnerabilities
To report a vulnerability, please e-mail security@mermaid.live with a description of the issue, the steps you took to create the issue, affected versions, and if known, mitigations for the issue.
## Appreciation
A quick note from Knut Sveidqvist:
> _Many thanks to the [d3](https://d3js.org/) and [dagre-d3](https://github.com/cpettitt/dagre-d3) projects for providing the graphical layout and drawing libraries!_
>
> _Thanks also to the [js-sequence-diagram](https://bramp.github.io/js-sequence-diagrams) project for usage of the grammar for the sequence diagrams. Thanks to Jessica Peter for inspiration and starting point for gantt rendering._
>
> _Thank you to [Tyler Long](https://github.com/tylerlong) who has been a collaborator since April 2017._
>
> _Thank you to the ever-growing list of [contributors](https://github.com/knsv/mermaid/graphs/contributors) that brought the project this far!_
---
_Mermaid was created by Knut Sveidqvist for easier documentation._
-----------
The following NPM package may be included in this product:
- metro-config@0.73.9
This package contains the following license and notice below:
# Metro Config
🚇 Config resolver and transformer for [Metro](https://facebook.github.io/metro/).
-----------
The following NPM package may be included in this product:
- metro-core@0.73.9
This package contains the following license and notice below:
# Metro
🚇 This package contains core files for [Metro](https://facebook.github.io/metro/).
(TODO)
-----------
The following NPM package may be included in this product:
- metro-file-map@0.73.9
This package contains the following license and notice below:
# \[Experimental\] Metro File Map
🚇 File system crawling, watching and mapping for [Metro](https://facebook.github.io/metro/).
Originally a fork of [`jest-haste-map`](https://github.com/facebook/jest/tree/main/packages/jest-haste-map).
This entire package should be considered "experimental" for the time being -
the API is considered internal and changes will not be semver-breaking.
If you need to rely on `metro-file-map` APIs directly please
[raise an issue](https://github.com/facebook/metro/issues/new) to discuss your
use case.
-----------
The following NPM package may be included in this product:
- metro-hermes-compiler@0.73.9
This package contains the following license and notice below:
# Metro Hermes Compiler
This experimental module provides a high-level API to work with the Hermes bytecode compiler (HBC). HBC is integrated as a WASM binary generated by the emscripten toolchain and checked in as part of this package.
## How to build HBC
A pre-configured emscripten environment can be used through this [Docker image](https://hub.docker.com/r/trzeci/emscripten/). Docker can be installed via its [desktop app](https://docs.docker.com/docker-for-mac/). Make sure to increase resource limits (16G RAM, as much CPU as possible).
```
cd path/to/hermes/checkout
docker run -i -t --rm -v `pwd`:`pwd` trzeci/emscripten bash
apt-get update -y && apt-get install -y icu-devtools
cd path/to/hermes/checkout
cmake . -DCMAKE_TOOLCHAIN_FILE=/emsdk_portable/emscripten/sdk/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_BUILD_TYPE=Release
make -j emhermesc
```
After the build process finishes the Hermes Bytecode Compiler JavaScript file will be available in the `bin` folder.
-----------
The following NPM package may be included in this product:
- metro-react-native-babel-preset@0.73.9
This package contains the following license and notice below:
# metro-react-native-babel-preset
Babel presets for [React Native](https://reactnative.dev) applications. React Native itself uses this Babel preset by default when transforming your app's source code.
If you wish to use a custom Babel configuration by writing a `babel.config.js` file in your project's root directory, you must specify all the plugins necessary to transform your code. React Native does not apply its default Babel configuration in this case. So, to make your life easier, you can use this preset to get the default configuration and then specify more plugins that run before it.
## Usage
As mentioned above, you only need to use this preset if you are writing a custom `babel.config.js` file.
### Installation
Install `metro-react-native-babel-preset` in your app:
with `npm`:
```sh
npm i metro-react-native-babel-preset --save-dev
```
or with `yarn`:
```sh
yarn add -D metro-react-native-babel-preset
```
### Configuring Babel
Then, create a file called `babel.config.js` in your project's root directory. The existence of this `babel.config.js` file will tell React Native to use your custom Babel configuration instead of its own. Then load this preset:
```
{
"presets": ["module:metro-react-native-babel-preset"]
}
```
You can further customize your Babel configuration by specifying plugins and other options. See [Babel's `babel.config.js` documentation](https://babeljs.io/docs/en/config-files/) to learn more.
## Help and Support
If you get stuck configuring Babel, please ask a question on Stack Overflow or find a consultant for help. If you discover a bug, please open up an issue.
-----------
The following NPM package may be included in this product:
- metro-resolver@0.73.9
This package contains the following license and notice below:
# metro-resolver
🚇 [Metro](https://facebook.github.io/metro/) resolution logic
-----------
The following NPM package may be included in this product:
- metro-source-map@0.73.9
This package contains the following license and notice below:
# Metro
🚇 The source map generator for [Metro](https://facebook.github.io/metro/).
(TODO)
-----------
The following NPM package may be included in this product:
- metro@0.73.9
This package contains the following license and notice below:
# Metro
🚇 The JavaScript bundler for React Native.
- **🚅 Fast**: We aim for sub-second reload cycles, fast startup and quick bundling speeds.
- **⚖️ Scalable**: Works with thousands of modules in a single application.
- **⚛️ Integrated**: Supports every React Native project out of the box.
This project was previously part of the [react-native](https://github.com/facebook/react-native) repository. In this smaller repository it is easier for the team working on Metro to respond to both issues and pull requests. See [react-native#13976](https://github.com/facebook/react-native/issues/13976) for the initial announcement.
-----------
The following NPM package may be included in this product:
- mgrs@1.0.0
This package contains the following license and notice below:
Copyright (c) 2012, Mike Adair, Richard Greenwood, Didier Richard, Stephen Irons, Olivier Terral, Calvin Metcalf
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
_THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE._
-----------
The following NPM package may be included in this product:
- micromark-core-commonmark@1.0.6
This package contains the following license and notice below:
# micromark-core-commonmark
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
The core CommonMark constructs needed to tokenize markdown.
Some of these can be [turned off][disable], but they are often essential to
markdown and weird things might happen.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-core-commonmark
```
## Use
```js
import {autolink} from 'micromark-core-commonmark'
console.log(autolink) // Do things with `autolink`.
```
## API
This module exports the following identifiers: `attention`, `autolink`,
`blankLine`, `blockQuote`, `characterEscape`, `characterReference`,
`codeFenced`, `codeIndented`, `codeText`, `content`, `definition`,
`hardBreakEscape`, `headingAtx`, `htmlFlow`, `htmlText`, `labelEnd`,
`labelStartImage`, `labelStartLink`, `lineEnding`, `list`, `setextUnderline`,
`thematicBreak`.
There is no default export.
Each identifier refers to a [construct](https://github.com/micromark/micromark#constructs).
See the code for more on the exported constructs.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-core-commonmark.svg
[downloads]: https://www.npmjs.com/package/micromark-core-commonmark
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-core-commonmark.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-core-commonmark
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[disable]: https://github.com/micromark/micromark#case-turn-off-constructs
-----------
The following NPM package may be included in this product:
- micromark-factory-destination@1.0.0
This package contains the following license and notice below:
# micromark-factory-destination
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark factory to parse destinations (found in resources, definitions).
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`factoryDestination(…)`](#factorydestination)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-factory-destination
```
## Use
```js
import {factoryDestination} from 'micromark-factory-destination'
import {codes} from 'micromark-util-symbol/codes'
import {types} from 'micromark-util-symbol/types'
// A micromark tokenizer that uses the factory:
/** @type {Tokenizer} */
function tokenizeResource(effects, ok, nok) {
return start
// …
/** @type {State} */
function open(code) {
if (code === codes.rightParenthesis) {
return end(code)
}
return factoryDestination(
effects,
destinationAfter,
nok,
types.resourceDestination,
types.resourceDestinationLiteral,
types.resourceDestinationLiteralMarker,
types.resourceDestinationRaw,
types.resourceDestinationString,
constants.linkResourceDestinationBalanceMax
)(code)
}
// …
}
```
## API
This module exports the following identifiers: `factoryDestination`.
There is no default export.
### `factoryDestination(…)`
###### Parameters
* `effects` (`Effects`) — Context
* `ok` (`State`) — State switched to when successful
* `nok` (`State`) — State switched to when not successful
* `type` (`string`) — Token type for whole (`` or `b`)
* `literalType` (`string`) — Token type when enclosed (` `)
* `literalMarkerType` (`string`) — Token type for enclosing (`<` and `>`)
* `rawType` (`string`) — Token type when not enclosed (`b`)
* `stringType` (`string`) — Token type for the URI (`a` or `b`)
* `max` (`number`, default: `Infinity`) — Max depth of nested parens
###### Returns
`State`.
###### Examples
```markdown
b>
a
a\)b
a(b)c
a(b)
```
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-factory-destination.svg
[downloads]: https://www.npmjs.com/package/micromark-factory-destination
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-factory-destination.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-factory-destination
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-factory-label@1.0.2
This package contains the following license and notice below:
# micromark-factory-label
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark factory to parse labels (found in media, definitions).
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`factoryLabel(…)`](#factorylabel)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-factory-label
```
## Use
```js
import {ok as assert} from 'uvu/assert'
import {factoryLabel} from 'micromark-factory-label'
import {codes} from 'micromark-util-symbol/codes'
import {types} from 'micromark-util-symbol/types'
// A micromark tokenizer that uses the factory:
/** @type {Tokenizer} */
function tokenizeDefinition(effects, ok, nok) {
return start
// …
/** @type {State} */
function start(code) {
assert(code === codes.leftSquareBracket, 'expected `[`')
effects.enter(types.definition)
return factoryLabel.call(
self,
effects,
labelAfter,
nok,
types.definitionLabel,
types.definitionLabelMarker,
types.definitionLabelString
)(code)
}
// …
}
```
## API
This module exports the following identifiers: `factoryLabel`.
There is no default export.
### `factoryLabel(…)`
Note that labels in markdown are capped at 999 characters in the string.
###### Parameters
* `this` (`TokenizeContext`) — Tokenize context
* `effects` (`Effects`) — Context
* `ok` (`State`) — State switched to when successful
* `nok` (`State`) — State switched to when not successful
* `type` (`string`) — Token type for whole (`[a]`)
* `markerType` (`string`) — Token type for the markers (`[` and `]`)
* `stringType` (`string`) — Token type for the identifier (`a`)
###### Returns
`State`.
###### Examples
```markdown
[a]
[a
b]
[a\]b]
```
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-factory-label.svg
[downloads]: https://www.npmjs.com/package/micromark-factory-label
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-factory-label.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-factory-label
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-factory-space@1.0.0
This package contains the following license and notice below:
# micromark-factory-space
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark factory to parse [markdown space][markdown-space] (found in lots of
places).
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`factorySpace(…)`](#factoryspace)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-factory-space
```
## Use
```js
import {factorySpace} from 'micromark-factory-space'
import {codes} from 'micromark-util-symbol/codes'
import {types} from 'micromark-util-symbol/types'
// A micromark tokenizer that uses the factory:
/** @type {Tokenizer} */
function tokenizeCodeFenced(effects, ok, nok) {
return start
// …
/** @type {State} */
function info(code) {
if (code === codes.eof || markdownLineEndingOrSpace(code)) {
effects.exit(types.chunkString)
effects.exit(types.codeFencedFenceInfo)
return factorySpace(effects, infoAfter, types.whitespace)(code)
}
if (code === codes.graveAccent && code === marker) return nok(code)
effects.consume(code)
return info
}
// …
}
```
## API
This module exports the following identifiers: `factorySpace`.
There is no default export.
### `factorySpace(…)`
Note that there is no `nok` parameter:
* spaces in markdown are often optional, in which case this factory can be
used and `ok` will be switched to whether spaces were found or not,
* One space character can be detected with
[markdownSpace(code)][markdown-space] right before using `factorySpace`
###### Parameters
* `effects` (`Effects`) — Context
* `ok` (`State`) — State switched to when successful
* `type` (`string`) — Token type for whole (`' \t'`)
* `max` (`number`, default: `Infinity`) — Max size of whitespace
###### Returns
`State`.
###### Examples
Where `␉` represents a tab (plus how much it expands) and `␠` represents a
single space.
```markdown
␉
␠␠␠␠
␉␠
```
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-factory-space.svg
[downloads]: https://www.npmjs.com/package/micromark-factory-space
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-factory-space.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-factory-space
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[markdown-space]: https://github.com/micromark/micromark/tree/main/packages/micromark-util-character#markdownspacecode
-----------
The following NPM package may be included in this product:
- micromark-factory-title@1.0.2
This package contains the following license and notice below:
# micromark-factory-title
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark factory to parse markdown titles (found in resources, definitions).
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`factoryTitle(…)`](#factorytitle)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-factory-title
```
## Use
```js
import {factoryTitle} from 'micromark-factory-title'
import {codes} from 'micromark-util-symbol/codes'
import {types} from 'micromark-util-symbol/types'
// A micromark tokenizer that uses the factory:
/** @type {Tokenizer} */
function tokenizeDefinition(effects, ok, nok) {
return start
// …
/** @type {State} */
function before(code) {
if (
code === codes.quotationMark ||
code === codes.apostrophe ||
code === codes.leftParenthesis
) {
return factoryTitle(
effects,
factorySpace(effects, after, types.whitespace),
nok,
types.definitionTitle,
types.definitionTitleMarker,
types.definitionTitleString
)(code)
}
return nok(code)
}
// …
}
```
## API
This module exports the following identifiers: `factoryTitle`.
There is no default export.
### `factoryTitle(…)`
###### Parameters
* `effects` (`Effects`) — Context
* `ok` (`State`) — State switched to when successful
* `nok` (`State`) — State switched to when not successful
* `type` (`string`) — Token type for whole (`"a"`, `'b'`, `(c)`)
* `markerType` (`string`) — Token type for the markers (`"`, `'`, `(`, and
`)`)
* `stringType` (`string`) — Token type for the value (`a`)
###### Returns
`State`.
###### Examples
```markdown
"a"
'b'
(c)
"a
b"
'a
b'
(a\)b)
```
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-factory-title.svg
[downloads]: https://www.npmjs.com/package/micromark-factory-title
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-factory-title.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-factory-title
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-factory-whitespace@1.0.0
This package contains the following license and notice below:
# micromark-factory-whitespace
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark factory to parse [markdown line endings or spaces][ws] (found in lots
of places).
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`factoryWhitespace(…)`](#factorywhitespace)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-factory-whitespace
```
## Use
```js
import {factoryWhitespace} from 'micromark-factory-whitespace'
import {codes} from 'micromark-util-symbol/codes'
import {types} from 'micromark-util-symbol/types'
// A micromark tokenizer that uses the factory:
/** @type {Tokenizer} */
function tokenizeTitle(effects, ok, nok) {
return start
/** @type {State} */
function start(code) {
return markdownLineEndingOrSpace(code)
? factoryWhitespace(effects, before)(code)
: nok(code)
}
// …
}
```
## API
This module exports the following identifiers: `factoryWhitespace`.
There is no default export.
### `factoryWhitespace(…)`
Note that there is no `nok` parameter:
* line endings or spaces in markdown are often optional, in which case this
factory can be used and `ok` will be switched to whether spaces were found
or not,
* One line ending or space can be detected with
[markdownLineEndingOrSpace(code)][ws] right before using `factoryWhitespace`
###### Parameters
* `effects` (`Effects`) — Context
* `ok` (`State`) — State switched to when successful
###### Returns
`State`.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-factory-whitespace.svg
[downloads]: https://www.npmjs.com/package/micromark-factory-whitespace
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-factory-whitespace.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-factory-whitespace
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[ws]: https://github.com/micromark/micromark/tree/main/packages/micromark-util-character#markdownlineendingorspacecode
-----------
The following NPM package may be included in this product:
- micromark-util-character@1.1.0
This package contains the following license and notice below:
# micromark-util-character
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to handle [character codes](https://github.com/micromark/micromark#preprocess).
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`asciiAlpha(code)`](#asciialphacode)
* [`asciiDigit(code)`](#asciidigitcode)
* [`asciiHexDigit(code)`](#asciihexdigitcode)
* [`asciiAlphanumeric(code)`](#asciialphanumericcode)
* [`asciiPunctuation(code)`](#asciipunctuationcode)
* [`asciiAtext(code)`](#asciiatextcode)
* [`asciiControl(code)`](#asciicontrolcode)
* [`markdownLineEndingOrSpace(code)`](#markdownlineendingorspacecode)
* [`markdownLineEnding(code)`](#markdownlineendingcode)
* [`markdownSpace(code)`](#markdownspacecode)
* [`unicodeWhitespace(code)`](#unicodewhitespacecode)
* [`unicodePunctuation(code)`](#unicodepunctuationcode)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-character
```
## Use
```js
import {asciiAlpha} from 'micromark-util-character'
console.log(asciiAlpha(64)) // false
console.log(asciiAlpha(65)) // true
```
## API
This module exports the following identifiers: `asciiAlpha`,
`asciiAlphanumeric`, `asciiAtext`, `asciiControl`, `asciiDigit`,
`asciiHexDigit`, `asciiPunctuation`, `markdownLineEnding`,
`markdownLineEndingOrSpace`, `markdownSpace`, `unicodePunctuation`,
`unicodeWhitespace`.
There is no default export.
### `asciiAlpha(code)`
Check whether the
[character code](https://github.com/micromark/micromark#preprocess)
represents an ASCII alpha (`a` through `z`,
case insensitive).
An **ASCII alpha** is an ASCII upper alpha or ASCII lower alpha.
An **ASCII upper alpha** is a character in the inclusive range U+0041 (`A`)
to U+005A (`Z`).
An **ASCII lower alpha** is a character in the inclusive range U+0061 (`a`)
to U+007A (`z`).
### `asciiDigit(code)`
Check whether the
[character code](https://github.com/micromark/micromark#preprocess)
represents an ASCII digit (`0` through `9`).
An **ASCII digit** is a character in the inclusive range U+0030 (`0`) to
U+0039 (`9`).
### `asciiHexDigit(code)`
Check whether the
[character code](https://github.com/micromark/micromark#preprocess)
represents an ASCII hex digit (`a` through `f`, case insensitive, or `0` through
`9`).
An **ASCII hex digit** is an ASCII digit (see `asciiDigit`), ASCII upper hex
digit, or an ASCII lower hex digit.
An **ASCII upper hex digit** is a character in the inclusive range U+0041
(`A`) to U+0046 (`F`).
An **ASCII lower hex digit** is a character in the inclusive range U+0061
(`a`) to U+0066 (`f`).
### `asciiAlphanumeric(code)`
Check whether the
[character code](https://github.com/micromark/micromark#preprocess)
represents an ASCII alphanumeric (`a` through `z`, case insensitive, or `0`
through `9`).
An **ASCII alphanumeric** is an ASCII digit (see `asciiDigit`) or ASCII alpha
(see `asciiAlpha`).
### `asciiPunctuation(code)`
Check whether the
[character code](https://github.com/micromark/micromark#preprocess)
represents ASCII punctuation.
An **ASCII punctuation** is a character in the inclusive ranges U+0021
EXCLAMATION MARK (`!`) to U+002F SLASH (`/`), U+003A COLON (`:`) to U+0040 AT
SIGN (`@`), U+005B LEFT SQUARE BRACKET (`[`) to U+0060 GRAVE ACCENT
(`` ` ``), or U+007B LEFT CURLY BRACE (`{`) to U+007E TILDE (`~`).
### `asciiAtext(code)`
Check whether the
[character code](https://github.com/micromark/micromark#preprocess)
represents an ASCII atext.
atext is an ASCII alphanumeric (see `asciiAlphanumeric`), or a character in
the inclusive ranges U+0023 NUMBER SIGN (`#`) to U+0027 APOSTROPHE (`'`),
U+002A ASTERISK (`*`), U+002B PLUS SIGN (`+`), U+002D DASH (`-`), U+002F
SLASH (`/`), U+003D EQUALS TO (`=`), U+003F QUESTION MARK (`?`), U+005E
CARET (`^`) to U+0060 GRAVE ACCENT (`` ` ``), or U+007B LEFT CURLY BRACE
(`{`) to U+007E TILDE (`~`) (**\[RFC5322]**).
See **\[RFC5322]**:\
[Internet Message Format](https://tools.ietf.org/html/rfc5322).\
P. Resnick.\
IETF.
### `asciiControl(code)`
Check whether a
[character code](https://github.com/micromark/micromark#preprocess)
is an ASCII control character.
An **ASCII control** is a character in the inclusive range U+0000 NULL (NUL)
to U+001F (US), or U+007F (DEL).
### `markdownLineEndingOrSpace(code)`
Check whether a
[character code](https://github.com/micromark/micromark#preprocess)
is a markdown line ending (see `markdownLineEnding`) or markdown space (see
`markdownSpace`).
### `markdownLineEnding(code)`
Check whether a
[character code](https://github.com/micromark/micromark#preprocess)
is a markdown line ending.
A **markdown line ending** is the virtual characters M-0003 CARRIAGE RETURN
LINE FEED (CRLF), M-0004 LINE FEED (LF) and M-0005 CARRIAGE RETURN (CR).
In micromark, the actual character U+000A LINE FEED (LF) and U+000D CARRIAGE
RETURN (CR) are replaced by these virtual characters depending on whether
they occurred together.
### `markdownSpace(code)`
Check whether a
[character code](https://github.com/micromark/micromark#preprocess)
is a markdown space.
A **markdown space** is the concrete character U+0020 SPACE (SP) and the
virtual characters M-0001 VIRTUAL SPACE (VS) and M-0002 HORIZONTAL TAB (HT).
In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is
replaced by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL
SPACE (VS) characters, depending on the column at which the tab occurred.
### `unicodeWhitespace(code)`
Check whether the
[character code](https://github.com/micromark/micromark#preprocess)
represents Unicode whitespace.
Note that this does handle micromark specific markdown whitespace characters.
See `markdownLineEndingOrSpace` to check that.
A **Unicode whitespace** is a character in the Unicode `Zs` (Separator,
Space) category, or U+0009 CHARACTER TABULATION (HT), U+000A LINE FEED (LF),
U+000C (FF), or U+000D CARRIAGE RETURN (CR) (**\[UNICODE]**).
See **\[UNICODE]**:\
[The Unicode Standard](https://www.unicode.org/versions/).\
Unicode Consortium.
### `unicodePunctuation(code)`
Check whether the
[character code](https://github.com/micromark/micromark#preprocess)
represents Unicode punctuation.
A **Unicode punctuation** is a character in the Unicode `Pc` (Punctuation,
Connector), `Pd` (Punctuation, Dash), `Pe` (Punctuation, Close), `Pf`
(Punctuation, Final quote), `Pi` (Punctuation, Initial quote), `Po`
(Punctuation, Other), or `Ps` (Punctuation, Open) categories, or an ASCII
punctuation (see `asciiPunctuation`) (**\[UNICODE]**).
See **\[UNICODE]**:\
[The Unicode Standard](https://www.unicode.org/versions/).\
Unicode Consortium.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-character.svg
[downloads]: https://www.npmjs.com/package/micromark-util-character
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-character.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-character
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-chunked@1.0.0
This package contains the following license and notice below:
# micromark-util-chunked
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to splice and push with giant arrays.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`push(list, items)`](#pushlist-items)
* [`splice(list, start, remove, items)`](#splicelist-start-remove-items)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-chunked
```
## Use
```js
import {push, splice} from 'micromark-util-chunked'
// …
nextEvents = push(nextEvents, [
['enter', events[open][1], context],
['exit', events[open][1], context]
])
// …
splice(events, open - 1, index - open + 3, nextEvents)
// …
```
## API
This module exports the following identifiers: `push`, `splice`.
There is no default export.
### `push(list, items)`
Append `items` (an array) at the end of `list` (another array).
When `list` was empty, returns `items` instead.
This prevents a potentially expensive operation when `list` is empty,
and adds items in batches to prevent V8 from hanging.
###### Parameters
* `list` (`unknown[]`) — List to operate on
* `items` (`unknown[]`) — Items to add to `list`
###### Returns
`list` or `items`
### `splice(list, start, remove, items)`
Like `Array#splice`, but smarter for giant arrays.
`Array#splice` takes all items to be inserted as individual argument which
causes a stack overflow in V8 when trying to insert 100k items for instance.
Otherwise, this does not return the removed items, and takes `items` as an
array instead of rest parameters.
###### Parameters
* `list` (`unknown[]`) — List to operate on
* `start` (`number`) — Index to remove/insert at (can be negative)
* `remove` (`number`) — Number of items to remove
* `items` (`unknown[]`) — Items to inject into `list`
###### Returns
`void`
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-chunked.svg
[downloads]: https://www.npmjs.com/package/micromark-util-chunked
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-chunked.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-chunked
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-classify-character@1.0.0
This package contains the following license and notice below:
# micromark-util-classify-character
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to classify whether a character is whitespace or punctuation.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`classifyCharacter(code)`](#classifycharactercode)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-classify-character
```
## Use
```js
/** @type {Tokenizer} */
function tokenizeAttention(effects, ok) {
return start
// …
/** @type {State} */
function sequence(code) {
if (code === marker) {
// …
}
const token = effects.exit('attentionSequence')
const after = classifyCharacter(code)
const open =
!after || (after === constants.characterGroupPunctuation && before)
const close =
!before || (before === constants.characterGroupPunctuation && after)
// …
}
// …
}
```
## API
This module exports the following identifiers: `classifyCharacter`.
There is no default export.
### `classifyCharacter(code)`
Classify whether a
[character code](https://github.com/micromark/micromark#preprocess)
represents whitespace, punctuation, or
something else.
Used for attention (emphasis, strong), whose sequences can open or close based
on the class of surrounding characters.
Note that eof (`null`) is seen as whitespace.
###### Returns
`constants.characterGroupWhitespace`, `constants.characterGroupPunctuation`,
or `undefined.`
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-classify-character.svg
[downloads]: https://www.npmjs.com/package/micromark-util-classify-character
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-classify-character.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-classify-character
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-combine-extensions@1.0.0
This package contains the following license and notice below:
# micromark-util-combine-extensions
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to combine [syntax][] or [html][] extensions.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`combineExtensions(extensions)`](#combineextensionsextensions)
* [`combineHtmlExtensions(htmlExtensions)`](#combinehtmlextensionshtmlextensions)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-combine-extensions
```
## Use
```js
import {gfmAutolinkLiteral} from 'micromark-extension-gfm-autolink-literal'
import {gfmStrikethrough} from 'micromark-extension-gfm-strikethrough'
import {gfmTable} from 'micromark-extension-gfm-table'
import {gfmTaskListItem} from 'micromark-extension-gfm-task-list-item'
import {combineExtensions} from 'micromark-util-combine-extensions'
const gfm = combineExtensions([gfmAutolinkLiteral, gfmStrikethrough(), gfmTable, gfmTaskListItem])
```
## API
This module exports the following identifiers: `combineExtensions`,
`combineHtmlExtensions`.
There is no default export.
### `combineExtensions(extensions)`
Combine several syntax extensions into one.
###### Parameters
* `extensions` (`Extension[]`) — List of syntax extensions
###### Returns
A single combined extension (`Extension`).
### `combineHtmlExtensions(htmlExtensions)`
Combine several html extensions into one.
###### Parameters
* `htmlExtensions` (`HtmlExtension[]`) — List of html extensions
###### Returns
A single combined html extension (`HtmlExtension`).
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-combine-extensions.svg
[downloads]: https://www.npmjs.com/package/micromark-util-combine-extensions
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-combine-extensions.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-combine-extensions
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[syntax]: https://github.com/micromark/micromark#syntaxextension
[html]: https://github.com/micromark/micromark#htmlextension
-----------
The following NPM package may be included in this product:
- micromark-util-decode-numeric-character-reference@1.0.0
This package contains the following license and notice below:
# micromark-util-decode-numeric-character-reference
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to decode numeric character references.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`decodeNumericCharacterReference(value)`](#decodenumericcharacterreferencevalue)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-decode-numeric-character-reference
```
## Use
```js
import {decodeNumericCharacterReference} from 'micromark-util-decode-numeric-character-reference'
decodeNumericCharacterReference('41', 16) // 'A'
decodeNumericCharacterReference('65', 10) // 'A'
decodeNumericCharacterReference('A', 16) // '\n'
decodeNumericCharacterReference('7F', 16) // '�' - Control
decodeNumericCharacterReference('110000', 16) // '�' - Out of range
```
## API
This module exports the following identifiers:
`decodeNumericCharacterReference`.
There is no default export.
### `decodeNumericCharacterReference(value)`
Sort of like `String.fromCharCode(Number.parseInt(value, base))`,
but makes non-characters and control characters safe.
###### Parameters
* `value` (`string`) — Value to decode.
* `base` (`number`, probably `10` or `16`) — Numeric base.
###### Returns
`string` — Character code.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-normalize-identifier.svg
[downloads]: https://www.npmjs.com/package/micromark-util-normalize-identifier
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-normalize-identifier.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-normalize-identifier
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-decode-string@1.0.2
This package contains the following license and notice below:
# micromark-util-decode-string
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to decode markdown strings.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`decodeString(value)`](#decodestringvalue)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-decode-string
```
## Use
```js
import {decodeString} from 'micromark-util-decode-string'
decodeString('a ; b') // 'a ; b'
decodeString('a \\; b') // 'a ; b'
decodeString('a ; b') // 'a ; b'
```
## API
This module exports the following identifiers: `decodeString`.
There is no default export.
### `decodeString(value)`
micromark utility to decode markdown strings (which occur in places such as
fenced code info strings, destinations, labels, and titles).
The “string” content type allows character escapes and -references.
This decodes those.
###### Parameters
* `value` (`string`) — Value to decode.
###### Returns
`string` — Decoded value.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-normalize-identifier.svg
[downloads]: https://www.npmjs.com/package/micromark-util-normalize-identifier
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-normalize-identifier.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-normalize-identifier
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-encode@1.0.1
This package contains the following license and notice below:
# micromark-util-encode
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to encode dangerous html characters.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`encode(value)`](#encodevalue)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-encode
```
## Use
```js
import {encode} from 'micromark-util-encode'
encode('<3') // '<3'
```
## API
This module exports the following identifiers: `encode`.
There is no default export.
### `encode(value)`
Encode only the dangerous HTML characters.
This ensures that certain characters which have special meaning in HTML are
dealt with.
Technically, we can skip `>` and `"` in many cases, but CM includes them.
###### Parameters
* `value` (`string`) — Value to encode.
###### Returns
`string` — Encoded value.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-encode.svg
[downloads]: https://www.npmjs.com/package/micromark-util-encode
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-encode.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-encode
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-html-tag-name@1.1.0
This package contains the following license and notice below:
# micromark-util-html-tag-name
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility with list of html tag names.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`htmlBlockNames`](#htmlblocknames)
* [`htmlRawNames`](#htmlrawnames)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
```sh
npm install micromark-util-html-tag-name
```
In Deno with [`esm.sh`][esmsh]:
```js
import {htmlBlockNames, htmlRawNames} from 'https://esm.sh/micromark-util-html-tag-name@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
```
## Use
```js
import {htmlBlockNames, htmlRawNames} from 'micromark-util-html-tag-name'
console.log(htmlBlockNames) // ['address', 'article', …]
console.log(htmlRawNames) // ['pre', 'script', …]
```
## API
This module exports the following identifiers: `htmlBlockNames`,
`htmlRawNames`.
There is no default export.
### `htmlBlockNames`
List of lowercase HTML tag names (`Array`) which when parsing HTML
(flow), result in more relaxed rules (condition 6): because they are known
blocks, the HTML-like syntax doesn’t have to be strictly parsed.
For tag names not in this list, a more strict algorithm (condition 7) is used
to detect whether the HTML-like syntax is seen as HTML (flow) or not.
This is copied from: .
### `htmlRawNames`
List of lowercase HTML tag names (`Array`) which when parsing HTML
(flow), result in HTML that can include lines w/o exiting, until a closing tag
also in this list is found (condition 1).
This is copied from:
.
Note that `textarea` was added in `CommonMark@0.30`.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-html-tag-name.svg
[downloads]: https://www.npmjs.com/package/micromark-util-html-tag-name
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-html-tag-name.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-html-tag-name
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-normalize-identifier@1.0.0
This package contains the following license and notice below:
# micromark-util-normalize-identifier
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility normalize identifiers (as found in references, definitions).
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`normalizeIdentifier(value)`](#normalizeidentifiervalue)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-normalize-identifier
```
## Use
```js
import {normalizeIdentifier} from 'micromark-util-normalize-identifier'
normalizeIdentifier(' a ') // 'A'
normalizeIdentifier('a\t\r\nb') // 'A B'
normalizeIdentifier('ТОЛПОЙ') // 'ТОЛПОЙ'
normalizeIdentifier('Толпой') // 'ТОЛПОЙ'
```
## API
This module exports the following identifiers: `normalizeIdentifier`.
There is no default export.
### `normalizeIdentifier(value)`
Normalize an identifier (such as used in definitions).
Collapse Markdown whitespace, trim, and then lower- and uppercase.
Some characters are considered “uppercase”, such as U+03F4 (`ϴ`), but if their
lowercase counterpart (U+03B8 (`θ`)) is uppercased will result in a different
uppercase character (U+0398 (`Θ`)).
Hence, to get that form, we perform both lower- and uppercase.
Using uppercase last makes sure keys will not interact with default prototypal
methods: no method is uppercase.
###### Parameters
* `value` (`string`) — Identifier to normalize.
###### Returns
`string` — Normalized value.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-normalize-identifier.svg
[downloads]: https://www.npmjs.com/package/micromark-util-normalize-identifier
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-normalize-identifier.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-normalize-identifier
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-resolve-all@1.0.0
This package contains the following license and notice below:
# micromark-util-resolve-all
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to resolve subtokens.
[Resolvers][resolver] are functions that take events and manipulate them.
This is needed for example because media (links, images) and attention (strong,
italic) aren’t parsed left-to-right.
Instead, their openings and closings are parsed, and when done, their openings
and closings are matched, and left overs are turned into plain text.
Because media and attention can’t overlap, we need to perform that operation
when one closing matches an opening, too.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`resolveAll(constructs, events, context)`](#resolveallconstructs-events-context)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-resolve-all
```
## Use
```js
import {push} from 'micromark-util-chunked'
import {resolveAll} from 'micromark-util-resolve-all'
/**
* @type {Resolver}
*/
function resolveAllAttention(events, context) {
// …
// Walk through all events.
while (++index < events.length) {
// Find a token that can close.
if (
events[index][0] === 'enter' &&
events[index][1].type === 'attentionSequence' &&
events[index][1]._close
) {
open = index
// Now walk back to find an opener.
while (open--) {
// Find a token that can open the closer.
if (
// …
) {
// …
// Opening.
nextEvents = push(nextEvents, [
// …
])
// Between.
nextEvents = push(
nextEvents,
resolveAll(
context.parser.constructs.insideSpan.null,
events.slice(open + 1, index),
context
)
)
// Closing.
nextEvents = push(nextEvents, [
// …
])
// …
}
}
}
}
// …
}
```
## API
This module exports the following identifiers: `resolveAll`.
There is no default export.
### `resolveAll(constructs, events, context)`
Call all `resolveAll`s in `constructs`.
###### Parameters
* `constructs` (`Construct[]`) — List of constructs, optionally with
`resolveAll`s
* `events` (`Event[]`) — List of events
* `context` (`TokenizeContext`) — Context used by `tokenize`
###### Returns
`Events[]` — Changed events.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-resolve-all.svg
[downloads]: https://www.npmjs.com/package/micromark-util-resolve-all
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-resolve-all.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-resolve-all
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[resolver]: https://github.com/micromark/micromark/blob/a571c09/packages/micromark-util-types/index.js#L219
-----------
The following NPM package may be included in this product:
- micromark-util-sanitize-uri@1.1.0
This package contains the following license and notice below:
# micromark-util-sanitize-uri
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to sanitize urls.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`sanitizeUri(url[, pattern])`](#sanitizeuriurl-pattern)
* [`normalizeUri(url[, pattern])`](#normalizeuriurl-pattern)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
```sh
npm install micromark-util-sanitize-uri
```
In Deno with [`esm.sh`][esmsh]:
```js
import {sanitizeUri} from 'https://esm.sh/micromark-util-sanitize-uri@1'
```
In browsers with [`esm.sh`][esmsh]:
```html
```
## Use
```js
import {sanitizeUri} from 'micromark-util-sanitize-uri'
sanitizeUri('https://example.com/a&b') // 'https://example.com/a&b'
sanitizeUri('https://example.com/a%b') // 'https://example.com/a%25b'
sanitizeUri('https://example.com/a%20b') // 'https://example.com/a%20b'
sanitizeUri('https://example.com/👍') // 'https://example.com/%F0%9F%91%8D'
sanitizeUri('https://example.com/', /^https?$/i) // 'https://example.com/'
sanitizeUri('javascript:alert(1)', /^https?$/i) // ''
sanitizeUri('./example.jpg', /^https?$/i) // './example.jpg'
sanitizeUri('#a', /^https?$/i) // '#a'
```
## API
This module exports the following identifiers: `sanitizeUri`.
There is no default export.
### `sanitizeUri(url[, pattern])`
Make a value safe for injection as a URL.
This encodes unsafe characters with percent-encoding and skips already
encoded sequences (see `normalizeUri` internally).
Further unsafe characters are encoded as character references (see
`micromark-util-encode`).
A regex of allowed protocols can be given, in which case the URL is sanitized.
For example, `/^(https?|ircs?|mailto|xmpp)$/i` can be used for `a[href]`, or
`/^https?$/i` for `img[src]` (this is what `github.com` allows).
If the URL includes an unknown protocol (one not matched by `protocol`, such
as a dangerous example, `javascript:`), the value is ignored.
###### Parameters
* `url` (`string`) — URI to sanitize.
* `pattern` (`RegExp`, optional) — Allowed protocols.
###### Returns
`string` — Sanitized URI.
### `normalizeUri(url[, pattern])`
Normalize a URL (such as used in definitions).
Encode unsafe characters with percent-encoding, skipping already encoded
sequences.
###### Parameters
* `url` (`string`) — URI to normalize.
###### Returns
`string` — Normalized URI.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-sanitize-uri.svg
[downloads]: https://www.npmjs.com/package/micromark-util-sanitize-uri
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-sanitize-uri.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-sanitize-uri
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-subtokenize@1.0.2
This package contains the following license and notice below:
# micromark-util-subtokenize
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility to tokenize subtokens.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`subtokenize(events)`](#subtokenizeevents)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-subtokenize
```
## Use
```js
import {subtokenize} from 'micromark-util-subtokenize'
/**
* Content is transparent: it’s parsed right now. That way, definitions are also
* parsed right now: before text in paragraphs (specifically, media) are parsed.
*
* @type {Resolver}
*/
function resolveContent(events) {
subtokenize(events)
return events
}
```
## API
This module exports the following identifiers: `subtokenize`.
There is no default export.
### `subtokenize(events)`
Tokenize subcontent.
###### Parameters
* `events` (`Event[]`) — List of events
###### Returns
`boolean` — Whether subtokens were found.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-subtokenize.svg
[downloads]: https://www.npmjs.com/package/micromark-util-subtokenize
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-subtokenize.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-subtokenize
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark-util-symbol@1.0.1
This package contains the following license and notice below:
# micromark-util-symbol
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility with symbols.
It’s useful to reference these by name instead of value while developing.
[`micromark-build`][micromark-build] compiles them away for production code.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-symbol
```
## Use
```js
import {codes} from 'micromark-util-symbol/codes'
import {constants} from 'micromark-util-symbol/constants'
import {types} from 'micromark-util-symbol/types'
import {values} from 'micromark-util-symbol/values'
console.log(codes.atSign) // 64
console.log(constants.characterReferenceNamedSizeMax) // 31
console.log(types.definitionDestinationRaw) // 'definitionDestinationRaw'
console.log(values.atSign) // '@'
```
## API
This package has four entries in its export map: `micromark-util-symbol/codes`,
`micromark-util-symbol/constants`, `micromark-util-symbol/types`,
`micromark-util-symbol/values`.
Each module exports an identifier with the same name (for example,
`micromark-util-symbol/codes` has `codes`), which is an object mapping strings
to other values.
Take a peek at the code to learn more!
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-symbol.svg
[downloads]: https://www.npmjs.com/package/micromark-util-symbol
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-symbol.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-symbol
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
[micromark-build]: https://github.com/micromark/micromark/tree/main/packages/micromark-build
-----------
The following NPM package may be included in this product:
- micromark-util-types@1.0.2
This package contains the following license and notice below:
# micromark-util-types
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
micromark utility with a couple of typescript types.
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## Install
[npm][]:
```sh
npm install micromark-util-types
```
## Use
```js
/**
* @typedef {import('micromark-util-types').Point} Point
*/
```
## API
This module exports no identifiers.
There is no default export.
See
[the code](https://github.com/micromark/micromark/blob/main/packages/micromark-util-types/index.js)
for all about the exposed types.
## Security
See [`security.md`][securitymd] in [`micromark/.github`][health] for how to
submit a security report.
## Contribute
See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organisation, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg
[build]: https://github.com/micromark/micromark/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg
[coverage]: https://codecov.io/github/micromark/micromark
[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-encode.svg
[downloads]: https://www.npmjs.com/package/micromark-util-encode
[bundle-size-badge]: https://img.shields.io/bundlephobia/minzip/micromark-util-encode.svg
[bundle-size]: https://bundlephobia.com/result?p=micromark-util-encode
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[opencollective]: https://opencollective.com/unified
[npm]: https://docs.npmjs.com/cli/install
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/micromark/micromark/discussions
[license]: https://github.com/micromark/micromark/blob/main/license
[author]: https://wooorm.com
[health]: https://github.com/micromark/.github
[securitymd]: https://github.com/micromark/.github/blob/HEAD/security.md
[contributing]: https://github.com/micromark/.github/blob/HEAD/contributing.md
[support]: https://github.com/micromark/.github/blob/HEAD/support.md
[coc]: https://github.com/micromark/.github/blob/HEAD/code-of-conduct.md
-----------
The following NPM package may be included in this product:
- micromark@3.1.0
This package contains the following license and notice below:
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][bundle-size-badge]][bundle-size]
[![Sponsors][sponsors-badge]][opencollective]
[![Backers][backers-badge]][opencollective]
[![Chat][chat-badge]][chat]
The smallest CommonMark compliant markdown parser with positional info and
concrete tokens.
## Feature highlights
* [x] **[compliant][commonmark]** (100% to CommonMark)
* [x] **[extensions][]** ([GFM][], [directives][], [frontmatter][], [math][],
[MDX.js][mdxjs])
* [x] **[safe][security]** (by default)
* [x] **[small][size]** (smallest CM parser that exists)
* [x] **[robust][test]** (1800+ tests, 100% coverage, fuzz testing)
## When to use this
* If you *just* want to turn markdown into HTML (with maybe a few extensions)
* If you want to do *really complex things* with markdown
See [§ Comparison][comparison] for more info
## Intro
micromark is a long awaited markdown parser.
It uses a [state machine][cmsm] to parse the entirety of markdown into concrete
tokens.
It’s the smallest 100% [CommonMark][] compliant markdown parser in JavaScript.
It was made to replace the internals of [`remark-parse`][remark-parse], the most
[popular][] markdown parser.
Its API compiles to HTML, but its parts are made to be used separately, so as to
generate syntax trees ([`mdast-util-from-markdown`][from-markdown]) or compile
to other output formats.
* to learn markdown, see this [cheatsheet and tutorial][cheat]
* for more about us, see [`unifiedjs.com`][site]
* for updates, see [Twitter][]
* for questions, see [Discussions][chat]
* to help, see [contribute][] or [sponsor][] below
## Contents
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`micromark(value[, encoding][, options])`](#micromarkvalue-encoding-options)
* [`stream(options?)`](#streamoptions)
* [Extensions](#extensions)
* [List of extensions](#list-of-extensions)
* [`SyntaxExtension`](#syntaxextension)
* [`HtmlExtension`](#htmlextension)
* [Extending markdown](#extending-markdown)
* [Creating a micromark extension](#creating-a-micromark-extension)
* [Architecture](#architecture)
* [Overview](#overview)
* [Preprocess](#preprocess)
* [Parse](#parse)
* [Postprocess](#postprocess)
* [Compile](#compile)
* [Examples](#examples)
* [GitHub flavored markdown (GFM)](#github-flavored-markdown-gfm)
* [Math](#math)
* [Syntax tree](#syntax-tree)
* [Markdown](#markdown)
* [CommonMark](#commonmark)
* [Grammar](#grammar)
* [Project](#project)
* [Comparison](#comparison)
* [Test](#test)
* [Size & debug](#size--debug)
* [Version](#version)
* [Security](#security)
* [Contribute](#contribute)
* [Sponsor](#sponsor)
* [Origin story](#origin-story)
* [License](#license)
## Install
This package is [ESM only][esm].
In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install with [npm][]:
```sh
npm install micromark
```
In Deno with [`esm.sh`][esmsh]:
```js
import {micromark} from 'https://esm.sh/micromark@3'
```
In browsers with [`esm.sh`][esmsh]:
```html
```
## Use
Typical use (buffering):
```js
import {micromark} from 'micromark'
console.log(micromark('## Hello, *world*!'))
```
Yields:
```html
Hello, world !
```
You can pass extensions (in this case [`micromark-extension-gfm`][gfm]):
```js
import {micromark} from 'micromark'
import {gfm, gfmHtml} from 'micromark-extension-gfm'
const value = '* [x] contact@example.com ~~strikethrough~~'
const result = micromark(value, {
extensions: [gfm()],
htmlExtensions: [gfmHtml()]
})
console.log(result)
```
Yields:
```html
```
Streaming interface:
```js
import fs from 'fs'
import {stream} from 'micromark/stream'
fs.createReadStream('example.md')
.on('error', handleError)
.pipe(stream())
.pipe(process.stdout)
function handleError(error) {
// Handle your error here!
throw error
}
```
## API
`micromark` core has two entries in its export map: `micromark` and
`micromark/stream`.
`micromark` exports the following identifier: `micromark`.
`micromark/stream` exports the following identifier: `stream`.
There are no default exports.
The export map supports the endorsed
[`development` condition](https://nodejs.org/api/packages.html#packages_resolving_user_conditions).
Run `node --conditions development module.js` to get instrumented dev code.
Without this condition, production code is loaded.
See [§ Size & debug][size-debug] for more info.
### `micromark(value[, encoding][, options])`
Compile markdown to HTML.
##### Parameters
###### `value`
Markdown to parse (`string` or `Buffer`).
###### `encoding`
[Character encoding][encoding] to understand `value` as when it’s a
[`Buffer`][buffer] (`string`, default: `'utf8'`).
###### `options.defaultLineEnding`
Value to use for line endings not in `value` (`string`, default: first line
ending or `'\n'`).
Generally, micromark copies line endings (`'\r'`, `'\n'`, `'\r\n'`) in the
markdown document over to the compiled HTML.
In some cases, such as `> a`, CommonMark requires that extra line endings are
added: `\na
\n `.
###### `options.allowDangerousHtml`
Whether to allow embedded HTML (`boolean`, default: `false`).
See [§ Security][security].
###### `options.allowDangerousProtocol`
Whether to allow potentially dangerous protocols in links and images (`boolean`,
default: `false`).
URLs relative to the current protocol are always allowed (such as, `image.jpg`).
For links, the allowed protocols are `http`, `https`, `irc`, `ircs`, `mailto`,
and `xmpp`.
For images, the allowed protocols are `http` and `https`.
See [§ Security][security].
###### `options.extensions`
Array of syntax extensions ([`Array`][syntax-extension],
default: `[]`).
See [§ Extensions][extensions].
###### `options.htmlExtensions`
Array of HTML extensions ([`Array`][html-extension], default:
`[]`).
See [§ Extensions][extensions].
##### Returns
`string` — Compiled HTML.
### `stream(options?)`
Streaming interface of micromark.
Compiles markdown to HTML.
`options` are the same as the buffering API above.
Note that some of the work to parse markdown can be done streaming, but in the
end buffering is required.
micromark does not handle errors for you, so you must handle errors on whatever
streams you pipe into it.
As markdown does not know errors, `micromark` itself does not emit errors.
## Extensions
micromark supports extensions.
There are two types of extensions for micromark:
[`SyntaxExtension`][syntax-extension],
which change how markdown is parsed, and [`HtmlExtension`][html-extension],
which change how it compiles.
They can be passed in [`options.extensions`][option-extensions] or
[`options.htmlExtensions`][option-htmlextensions], respectively.
As a user of extensions, refer to each extension’s readme for more on how to use
them.
As a (potential) author of extensions, refer to
[§ Extending markdown][extending-markdown] and
[§ Creating a micromark extension][create-extension].
### List of extensions
* [`micromark/micromark-extension-directive`][directives]
— support directives (generic extensions)
* [`micromark/micromark-extension-frontmatter`][frontmatter]
— support frontmatter (YAML, TOML, etc)
* [`micromark/micromark-extension-gfm`][gfm]
— support GFM (GitHub Flavored Markdown)
* [`micromark/micromark-extension-gfm-autolink-literal`](https://github.com/micromark/micromark-extension-gfm-autolink-literal)
— support GFM autolink literals
* [`micromark/micromark-extension-gfm-footnote`](https://github.com/micromark/micromark-extension-gfm-footnote)
— support GFM footnotes
* [`micromark/micromark-extension-gfm-strikethrough`](https://github.com/micromark/micromark-extension-gfm-strikethrough)
— support GFM strikethrough
* [`micromark/micromark-extension-gfm-table`](https://github.com/micromark/micromark-extension-gfm-table)
— support GFM tables
* [`micromark/micromark-extension-gfm-tagfilter`](https://github.com/micromark/micromark-extension-gfm-tagfilter)
— support GFM tagfilter
* [`micromark/micromark-extension-gfm-task-list-item`](https://github.com/micromark/micromark-extension-gfm-task-list-item)
— support GFM tasklists
* [`micromark/micromark-extension-math`][math]
— support math
* [`micromark/micromark-extension-mdx`](https://github.com/micromark/micromark-extension-mdx)
— support MDX
* [`micromark/micromark-extension-mdxjs`][mdxjs]
— support MDX.js
* [`micromark/micromark-extension-mdx-expression`](https://github.com/micromark/micromark-extension-mdx-expression)
— support MDX (or MDX.js) expressions
* [`micromark/micromark-extension-mdx-jsx`](https://github.com/micromark/micromark-extension-mdx-jsx)
— support MDX (or MDX.js) JSX
* [`micromark/micromark-extension-mdx-md`](https://github.com/micromark/micromark-extension-mdx-md)
— support misc MDX changes
* [`micromark/micromark-extension-mdxjs-esm`](https://github.com/micromark/micromark-extension-mdxjs-esm)
— support MDX.js import/exports
#### Community extensions
* [`wataru-chocola/micromark-extension-definition-list`](https://github.com/wataru-chocola/micromark-extension-definition-list)
— support definition lists
### `SyntaxExtension`
A syntax extension is an object whose fields are typically the names of hooks,
referring to where constructs “hook” into.
The fields at such objects are character codes, mapping to constructs as values.
The built in [constructs][] are an example.
See it and [existing extensions][extensions] for inspiration.
### `HtmlExtension`
An HTML extension is an object whose fields are typically `enter` or `exit`
(reflecting whether a token is entered or exited).
The values at such objects are names of tokens mapping to handlers.
See [existing extensions][extensions] for inspiration.
### Extending markdown
micromark lets you change markdown syntax, yes, but there are alternatives.
The alternatives are often better.
Over the years, many micromark and remark users have asked about their unique
goals for markdown.
Some exemplary goals are:
1. I want to add `rel="nofollow"` to external links
2. I want to add links from headings to themselves
3. I want line breaks in paragraphs to become hard breaks
4. I want to support embedded music sheets
5. I want authors to add arbitrary attributes
6. I want authors to mark certain blocks with meaning, such as tip, warning,
etc
7. I want to combine markdown with JS(X)
8. I want to support our legacy flavor of markdown-like syntax
These can be solved in different ways and which solution is best is both
subjective and dependant on unique needs.
Often, there is already a solution in the form of an existing remark or rehype
plugin.
Respectively, their solutions are:
1. [`remark-external-links`](https://github.com/remarkjs/remark-external-links)
2. [`rehype-autolink-headings`](https://github.com/rehypejs/rehype-autolink-headings)
3. [`remark-breaks`](https://github.com/remarkjs/remark-breaks)
4. custom plugin similar to
[`rehype-katex`](https://github.com/remarkjs/remark-math/tree/main/packages/rehype-katex)
but integrating [`abcjs`](https://www.abcjs.net)
5. either [`remark-directive`](https://github.com/remarkjs/remark-directive)
and a custom plugin or with
[`rehype-attr`](https://github.com/jaywcjlove/rehype-attr)
6. [`remark-directive`](https://github.com/remarkjs/remark-directive)
combined with a custom plugin
7. combining the existing micromark MDX extensions however you please, such as
done by [`mdx-js/mdx`](https://github.com/mdx-js/mdx) or
[`xdm`](https://github.com/wooorm/xdm)
8. Writing a micromark extension
Looking at these from a higher level, they can be categorized:
* **Changing the output by transforming syntax trees**
(1 and 2)
This category is nice as the format remains plain markdown that authors are
already familiar with and which will work with existing tools and platforms.
Implementations will deal with the syntax tree
([`mdast`][mdast]) and the ecosystems
**[remark][]** and **[rehype][]**.
There are many existing
[utilities for working with that tree][utilities].
Many [remark plugins][] and [rehype plugins][] also exist.
* **Using and abusing markdown to add new meaning**
(3, 4, potentially 5)
This category is similar to *Changing the output by transforming syntax
trees*, but adds a new meaning to certain things which already have
semantics in markdown.
Some examples in pseudo code:
````markdown
* **A list item with the first paragraph bold**
And then more content, is turned into `` / `` / ` ` elements
Or, the title attributes on links or images is [overloaded](/url 'rel:nofollow')
with a new meaning.
```csv
fenced,code,can,include,data
which,is,turned,into,a,graph
```
```js data can="be" passed=true
// after the code language name
```
HTML, especially comments, could be used as **markers**
````
* **Arbitrary extension mechanism**
(potentially 5; 6)
This category is nice when content should contain embedded “components”.
Often this means it’s required for authors to have some programming
experience.
There are three good ways to solve arbitrary extensions.
**HTML**: Markdown already has an arbitrary extension syntax.
It works in most places and authors are already familiar with the syntax,
but it’s reasonably hard to implement securely.
Certain platforms will remove HTML completely, others sanitize it to varying
degrees.
HTML also supports custom elements.
These could be used and enhanced by client side JavaScript or enhanced when
transforming the syntax tree.
**Generic directives**: although
[a proposal][directive-proposal]
and not supported on most platforms, directives do work with many tools
already.
They’re not the easiest to author compared to, say, a heading, but sometimes
that’s okay.
They do have potential: they nicely solve the need for an infinite number of
potential extensions to markdown in a single markdown-esque way.
**MDX** also adds support for components by swapping HTML out for JS(X).
JSX is an extension to JavaScript, so MDX is something along the lines of
literate programming.
This does require knowledge of React (or Vue) and JavaScript, excluding some
authors.
* **Extending markdown syntax**
(7 and 8)
Extend the syntax of markdown means:
* Authors won’t be familiar with the syntax
* Content won’t work in other places (such as on GitHub)
* Defeating the purpose of markdown: being simple to author and looking
like what it means
…and it’s hard to do as it requires some in-depth knowledge of JavaScript
and parsing.
But it’s possible and in certain cases very powerful.
### Creating a micromark extension
This section shows how to create an extension for micromark that parses
“variables” (a way to render some data) and one to turn a default construct off.
> Stuck?
> See [`support.md`][support].
#### Prerequisites
* You should possess an intermediate to high understanding of JavaScript:
it’s going to get a bit complex
* Read the readme of [unified][] (until you hit the API section) to better
understand where micromark fits
* Read the [§ Architecture][architecture] section to understand how micromark
works
* Read the [§ Extending markdown][extending-markdown] section to understand
whether it’s a good idea to extend the syntax of markdown
#### Extension basics
micromark supports two types of extensions.
Syntax extensions change how markdown is parsed.
HTML extensions change how it compiles.
HTML extensions are not always needed, as micromark is often used through
[`mdast-util-from-markdown`][from-markdown] to parse to a markdown syntax tree
So instead of an HTML extension a `from-markdown` utility is needed.
Then, a [`mdast-util-to-markdown`][to-markdown] utility, which is responsible
for serializing syntax trees to markdown, is also needed.
When developing something for internal use only, you can pick and choose which
parts you need.
When open sourcing your extensions, it should probably contain four parts:
syntax extension, HTML extension, `from-markdown` utility, and a `to-markdown`
utility.
On to our first case!
#### Case: variables
Let’s first outline what we want to make: render some data, similar to how
[Liquid](https://github.com/Shopify/liquid/wiki/Liquid-for-Designers) and the
like work, in our markdown.
It could look like this:
```markdown
Hello, {planet}!
```
Turned into:
```html
Hello, Venus!
```
An opening curly brace, followed by one or more characters, and then a closing
brace.
We’ll then look up `planet` in some object and replace the variable with its
corresponding value, to get something like `Venus` out.
It looks simple enough, but with markdown there are often a couple more things
to think about.
For this case, I can see the following:
* Is there a “block” version too?
* Are spaces allowed?
Line endings?
Should initial and final white space be ignored?
* Balanced nested braces?
Superfluous ones such as `{{planet}}` or meaningful ones such as
`{a {pla} net}`?
* Character escapes (`{pla\}net}`) and character references
(`{pla}net}`)?
To keep things as simple as possible, let’s not support a block syntax, see
spaces as special, support line endings, or support nested braces.
But to learn interesting things, we *will* support character escapes and
\-references.
Note that this particular case is already solved quite nicely by
[`micromark-extension-mdx-expression`][mdx-expression].
It’s a bit more powerful and does more things, but it can be used to solve this
case and otherwise serve as inspiration.
##### Setup
Create a new folder, enter it, and set up a new package:
```sh
mkdir example
cd example
npm init -y
```
In this example we’ll use ESM, so add `type: 'module'` to `package.json`:
```diff
@@ -2,6 +2,7 @@
"name": "example",
"version": "1.0.0",
"description": "",
+ "type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
```
Add a markdown file, `example.md`, with the following text:
```markdown
Hello, {planet}!
{pla\}net} and {pla}net}.
```
To check if our extension works, add an `example.js` module, with the following
code:
```js
import {promises as fs} from 'node:fs'
import {micromark} from 'micromark'
import {variables} from './index.js'
main()
async function main() {
const buf = await fs.readFile('example.md')
const out = micromark(buf, {extensions: [variables]})
console.log(out)
}
```
While working on the extension, run `node example` to see whether things work.
Feel free to add more examples of the variables syntax in `example.md` if
needed.
Our extension doesn’t work yet, for one because `micromark` is not installed:
```sh
npm install micromark --save-dev
```
…and we need to write our extension.
Let’s do that in `index.js`:
```js
export const variables = {}
```
Although our extension doesn’t do anything, running `node example` now somewhat
works!
##### Syntax extension
Much in micromark is based on character codes (see [§ Preprocess][preprocess]).
For this extension, the relevant codes are:
* `-5`
— M-0005 CARRIAGE RETURN (CR)
* `-4`
— M-0004 LINE FEED (LF)
* `-3`
— M-0003 CARRIAGE RETURN LINE FEED (CRLF)
* `null`
— EOF (end of the stream)
* `92`
— U+005C BACKSLASH (`\`)
* `123`
— U+007B LEFT CURLY BRACE (`{`)
* `125`
— U+007D RIGHT CURLY BRACE (`}`)
Also relevant are the content types (see [§ Content types][content-types]).
This extension is a *text* construct, as it’s parsed alongsides links and such.
The content inside it (between the braces) is *string*, to support character
escapes and -references.
Let’s write our extension.
Add the following code to `index.js`:
```js
const variableConstruct = {name: 'variable', tokenize: variableTokenize}
export const variables = {text: {123: variableConstruct}}
function variableTokenize(effects, ok, nok) {
return start
function start(code) {
console.log('start:', effects, code);
return nok(code)
}
}
```
The above code exports an extension with the identifier `variables`.
The extension defines a *text* construct for the character code `123`.
The construct has a `name`, so that it can be turned off (optional, see next
case), and it has a `tokenize` function that sets up a state machine, which
receives `effects` and the `ok` and `nok` states.
`ok` can be used when successful, `nok` when not, and so constructs are a bit
similar to how promises can *resolve* or *reject*.
`tokenize` returns the initial state, `start`, which itself receives the current
character code, prints some debugging information, and then returns a call
to `nok`.
Ensure that things work by running `node example` and see what it prints.
Now we need to define our states and figure out how variables work.
Some people prefer sketching a diagram of the flow.
I often prefer writing it down in pseudo-code prose.
I’ve also found that test driven development works well, where I write unit
tests for how it should work, then write the state machine, and finally use a
code coverage tool to ensure I’ve thought of everything.
In prose, what we have to code looks like this:
* **start**:
Receive `123` as `code`, enter a token for the whole (let’s call it
`variable`), enter a token for the marker (`variableMarker`), consume
`code`, exit the marker token, enter a token for the contents
(`variableString`), switch to *begin*
* **begin**:
If `code` is `125`, reconsume in *nok*.
Else, reconsume in *inside*
* **inside**:
If `code` is `-5`, `-4`, `-3`, or `null`, reconsume in `nok`.
Else, if `code` is `125`, exit the string token, enter a `variableMarker`,
consume `code`, exit the marker token, exit the variable token, and switch
to *ok*.
Else, consume, and remain in *inside*.
That should be it!
Replace `variableTokenize` with the following to include the needed states:
```js
function variableTokenize(effects, ok, nok) {
return start
function start(code) {
effects.enter('variable')
effects.enter('variableMarker')
effects.consume(code)
effects.exit('variableMarker')
effects.enter('variableString')
return begin
}
function begin(code) {
return code === 125 ? nok(code) : inside(code)
}
function inside(code) {
if (code === -5 || code === -4 || code === -3 || code === null) {
return nok(code)
}
if (code === 125) {
effects.exit('variableString')
effects.enter('variableMarker')
effects.consume(code)
effects.exit('variableMarker')
effects.exit('variable')
return ok
}
effects.consume(code)
return inside
}
}
```
Run `node example` again and see what it prints!
The HTML compiler ignores things it doesn’t know, so variables are now removed.
We have our first syntax extension, and it sort of works, but we don’t handle
character escapes and -references yet.
We need to do two things to make that work:
a) skip over `\\` and `\}` in our algorithm,
b) tell micromark to parse them.
Change the code in `index.js` to support escapes like so:
```diff
@@ -23,6 +23,11 @@ function variableTokenize(effects, ok, nok) {
return nok(code)
}
+ if (code === 92) {
+ effects.consume(code)
+ return insideEscape
+ }
+
if (code === 125) {
effects.exit('variableString')
effects.enter('variableMarker')
@@ -35,4 +40,13 @@ function variableTokenize(effects, ok, nok) {
effects.consume(code)
return inside
}
+
+ function insideEscape(code) {
+ if (code === 92 || code === 125) {
+ effects.consume(code)
+ return inside
+ }
+
+ return inside(code)
+ }
}
```
Finally add support for character references and character escapes between
braces by adding a special token that defines a content type:
```diff
@@ -11,6 +11,7 @@ function variableTokenize(effects, ok, nok) {
effects.consume(code)
effects.exit('variableMarker')
effects.enter('variableString')
+ effects.enter('chunkString', {contentType: 'string'})
return begin
}
@@ -29,6 +30,7 @@ function variableTokenize(effects, ok, nok) {
}
if (code === 125) {
+ effects.exit('chunkString')
effects.exit('variableString')
effects.enter('variableMarker')
effects.consume(code)
```
Tokens with a `contentType` will be replaced by *postprocess* (see
[§ Postprocess][postprocess]) by the tokens belonging to that content type.
##### HTML extension
Up next is an HTML extension to replace variables with data.
Change `example.js` to use one like so:
```diff
@@ -1,11 +1,12 @@
import {promises as fs} from 'node:fs'
import {micromark} from 'micromark'
-import {variables} from './index.js'
+import {variables, variablesHtml} from './index.js'
main()
async function main() {
const buf = await fs.readFile('example.md')
- const out = micromark(buf, {extensions: [variables]})
+ const html = variablesHtml({planet: '1', 'pla}net': '2'})
+ const out = micromark(buf, {extensions: [variables], htmlExtensions: [html]})
console.log(out)
}
```
And add the HTML extension, `variablesHtml`, to `index.js` like so:
```diff
@@ -52,3 +52,19 @@ function variableTokenize(effects, ok, nok) {
return inside(code)
}
}
+
+export function variablesHtml(data = {}) {
+ return {
+ enter: {variableString: enterVariableString},
+ exit: {variableString: exitVariableString},
+ }
+
+ function enterVariableString() {
+ this.buffer()
+ }
+
+ function exitVariableString() {
+ var id = this.resume()
+ if (id in data) {
+ this.raw(this.encode(data[id]))
+ }
+ }
+}
```
`variablesHtml` is a function that receives an object mapping “variables” to
strings and returns an HTML extension.
The extension hooks two functions to `variableString`, one when it starts,
the other when it ends.
We don’t need to do anything to handle the other tokens as they’re already
ignored by default.
`enterVariableString` calls `buffer`, which is a function that “stashes” what
would otherwise be emitted.
`exitVariableString` calls `resume`, which is the inverse of `buffer` and
returns the stashed value.
If the variable is defined, we ensure it’s made safe (with `this.encode`) and
finally output that (with `this.raw`).
##### Further exercises
It works!
We’re done!
Of course, it can be better, such as with the following potential features:
* Add support for empty variables
* Add support for spaces between markers and string
* Add support for line endings in variables
* Add support for nested braces
* Add support for blocks
* Add warnings on undefined variables
* Use `micromark-build`, and use `uvu/assert`, `debug`, and
`micromark-util-symbol` (see [§ Size & debug][size-debug])
* Add [`mdast-util-from-markdown`][from-markdown] and
[`mdast-util-to-markdown`][to-markdown] utilities to parse and serialize the
AST
#### Case: turn off constructs
Sometimes it’s needed to turn a default construct off.
That’s possible through a syntax extension.
Note that not everything can be turned off (such as paragraphs) and even if it’s
possible to turn something off, it could break micromark (such as character
escapes).
To disable constructs, refer to them by name in an array at the `disable.null`
field of an extension:
```js
import {micromark} from 'micromark'
const extension = {disable: {null: ['codeIndented']}}
console.log(micromark('\ta', {extensions: [extension]}))
```
Yields:
```html
a
```
## Architecture
micromark is maintained as a monorepo.
Many of its internals, which are used in `micromark` (core) but also useful for
developers of extensions or integrations, are available as separate modules.
Each module maintained here is available in [`packages/`][packages].
### Overview
The naming scheme in [`packages/`][packages] is as follows:
* `micromark-build`
— Small CLI to build dev code into production code
* `micromark-core-commonmark`
— CommonMark constructs used in micromark
* `micromark-factory-*`
— Reusable subroutines used to parse parts of constructs
* `micromark-util-*`
— Reusable helpers often needed when parsing markdown
* `micromark`
— Core module
micromark has two interfaces: buffering (maintained in
[`micromark/dev/index.js`](https://github.com/micromark/micromark/blob/main/packages/micromark/dev/index.js))
and streaming (maintained in
[`micromark/dev/stream.js`](https://github.com/micromark/micromark/blob/main/packages/micromark/dev/stream.js)).
The first takes all input at once whereas the last uses a Node.js stream to take
input separately.
They thinly wrap how data flows through micromark:
```txt
micromark
+-----------------------------------------------------------------------------------------------+
| +------------+ +-------+ +-------------+ +---------+ |
| -markdown->+ preprocess +-chunks->+ parse +-events->+ postprocess +-events->+ compile +-html- |
| +------------+ +-------+ +-------------+ +---------+ |
+-----------------------------------------------------------------------------------------------+
```
### Preprocess
The **preprocessor**
([`micromark/dev/lib/preprocess.js`](https://github.com/micromark/micromark/blob/main/packages/micromark/dev/lib/preprocess.js))
takes markdown and turns it into chunks.
A **chunk** is either a character code or a slice of a buffer in the form of a
string.
Chunks are used because strings are more efficient storage than character codes,
but limited in what they can represent.
For example, the input `ab\ncd` is represented as `['ab', -4, 'cd']` in chunks.
A character **code** is often the same as what `String#charCodeAt()` yields but
micromark adds meaning to certain other values.
In micromark, the actual character U+0009 CHARACTER TABULATION (HT) is replaced
by one M-0002 HORIZONTAL TAB (HT) and between 0 and 3 M-0001 VIRTUAL SPACE (VS)
characters, depending on the column at which the tab occurred.
For example, the input `\ta` is represented as `[-2, -1, -1, -1, 97]` and `a\tb`
as `[97, -2, -1, -1, 98]` in character codes.
The characters U+000A LINE FEED (LF) and U+000D CARRIAGE RETURN (CR) are
replaced by virtual characters depending on whether they occur together: M-0003
CARRIAGE RETURN LINE FEED (CRLF), M-0004 LINE FEED (LF), and M-0005 CARRIAGE
RETURN (CR).
For example, the input `a\r\nb\nc\rd` is represented as
`[97, -5, 98, -4, 99, -3, 100]` in character codes.
The `0` (U+0000 NUL) character code is replaced by U+FFFD REPLACEMENT CHARACTER
(`�`).
The `null` code represents the end of the input stream (called *eof* for end of
file).
### Parse
The **parser**
([`micromark/dev/lib/parse.js`](https://github.com/micromark/micromark/blob/main/packages/micromark/dev/lib/parse.js))
takes chunks and turns them into events.
An **event** is the start or end of a token amongst other events.
Tokens can “contain” other tokens, even though they are stored in a flat list,
by entering before and exiting after them.
A **token** is a span of one or more codes.
Tokens are most of what micromark produces: the built in HTML compiler or other
tools can turn them into different things.
Tokens are essentially names attached to a slice, such as `lineEndingBlank` for
certain line endings, or `codeFenced` for a whole fenced code.
Sometimes, more info is attached to tokens, such as `_open` and `_close` by
`attention` (strong, emphasis) to signal whether the sequence can open or close
an attention run.
These fields have to do with how the parser works, which is complex and not
always pretty.
Certain fields (`previous`, `next`, and `contentType`) are used in many cases:
linked tokens for subcontent.
Linked tokens are used because outer constructs are parsed first.
Take for example:
```markdown
- *a
b*.
```
1. The list marker and the space after it is parsed first
2. The rest of the line is a `chunkFlow` token
3. The two spaces on the second line are a `linePrefix` of the list
4. The rest of the line is another `chunkFlow` token
The two `chunkFlow` tokens are linked together and the chunks they span are
passed through the flow tokenizer.
There the chunks are seen as `chunkContent` and passed through the content
tokenizer.
There the chunks are seen as a paragraph and seen as `chunkText` and passed
through the text tokenizer.
Finally, the attention (emphasis) and data (“raw” characters) is parsed there,
and we’re done!
#### Content types
The parser starts out with a document tokenizer.
*Document* is the top-most content type, which includes containers such as block
quotes and lists.
Containers in markdown come from the margin and include more constructs
on the lines that define them.
*Flow* represents the sections (block constructs such as ATX and setext
headings, HTML, indented and fenced code, thematic breaks), which like
*document* are also parsed per line.
An example is HTML, which has a certain starting condition (such as `