AK-21/Graphite-Industrial-Intelligence
0
1/**2 * @import {3 * Construct,4 * Exiter,5 * State,6 * TokenizeContext,7 * Tokenizer8 * } from 'micromark-util-types'9 */10 11import { factorySpace } from 'micromark-factory-space';12import { markdownSpace } from 'micromark-util-character';13/** @type {Construct} */14export const blockQuote = {15 continuation: {16 tokenize: tokenizeBlockQuoteContinuation17 },18 exit,19 name: 'blockQuote',20 tokenize: tokenizeBlockQuoteStart21};22 23/**24 * @this {TokenizeContext}25 * Context.26 * @type {Tokenizer}27 */28function tokenizeBlockQuoteStart(effects, ok, nok) {29 const self = this;30 return start;31 32 /**33 * Start of block quote.34 *35 * ```markdown36 * > | > a37 * ^38 * ```39 *40 * @type {State}41 */42 function start(code) {43 if (code === 62) {44 const state = self.containerState;45 if (!state.open) {46 effects.enter("blockQuote", {47 _container: true48 });49 state.open = true;50 }51 effects.enter("blockQuotePrefix");52 effects.enter("blockQuoteMarker");53 effects.consume(code);54 effects.exit("blockQuoteMarker");55 return after;56 }57 return nok(code);58 }59 60 /**61 * After `>`, before optional whitespace.62 *63 * ```markdown64 * > | > a65 * ^66 * ```67 *68 * @type {State}69 */70 function after(code) {71 if (markdownSpace(code)) {72 effects.enter("blockQuotePrefixWhitespace");73 effects.consume(code);74 effects.exit("blockQuotePrefixWhitespace");75 effects.exit("blockQuotePrefix");76 return ok;77 }78 effects.exit("blockQuotePrefix");79 return ok(code);80 }81}82 83/**84 * Start of block quote continuation.85 *86 * ```markdown87 * | > a88 * > | > b89 * ^90 * ```91 *92 * @this {TokenizeContext}93 * Context.94 * @type {Tokenizer}95 */96function tokenizeBlockQuoteContinuation(effects, ok, nok) {97 const self = this;98 return contStart;99 100 /**101 * Start of block quote continuation.102 *103 * Also used to parse the first block quote opening.104 *105 * ```markdown106 * | > a107 * > | > b108 * ^109 * ```110 *111 * @type {State}112 */113 function contStart(code) {114 if (markdownSpace(code)) {115 // Always populated by defaults.116 117 return factorySpace(effects, contBefore, "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4)(code);118 }119 return contBefore(code);120 }121 122 /**123 * At `>`, after optional whitespace.124 *125 * Also used to parse the first block quote opening.126 *127 * ```markdown128 * | > a129 * > | > b130 * ^131 * ```132 *133 * @type {State}134 */135 function contBefore(code) {136 return effects.attempt(blockQuote, ok, nok)(code);137 }138}139 140/** @type {Exiter} */141function exit(effects) {142 effects.exit("blockQuote");143}