{"id":11317,"library":"micromark-util-resolve-all","title":"micromark Utility to Resolve Subtokens","description":"micromark-util-resolve-all is a core utility package within the micromark ecosystem, designed to facilitate the complex process of resolving subtokens that cannot be parsed in a straightforward left-to-right manner. This is crucial for Markdown constructs such as attention (e.g., strong and emphasis) and media (links and images), where opening and closing delimiters might be matched non-sequentially or need post-processing after initial tokenization. The package is currently at version 2.0.1 and is part of the micromark project, which typically sees frequent, granular updates across its many utility packages, often released in lock-step with micromark's major versions. As an internal utility, it's not typically intended for direct end-user consumption but rather for developers extending micromark's parsing capabilities. Its primary differentiator is its role in orchestrating the event manipulation necessary for correct CommonMark parsing of non-linear syntax structures.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/micromark/micromark#main","tags":["javascript","micromark","util","utility","resolve","typescript"],"install":[{"cmd":"npm install micromark-util-resolve-all","lang":"bash","label":"npm"},{"cmd":"yarn add micromark-util-resolve-all","lang":"bash","label":"yarn"},{"cmd":"pnpm add micromark-util-resolve-all","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since version 2.0.0. CommonJS `require()` is not supported.","wrong":"const resolveAll = require('micromark-util-resolve-all')","symbol":"resolveAll","correct":"import { resolveAll } from 'micromark-util-resolve-all'"}],"quickstart":{"code":"import { resolveAll } from 'micromark-util-resolve-all';\n\n// These types are simplified for demonstration. In a real micromark setup,\n// these would be imported from micromark-util-types and other micromark core packages.\ntype MicromarkEvent = [string, { type: string; start: { offset: number }; end: { offset: number }; [key: string]: any }];\ntype MicromarkConstruct = {\n  resolveAll?: (events: MicromarkEvent[], context: MicromarkTokenizeContext) => MicromarkEvent[];\n  [key: string]: any;\n};\ntype MicromarkTokenizeContext = {\n  parser: {\n    constructs: {\n      insideSpan: {\n        null: MicromarkConstruct[];\n      };\n      [key: string]: any;\n    };\n  };\n  // Other context properties would be here in a real scenario\n  defineSkip: () => {};\n  events: MicromarkEvent[];\n  previous: number;\n  sliceStream: (start: {offset: number}, end: {offset: number}) => string;\n};\n\n// 1. Define some dummy events. In micromark, these represent tokens parsed from Markdown.\nconst inputEvents: MicromarkEvent[] = [\n  ['enter', { type: 'paragraph', start: { offset: 0 }, end: { offset: 0 } }],\n  ['enter', { type: 'text', start: { offset: 0 }, end: { offset: 5 }, value: 'Hello' }],\n  ['exit', { type: 'text', start: { offset: 0 }, end: { offset: 5 } }],\n  ['enter', { type: 'strongSequence', start: { offset: 6 }, end: { offset: 8 }, _open: true }], // e.g., '**'\n  ['enter', { type: 'text', start: { offset: 8 }, end: { offset: 13 }, value: 'World' }],\n  ['exit', { type: 'text', start: { offset: 8 }, end: { offset: 13 } }],\n  ['exit', { type: 'strongSequence', start: { offset: 13 }, end: { offset: 15 }, _close: true }], // e.g., '**'\n  ['exit', { type: 'paragraph', start: { offset: 15 }, end: { offset: 15 } }],\n];\n\n// 2. Define dummy constructs. `resolveAll` takes a list of constructs, \n// some of which may contain their own `resolveAll` logic for post-processing.\nconst dummyConstructs: MicromarkConstruct[] = [\n  {\n    name: 'emphasis',\n    resolveAll: (events: MicromarkEvent[], context: MicromarkTokenizeContext): MicromarkEvent[] => {\n      console.log('  -> Custom emphasis resolver called within resolveAll. Events count:', events.length);\n      // In a real scenario, this resolver would match openers and closers (like `*` or `**`)\n      // and transform `attentionSequence` events into `emphasis` or `strong` nodes.\n      return events.map(event => {\n        if (event[1].type === 'strongSequence') {\n          return [event[0], { ...event[1], type: 'strongToken' }];\n        }\n        return event;\n      });\n    }\n  },\n  { name: 'link' } // A construct without a custom `resolveAll`\n];\n\n// 3. Define a dummy context. In a real micromark parser, this object holds state.\nconst dummyContext: MicromarkTokenizeContext = {\n  parser: { constructs: { insideSpan: { null: dummyConstructs } } },\n  defineSkip: () => {},\n  events: inputEvents, // Often, context.events would be the input events\n  previous: -1,\n  sliceStream: () => ''\n};\n\nconsole.log('--- Before resolveAll ---');\ninputEvents.forEach(e => console.log(`  ${e[0].padEnd(5)} ${e[1].type}`));\n\n// 4. Call `resolveAll` with the constructs, events, and context.\n// It iterates through the provided constructs and calls their `resolveAll` methods.\nconst outputEvents = resolveAll(\n  dummyContext.parser.constructs.insideSpan.null, // Typically operates on constructs relevant to inline content\n  inputEvents,\n  dummyContext\n);\n\nconsole.log('\\n--- After resolveAll ---');\noutputEvents.forEach(e => console.log(`  ${e[0].padEnd(5)} ${e[1].type}`));\n","lang":"typescript","description":"This quickstart demonstrates how to use the `resolveAll` function by providing mock micromark events, constructs, and context. It shows how `resolveAll` orchestrates custom resolvers within constructs to process and transform the event stream, crucial for parsing non-linear Markdown syntax elements."},"warnings":[{"fix":"Migrate your project to use ECMAScript Modules (ESM) with `import` statements, or stick to a previous major version if CommonJS is strictly required (though older versions might not be compatible with newer micromark releases).","message":"Starting with version 2.0.0, micromark-util-resolve-all is an ESM-only package. Projects using CommonJS `require()` will encounter an `ERR_REQUIRE_ESM` error.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your Node.js environment to version 16 or newer. Refer to the Node.js official documentation for upgrade instructions.","message":"Version 2.x of micromark-util-resolve-all requires Node.js 16 or higher. Older Node.js versions are not supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Unless you are developing a custom micromark extension at a very low level, consider using micromark's higher-level APIs or existing extensions instead of this utility directly.","message":"This package is an internal utility for the `micromark` parser. It's not typically intended for direct use by most developers. Directly depending on and using this package might couple your code too tightly to micromark's internal architecture, which can change in patch or minor releases without being considered a breaking change for external APIs.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure your project is configured for ESM, using `import` statements and setting `\"type\": \"module\"` in your `package.json`, or explicitly using `.mjs` file extensions. For Node.js, ensure you are running a compatible version (16+).","cause":"Attempting to use `require()` to import `micromark-util-resolve-all` in a CommonJS environment.","error":"ERR_REQUIRE_ESM: require() of ES Module ... micromark-util-resolve-all.js from ... not supported."}],"ecosystem":"npm"}