What is micromark-factory-space?
The micromark-factory-space package is a utility for handling spaces in the micromark ecosystem, which is a tool for parsing and compiling markdown. It provides functions to handle spaces, tabs, and line endings in markdown documents.
What are micromark-factory-space's main functionalities?
Handling spaces
This feature allows you to handle spaces in markdown documents. The factorySpace function is used to create a tokenizer that processes spaces.
const { factorySpace } = require('micromark-factory-space');
const tokenizer = {
tokenize: function (effects, ok, nok) {
return factorySpace(effects, ok, 'space');
}
};
Handling tabs
This feature allows you to handle tabs in markdown documents. The factorySpace function is used to create a tokenizer that processes tabs.
const { factorySpace } = require('micromark-factory-space');
const tokenizer = {
tokenize: function (effects, ok, nok) {
return factorySpace(effects, ok, 'tab');
}
};
Handling line endings
This feature allows you to handle line endings in markdown documents. The factorySpace function is used to create a tokenizer that processes line endings.
const { factorySpace } = require('micromark-factory-space');
const tokenizer = {
tokenize: function (effects, ok, nok) {
return factorySpace(effects, ok, 'lineEnding');
}
};
Other packages similar to micromark-factory-space
micromark
Micromark is a comprehensive markdown parser that includes various utilities for handling markdown syntax, including spaces, tabs, and line endings. It is more feature-rich compared to micromark-factory-space, which focuses specifically on space handling.
remark
Remark is a markdown processor built on the unified framework. It provides extensive plugins and utilities for parsing, transforming, and compiling markdown. While it offers broader functionality, it can be more complex to use compared to the focused micromark-factory-space.
markdown-it
Markdown-it is a fast and flexible markdown parser that supports plugins for extended functionality. It provides similar capabilities for handling spaces, tabs, and line endings but is designed to be more extensible and customizable.
micromark-factory-space
micromark factory to parse markdown space (found in lots of
places).
Contents
Install
npm:
npm install micromark-factory-space
Use
import {factorySpace} from 'micromark-factory-space'
import {codes} from 'micromark-util-symbol/codes'
import {types} from 'micromark-util-symbol/types'
function tokenizeCodeFenced(effects, ok, nok) {
return start
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) right before using
factorySpace
Parameters
effects
(Effects
) — Contextok
(State
) — State switched to when successfultype
(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.
␉
␠␠␠␠
␉␠
Security
See security.md
in micromark/.github
for how to
submit a security report.
Contribute
See contributing.md
in micromark/.github
for ways
to get started.
See support.md
for ways to get help.
This project has a code of conduct.
By interacting with this repository, organisation, or community you agree to
abide by its terms.
License
MIT © Titus Wormer