micromark-util-resolve-all
micromark utility to resolve subtokens
Last updated 4 years ago by wooorm .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install micromark-util-resolve-all 
SYNC missed versions from official npm registry.

micromark-util-resolve-all

Build Coverage Downloads Size Sponsors Backers Chat

micromark utility to resolve subtokens.

Resolvers 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

npm:

npm install micromark-util-resolve-all

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 following identifiers: resolveAll. There is no default export.

resolveAll(constructs, events, context)

Call all resolveAlls in constructs.

Parameters
  • constructs (Construct[]) — List of constructs, optionally with resolveAlls
  • events (Event[]) — List of events
  • context (TokenizeContext) — Context used by tokenize
Returns

Events[] — Changed events.

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

Current Tags

  • 1.0.0                                ...           latest (3 years ago)
  • 1.0.0-beta.1                                ...           next (3 years ago)

5 Versions

  • 1.0.0                                ...           3 years ago
  • 1.0.0-beta.1                                ...           3 years ago
  • 1.0.0-alpha.3                                ...           3 years ago
  • 1.0.0-alpha.2                                ...           4 years ago
  • 1.0.0-alpha.1                                ...           4 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (0)
None

Copyright 2013 - present © cnpmjs.org | Home |