basant307/AI_Governance_Project
048
1# micromark-util-resolve-all2 3[![Build][build-badge]][build]4[![Coverage][coverage-badge]][coverage]5[![Downloads][downloads-badge]][downloads]6[![Size][bundle-size-badge]][bundle-size]7[![Sponsors][sponsors-badge]][opencollective]8[![Backers][backers-badge]][opencollective]9[![Chat][chat-badge]][chat]10 11[micromark][] utility to resolve subtokens.12 13[Resolvers][resolver] are functions that take events and manipulate them.14This is needed for example because media (links, images) and attention (strong,15italic) aren’t parsed left-to-right.16Instead, their openings and closings are parsed, and when done, their openings17and closings are matched, and left overs are turned into plain text.18Because media and attention can’t overlap, we need to perform that operation19when one closing matches an opening, too.20 21## Contents22 23* [What is this?](#what-is-this)24* [When should I use this?](#when-should-i-use-this)25* [Install](#install)26* [Use](#use)27* [API](#api)28 * [`resolveAll(constructs, events, context)`](#resolveallconstructs-events-context)29* [Types](#types)30* [Compatibility](#compatibility)31* [Security](#security)32* [Contribute](#contribute)33* [License](#license)34 35## What is this?36 37This package exposes a micromark internal that you probably don’t need.38 39## When should I use this?40 41This package might be useful when you are making your own micromark extensions.42 43## Install44 45This package is [ESM only][esm].46In Node.js (version 16+), install with [npm][]:47 48```sh49npm install micromark-util-resolve-all50```51 52In Deno with [`esm.sh`][esmsh]:53 54```js55import {resolveAll} from 'https://esm.sh/micromark-util-resolve-all@1'56```57 58In browsers with [`esm.sh`][esmsh]:59 60```html61<script type="module">62 import {resolveAll} from 'https://esm.sh/micromark-util-resolve-all@1?bundle'63</script>64```65 66## Use67 68```js69import {push} from 'micromark-util-chunked'70import {resolveAll} from 'micromark-util-resolve-all'71 72/**73 * @type {Resolver}74 */75function resolveAllAttention(events, context) {76 // …77 78 // Walk through all events.79 while (++index < events.length) {80 // Find a token that can close.81 if (82 events[index][0] === 'enter' &&83 events[index][1].type === 'attentionSequence' &&84 events[index][1]._close85 ) {86 open = index87 88 // Now walk back to find an opener.89 while (open--) {90 // Find a token that can open the closer.91 if (92 // …93 ) {94 // …95 96 // Opening.97 nextEvents = push(nextEvents, [98 // …99 ])100 101 // Between.102 nextEvents = push(103 nextEvents,104 resolveAll(105 context.parser.constructs.insideSpan.null,106 events.slice(open + 1, index),107 context108 )109 )110 111 // Closing.112 nextEvents = push(nextEvents, [113 // …114 ])115 116 // …117 }118 }119 }120 }121 122 // …123}124```125 126## API127 128This module exports the identifier [`resolveAll`][api-resolve-all].129There is no default export.130 131### `resolveAll(constructs, events, context)`132 133Call all `resolveAll`s in `constructs`.134 135###### Parameters136 137* `constructs` (`Array<Construct>`)138 — list of constructs, optionally with `resolveAll`s139* `events` (`Array<Event>`)140 — list of events141* `context` (`TokenizeContext`)142 — context used by `tokenize`143 144###### Returns145 146Changed events (`Array<Events>`).147 148## Types149 150This package is fully typed with [TypeScript][].151It exports no additional types.152 153## Compatibility154 155Projects maintained by the unified collective are compatible with maintained156versions of Node.js.157 158When we cut a new major release, we drop support for unmaintained versions of159Node.160This means we try to keep the current release line,161`micromark-util-resolve-all@2`, compatible with Node.js 16.162This package works with `micromark@3`.163 164## Security165 166This package is safe.167See [`security.md`][securitymd] in [`micromark/.github`][health] for how to168submit a security report.169 170## Contribute171 172See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways173to get started.174See [`support.md`][support] for ways to get help.175 176This project has a [code of conduct][coc].177By interacting with this repository, organisation, or community you agree to178abide by its terms.179 180## License181 182[MIT][license] © [Titus Wormer][author]183 184<!-- Definitions -->185 186[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg187 188[build]: https://github.com/micromark/micromark/actions189 190[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg191 192[coverage]: https://codecov.io/github/micromark/micromark193 194[downloads-badge]: https://img.shields.io/npm/dm/micromark-util-resolve-all.svg195 196[downloads]: https://www.npmjs.com/package/micromark-util-resolve-all197 198[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-util-resolve-all199 200[bundle-size]: https://bundlejs.com/?q=micromark-util-resolve-all201 202[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg203 204[backers-badge]: https://opencollective.com/unified/backers/badge.svg205 206[opencollective]: https://opencollective.com/unified207 208[npm]: https://docs.npmjs.com/cli/install209 210[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c211 212[esmsh]: https://esm.sh213 214[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg215 216[chat]: https://github.com/micromark/micromark/discussions217 218[license]: https://github.com/micromark/micromark/blob/main/license219 220[author]: https://wooorm.com221 222[health]: https://github.com/micromark/.github223 224[securitymd]: https://github.com/micromark/.github/blob/main/security.md225 226[contributing]: https://github.com/micromark/.github/blob/main/contributing.md227 228[support]: https://github.com/micromark/.github/blob/main/support.md229 230[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md231 232[resolver]: https://github.com/micromark/micromark/blob/a571c09/packages/micromark-util-types/index.js#L219233 234[typescript]: https://www.typescriptlang.org235 236[micromark]: https://github.com/micromark/micromark237 238[api-resolve-all]: #resolveallconstructs-events-context239 