micromark-util-resolve-all
!Buildbuild-badgebuild
!Coveragecoverage-badgecoverage
!Downloadsdownloads-badgedownloads
!Sizebundle-size-badgebundle-size
!Sponsorssponsors-badgeopencollective
!Backersbackers-badgeopencollective
!Chatchat-badgechatmicromark utility to resolve subtokens.
Resolversresolver 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
* [`resolveAll(constructs, events, context)`](#resolveallconstructs-events-context)
What is this?
This package exposes a micromark internal that you probably don’t need.When should I use this?
This package might be useful when you are making your own micromark extensions.Install
This package is ESM onlyesm. In Node.js (version 16+), install with npm:npm install micromark-util-resolve-all
In Deno with
esm.sh
esmsh:import {resolveAll} from 'https://esm.sh/micromark-util-resolve-all@1'
In browsers with
esm.sh
esmsh:<script type="module">
import {resolveAll} from 'https://esm.sh/micromark-util-resolve-all@1?bundle'
</script>
Use
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 identifierresolveAll
api-resolve-all.
There is no default export.resolveAll(constructs, events, context)
Call all resolveAll
s in constructs
.Parameters
constructs
(Array<Construct>
)
— list of constructs, optionally with `resolveAll`s
events
(Array<Event>
)
— list of events
context
(TokenizeContext
)
— context used by `tokenize`
Returns
Changed events (Array<Events>
).Types
This package is fully typed with TypeScript. It exports no additional types.Compatibility
Projects maintained by the unified collective are compatible with maintained versions of Node.js.When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line,
micromark-util-resolve-all@^2
, compatible with Node.js 16.
This package works with micromark@^3
.Security
This package is safe. Seesecurity.md
securitymd in micromark/.github
health for how to
submit a security report.Contribute
Seecontributing.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 conductcoc. By interacting with this repository, organisation, or community you agree to abide by its terms.