AK-21/Graphite-Industrial-Intelligence
0
1/**2 * @import {3 * Construct,4 * State,5 * TokenizeContext,6 * Tokenizer7 * } from 'micromark-util-types'8 */9 10import { labelEnd } from './label-end.js';11 12/** @type {Construct} */13export const labelStartImage = {14 name: 'labelStartImage',15 resolveAll: labelEnd.resolveAll,16 tokenize: tokenizeLabelStartImage17};18 19/**20 * @this {TokenizeContext}21 * Context.22 * @type {Tokenizer}23 */24function tokenizeLabelStartImage(effects, ok, nok) {25 const self = this;26 return start;27 28 /**29 * Start of label (image) start.30 *31 * ```markdown32 * > | a ![b] c33 * ^34 * ```35 *36 * @type {State}37 */38 function start(code) {39 effects.enter("labelImage");40 effects.enter("labelImageMarker");41 effects.consume(code);42 effects.exit("labelImageMarker");43 return open;44 }45 46 /**47 * After `!`, at `[`.48 *49 * ```markdown50 * > | a ![b] c51 * ^52 * ```53 *54 * @type {State}55 */56 function open(code) {57 if (code === 91) {58 effects.enter("labelMarker");59 effects.consume(code);60 effects.exit("labelMarker");61 effects.exit("labelImage");62 return after;63 }64 return nok(code);65 }66 67 /**68 * After `![`.69 *70 * ```markdown71 * > | a ![b] c72 * ^73 * ```74 *75 * This is needed in because, when GFM footnotes are enabled, images never76 * form when started with a `^`.77 * Instead, links form:78 *79 * ```markdown80 * 81 *82 * ![^a][b]83 *84 * [b]: c85 * ```86 *87 * ```html88 * <p>!<a href=\"b\">^a</a></p>89 * <p>!<a href=\"c\">^a</a></p>90 * ```91 *92 * @type {State}93 */94 function after(code) {95 // To do: use a new field to do this, this is still needed for96 // `micromark-extension-gfm-footnote`, but the `label-start-link`97 // behavior isn’t.98 // Hidden footnotes hook.99 /* c8 ignore next 3 */100 return code === 94 && '_hiddenFootnoteSupport' in self.parser.constructs ? nok(code) : ok(code);101 }102}