diff --git a/node_modules/micromark-core-commonmark/dev/index.d.ts b/node_modules/micromark-core-commonmark/dev/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..bd832f665cfdf802955e1fb1663357efe8d03eff --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/index.d.ts @@ -0,0 +1,23 @@ +export { attention } from "./lib/attention.js"; +export { autolink } from "./lib/autolink.js"; +export { blankLine } from "./lib/blank-line.js"; +export { blockQuote } from "./lib/block-quote.js"; +export { characterEscape } from "./lib/character-escape.js"; +export { characterReference } from "./lib/character-reference.js"; +export { codeFenced } from "./lib/code-fenced.js"; +export { codeIndented } from "./lib/code-indented.js"; +export { codeText } from "./lib/code-text.js"; +export { content } from "./lib/content.js"; +export { definition } from "./lib/definition.js"; +export { hardBreakEscape } from "./lib/hard-break-escape.js"; +export { headingAtx } from "./lib/heading-atx.js"; +export { htmlFlow } from "./lib/html-flow.js"; +export { htmlText } from "./lib/html-text.js"; +export { labelEnd } from "./lib/label-end.js"; +export { labelStartImage } from "./lib/label-start-image.js"; +export { labelStartLink } from "./lib/label-start-link.js"; +export { lineEnding } from "./lib/line-ending.js"; +export { list } from "./lib/list.js"; +export { setextUnderline } from "./lib/setext-underline.js"; +export { thematicBreak } from "./lib/thematic-break.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/index.d.ts.map b/node_modules/micromark-core-commonmark/dev/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..ca7a93a9a2807d2076f2cc871f10d62d40e1265d --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/index.js b/node_modules/micromark-core-commonmark/dev/index.js new file mode 100644 index 0000000000000000000000000000000000000000..f9143e09370ab0b29c410c5efadc2bc529dd7ee1 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/index.js @@ -0,0 +1,22 @@ +export {attention} from './lib/attention.js' +export {autolink} from './lib/autolink.js' +export {blankLine} from './lib/blank-line.js' +export {blockQuote} from './lib/block-quote.js' +export {characterEscape} from './lib/character-escape.js' +export {characterReference} from './lib/character-reference.js' +export {codeFenced} from './lib/code-fenced.js' +export {codeIndented} from './lib/code-indented.js' +export {codeText} from './lib/code-text.js' +export {content} from './lib/content.js' +export {definition} from './lib/definition.js' +export {hardBreakEscape} from './lib/hard-break-escape.js' +export {headingAtx} from './lib/heading-atx.js' +export {htmlFlow} from './lib/html-flow.js' +export {htmlText} from './lib/html-text.js' +export {labelEnd} from './lib/label-end.js' +export {labelStartImage} from './lib/label-start-image.js' +export {labelStartLink} from './lib/label-start-link.js' +export {lineEnding} from './lib/line-ending.js' +export {list} from './lib/list.js' +export {setextUnderline} from './lib/setext-underline.js' +export {thematicBreak} from './lib/thematic-break.js' diff --git a/node_modules/micromark-core-commonmark/dev/lib/attention.d.ts b/node_modules/micromark-core-commonmark/dev/lib/attention.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1c8a1747cd541882f27256474956bf083271d56d --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/attention.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const attention: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=attention.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/attention.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/attention.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..a903a8668f8add6b01762fe3636413a980b97d87 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/attention.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"attention.d.ts","sourceRoot":"","sources":["attention.js"],"names":[],"mappings":"AAoBA,wBAAwB;AACxB,wBADW,SAAS,CAKnB;+BAdS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/attention.js b/node_modules/micromark-core-commonmark/dev/lib/attention.js new file mode 100644 index 0000000000000000000000000000000000000000..9c93eb83f76e7948172bb84eb49acfc3595b84ad --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/attention.js @@ -0,0 +1,300 @@ +/** + * @import { + * Code, + * Construct, + * Event, + * Point, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {push, splice} from 'micromark-util-chunked' +import {classifyCharacter} from 'micromark-util-classify-character' +import {resolveAll} from 'micromark-util-resolve-all' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const attention = { + name: 'attention', + resolveAll: resolveAllAttention, + tokenize: tokenizeAttention +} + +/** + * Take all events and resolve attention to emphasis or strong. + * + * @type {Resolver} + */ +// eslint-disable-next-line complexity +function resolveAllAttention(events, context) { + let index = -1 + /** @type {number} */ + let open + /** @type {Token} */ + let group + /** @type {Token} */ + let text + /** @type {Token} */ + let openingSequence + /** @type {Token} */ + let closingSequence + /** @type {number} */ + let use + /** @type {Array} */ + let nextEvents + /** @type {number} */ + let offset + + // Walk through all events. + // + // Note: performance of this is fine on an mb of normal markdown, but it’s + // a bottleneck for malicious stuff. + 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 ( + events[open][0] === 'exit' && + events[open][1].type === 'attentionSequence' && + events[open][1]._open && + // If the markers are the same: + context.sliceSerialize(events[open][1]).charCodeAt(0) === + context.sliceSerialize(events[index][1]).charCodeAt(0) + ) { + // If the opening can close or the closing can open, + // and the close size *is not* a multiple of three, + // but the sum of the opening and closing size *is* multiple of three, + // then don’t match. + if ( + (events[open][1]._close || events[index][1]._open) && + (events[index][1].end.offset - events[index][1].start.offset) % 3 && + !( + (events[open][1].end.offset - + events[open][1].start.offset + + events[index][1].end.offset - + events[index][1].start.offset) % + 3 + ) + ) { + continue + } + + // Number of markers to use from the sequence. + use = + events[open][1].end.offset - events[open][1].start.offset > 1 && + events[index][1].end.offset - events[index][1].start.offset > 1 + ? 2 + : 1 + + const start = {...events[open][1].end} + const end = {...events[index][1].start} + movePoint(start, -use) + movePoint(end, use) + + openingSequence = { + type: use > 1 ? types.strongSequence : types.emphasisSequence, + start, + end: {...events[open][1].end} + } + closingSequence = { + type: use > 1 ? types.strongSequence : types.emphasisSequence, + start: {...events[index][1].start}, + end + } + text = { + type: use > 1 ? types.strongText : types.emphasisText, + start: {...events[open][1].end}, + end: {...events[index][1].start} + } + group = { + type: use > 1 ? types.strong : types.emphasis, + start: {...openingSequence.start}, + end: {...closingSequence.end} + } + + events[open][1].end = {...openingSequence.start} + events[index][1].start = {...closingSequence.end} + + nextEvents = [] + + // If there are more markers in the opening, add them before. + if (events[open][1].end.offset - events[open][1].start.offset) { + nextEvents = push(nextEvents, [ + ['enter', events[open][1], context], + ['exit', events[open][1], context] + ]) + } + + // Opening. + nextEvents = push(nextEvents, [ + ['enter', group, context], + ['enter', openingSequence, context], + ['exit', openingSequence, context], + ['enter', text, context] + ]) + + // Always populated by defaults. + assert( + context.parser.constructs.insideSpan.null, + 'expected `insideSpan` to be populated' + ) + + // Between. + nextEvents = push( + nextEvents, + resolveAll( + context.parser.constructs.insideSpan.null, + events.slice(open + 1, index), + context + ) + ) + + // Closing. + nextEvents = push(nextEvents, [ + ['exit', text, context], + ['enter', closingSequence, context], + ['exit', closingSequence, context], + ['exit', group, context] + ]) + + // If there are more markers in the closing, add them after. + if (events[index][1].end.offset - events[index][1].start.offset) { + offset = 2 + nextEvents = push(nextEvents, [ + ['enter', events[index][1], context], + ['exit', events[index][1], context] + ]) + } else { + offset = 0 + } + + splice(events, open - 1, index - open + 3, nextEvents) + + index = open + nextEvents.length - offset - 2 + break + } + } + } + } + + // Remove remaining sequences. + index = -1 + + while (++index < events.length) { + if (events[index][1].type === 'attentionSequence') { + events[index][1].type = 'data' + } + } + + return events +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeAttention(effects, ok) { + const attentionMarkers = this.parser.constructs.attentionMarkers.null + const previous = this.previous + const before = classifyCharacter(previous) + + /** @type {NonNullable} */ + let marker + + return start + + /** + * Before a sequence. + * + * ```markdown + * > | ** + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert( + code === codes.asterisk || code === codes.underscore, + 'expected asterisk or underscore' + ) + marker = code + effects.enter('attentionSequence') + return inside(code) + } + + /** + * In a sequence. + * + * ```markdown + * > | ** + * ^^ + * ``` + * + * @type {State} + */ + function inside(code) { + if (code === marker) { + effects.consume(code) + return inside + } + + const token = effects.exit('attentionSequence') + + // To do: next major: move this to resolver, just like `markdown-rs`. + const after = classifyCharacter(code) + + // Always populated by defaults. + assert(attentionMarkers, 'expected `attentionMarkers` to be populated') + + const open = + !after || + (after === constants.characterGroupPunctuation && before) || + attentionMarkers.includes(code) + const close = + !before || + (before === constants.characterGroupPunctuation && after) || + attentionMarkers.includes(previous) + + token._open = Boolean( + marker === codes.asterisk ? open : open && (before || !close) + ) + token._close = Boolean( + marker === codes.asterisk ? close : close && (after || !open) + ) + return ok(code) + } +} + +/** + * Move a point a bit. + * + * Note: `move` only works inside lines! It’s not possible to move past other + * chunks (replacement characters, tabs, or line endings). + * + * @param {Point} point + * Point. + * @param {number} offset + * Amount to move. + * @returns {undefined} + * Nothing. + */ +function movePoint(point, offset) { + point.column += offset + point.offset += offset + point._bufferIndex += offset +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/autolink.d.ts b/node_modules/micromark-core-commonmark/dev/lib/autolink.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a69457b269fcc1d83c432756ca186d793bac5395 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/autolink.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const autolink: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=autolink.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/autolink.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/autolink.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..7b0216b0a09072c2df4bee60f469f5ff8750c413 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/autolink.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"autolink.d.ts","sourceRoot":"","sources":["autolink.js"],"names":[],"mappings":"AAkBA,wBAAwB;AACxB,uBADW,SAAS,CACkD;+BAb5D,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/autolink.js b/node_modules/micromark-core-commonmark/dev/lib/autolink.js new file mode 100644 index 0000000000000000000000000000000000000000..b951120f88df46eeb96aa1137ca85fd6d8de3f6b --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/autolink.js @@ -0,0 +1,269 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import { + asciiAlphanumeric, + asciiAlpha, + asciiAtext, + asciiControl +} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const autolink = {name: 'autolink', tokenize: tokenizeAutolink} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeAutolink(effects, ok, nok) { + let size = 0 + + return start + + /** + * Start of an autolink. + * + * ```markdown + * > | ab + * ^ + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.lessThan, 'expected `<`') + effects.enter(types.autolink) + effects.enter(types.autolinkMarker) + effects.consume(code) + effects.exit(types.autolinkMarker) + effects.enter(types.autolinkProtocol) + return open + } + + /** + * After `<`, at protocol or atext. + * + * ```markdown + * > | ab + * ^ + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (asciiAlpha(code)) { + effects.consume(code) + return schemeOrEmailAtext + } + + if (code === codes.atSign) { + return nok(code) + } + + return emailAtext(code) + } + + /** + * At second byte of protocol or atext. + * + * ```markdown + * > | ab + * ^ + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function schemeOrEmailAtext(code) { + // ASCII alphanumeric and `+`, `-`, and `.`. + if ( + code === codes.plusSign || + code === codes.dash || + code === codes.dot || + asciiAlphanumeric(code) + ) { + // Count the previous alphabetical from `open` too. + size = 1 + return schemeInsideOrEmailAtext(code) + } + + return emailAtext(code) + } + + /** + * In ambiguous protocol or atext. + * + * ```markdown + * > | ab + * ^ + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function schemeInsideOrEmailAtext(code) { + if (code === codes.colon) { + effects.consume(code) + size = 0 + return urlInside + } + + // ASCII alphanumeric and `+`, `-`, and `.`. + if ( + (code === codes.plusSign || + code === codes.dash || + code === codes.dot || + asciiAlphanumeric(code)) && + size++ < constants.autolinkSchemeSizeMax + ) { + effects.consume(code) + return schemeInsideOrEmailAtext + } + + size = 0 + return emailAtext(code) + } + + /** + * After protocol, in URL. + * + * ```markdown + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function urlInside(code) { + if (code === codes.greaterThan) { + effects.exit(types.autolinkProtocol) + effects.enter(types.autolinkMarker) + effects.consume(code) + effects.exit(types.autolinkMarker) + effects.exit(types.autolink) + return ok + } + + // ASCII control, space, or `<`. + if ( + code === codes.eof || + code === codes.space || + code === codes.lessThan || + asciiControl(code) + ) { + return nok(code) + } + + effects.consume(code) + return urlInside + } + + /** + * In email atext. + * + * ```markdown + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function emailAtext(code) { + if (code === codes.atSign) { + effects.consume(code) + return emailAtSignOrDot + } + + if (asciiAtext(code)) { + effects.consume(code) + return emailAtext + } + + return nok(code) + } + + /** + * In label, after at-sign or dot. + * + * ```markdown + * > | ab + * ^ ^ + * ``` + * + * @type {State} + */ + function emailAtSignOrDot(code) { + return asciiAlphanumeric(code) ? emailLabel(code) : nok(code) + } + + /** + * In label, where `.` and `>` are allowed. + * + * ```markdown + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function emailLabel(code) { + if (code === codes.dot) { + effects.consume(code) + size = 0 + return emailAtSignOrDot + } + + if (code === codes.greaterThan) { + // Exit, then change the token type. + effects.exit(types.autolinkProtocol).type = types.autolinkEmail + effects.enter(types.autolinkMarker) + effects.consume(code) + effects.exit(types.autolinkMarker) + effects.exit(types.autolink) + return ok + } + + return emailValue(code) + } + + /** + * In label, where `.` and `>` are *not* allowed. + * + * Though, this is also used in `emailLabel` to parse other values. + * + * ```markdown + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function emailValue(code) { + // ASCII alphanumeric or `-`. + if ( + (code === codes.dash || asciiAlphanumeric(code)) && + size++ < constants.autolinkDomainSizeMax + ) { + const next = code === codes.dash ? emailValue : emailLabel + effects.consume(code) + return next + } + + return nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/blank-line.d.ts b/node_modules/micromark-core-commonmark/dev/lib/blank-line.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..7a8deca617ee590e8028a5a3caec897d6c5b44d6 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/blank-line.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const blankLine: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=blank-line.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/blank-line.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/blank-line.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..f12302d76e6834ec78fb367b18810cba19273ce7 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/blank-line.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"blank-line.d.ts","sourceRoot":"","sources":["blank-line.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,wBADW,SAAS,CACiD;+BAR3D,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/blank-line.js b/node_modules/micromark-core-commonmark/dev/lib/blank-line.js new file mode 100644 index 0000000000000000000000000000000000000000..db9c817fbd48733f7c8e68cd9c3ded56ac4c4443 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/blank-line.js @@ -0,0 +1,62 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {factorySpace} from 'micromark-factory-space' +import {markdownLineEnding, markdownSpace} from 'micromark-util-character' +import {codes, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const blankLine = {partial: true, tokenize: tokenizeBlankLine} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeBlankLine(effects, ok, nok) { + return start + + /** + * Start of blank line. + * + * > 👉 **Note**: `␠` represents a space character. + * + * ```markdown + * > | ␠␠␊ + * ^ + * > | ␊ + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + return markdownSpace(code) + ? factorySpace(effects, after, types.linePrefix)(code) + : after(code) + } + + /** + * At eof/eol, after optional whitespace. + * + * > 👉 **Note**: `␠` represents a space character. + * + * ```markdown + * > | ␠␠␊ + * ^ + * > | ␊ + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + return code === codes.eof || markdownLineEnding(code) ? ok(code) : nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/block-quote.d.ts b/node_modules/micromark-core-commonmark/dev/lib/block-quote.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..bf91ff18e8eb3339cbeeda55b8e3a1a2875cddfa --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/block-quote.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const blockQuote: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=block-quote.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/block-quote.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/block-quote.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b19ef02032e9d309cd3b3b73a696e968e77f916e --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/block-quote.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"block-quote.d.ts","sourceRoot":"","sources":["block-quote.js"],"names":[],"mappings":"AAeA,wBAAwB;AACxB,yBADW,SAAS,CAMnB;+BAdS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/block-quote.js b/node_modules/micromark-core-commonmark/dev/lib/block-quote.js new file mode 100644 index 0000000000000000000000000000000000000000..cc4565d42e9ea883976a0ba3fb40054e2aded2b4 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/block-quote.js @@ -0,0 +1,162 @@ +/** + * @import { + * Construct, + * Exiter, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import {markdownSpace} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const blockQuote = { + continuation: {tokenize: tokenizeBlockQuoteContinuation}, + exit, + name: 'blockQuote', + tokenize: tokenizeBlockQuoteStart +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeBlockQuoteStart(effects, ok, nok) { + const self = this + + return start + + /** + * Start of block quote. + * + * ```markdown + * > | > a + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + if (code === codes.greaterThan) { + const state = self.containerState + + assert(state, 'expected `containerState` to be defined in container') + + if (!state.open) { + effects.enter(types.blockQuote, {_container: true}) + state.open = true + } + + effects.enter(types.blockQuotePrefix) + effects.enter(types.blockQuoteMarker) + effects.consume(code) + effects.exit(types.blockQuoteMarker) + return after + } + + return nok(code) + } + + /** + * After `>`, before optional whitespace. + * + * ```markdown + * > | > a + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + if (markdownSpace(code)) { + effects.enter(types.blockQuotePrefixWhitespace) + effects.consume(code) + effects.exit(types.blockQuotePrefixWhitespace) + effects.exit(types.blockQuotePrefix) + return ok + } + + effects.exit(types.blockQuotePrefix) + return ok(code) + } +} + +/** + * Start of block quote continuation. + * + * ```markdown + * | > a + * > | > b + * ^ + * ``` + * + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeBlockQuoteContinuation(effects, ok, nok) { + const self = this + + return contStart + + /** + * Start of block quote continuation. + * + * Also used to parse the first block quote opening. + * + * ```markdown + * | > a + * > | > b + * ^ + * ``` + * + * @type {State} + */ + function contStart(code) { + if (markdownSpace(code)) { + // Always populated by defaults. + assert( + self.parser.constructs.disable.null, + 'expected `disable.null` to be populated' + ) + + return factorySpace( + effects, + contBefore, + types.linePrefix, + self.parser.constructs.disable.null.includes('codeIndented') + ? undefined + : constants.tabSize + )(code) + } + + return contBefore(code) + } + + /** + * At `>`, after optional whitespace. + * + * Also used to parse the first block quote opening. + * + * ```markdown + * | > a + * > | > b + * ^ + * ``` + * + * @type {State} + */ + function contBefore(code) { + return effects.attempt(blockQuote, ok, nok)(code) + } +} + +/** @type {Exiter} */ +function exit(effects) { + effects.exit(types.blockQuote) +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/character-escape.d.ts b/node_modules/micromark-core-commonmark/dev/lib/character-escape.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c61455e85f343e3acf8814d17091943e638f33d5 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/character-escape.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const characterEscape: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=character-escape.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/character-escape.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/character-escape.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..e5ec56e148a65da3a2eae240e2502f900ec3e33b --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/character-escape.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"character-escape.d.ts","sourceRoot":"","sources":["character-escape.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,8BADW,SAAS,CAInB;+BAXS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/character-escape.js b/node_modules/micromark-core-commonmark/dev/lib/character-escape.js new file mode 100644 index 0000000000000000000000000000000000000000..1604cfaa364fcd64f953eff4d0680397702ee1af --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/character-escape.js @@ -0,0 +1,69 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {asciiPunctuation} from 'micromark-util-character' +import {codes, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const characterEscape = { + name: 'characterEscape', + tokenize: tokenizeCharacterEscape +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCharacterEscape(effects, ok, nok) { + return start + + /** + * Start of character escape. + * + * ```markdown + * > | a\*b + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.backslash, 'expected `\\`') + effects.enter(types.characterEscape) + effects.enter(types.escapeMarker) + effects.consume(code) + effects.exit(types.escapeMarker) + return inside + } + + /** + * After `\`, at punctuation. + * + * ```markdown + * > | a\*b + * ^ + * ``` + * + * @type {State} + */ + function inside(code) { + // ASCII punctuation. + if (asciiPunctuation(code)) { + effects.enter(types.characterEscapeValue) + effects.consume(code) + effects.exit(types.characterEscapeValue) + effects.exit(types.characterEscape) + return ok + } + + return nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/character-reference.d.ts b/node_modules/micromark-core-commonmark/dev/lib/character-reference.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..554fe30dbbb2ccee8dfeb83680019154a5f2ac99 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/character-reference.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const characterReference: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=character-reference.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/character-reference.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/character-reference.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..dd03537d5ff767aaa06234517251c6d536c2f057 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/character-reference.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"character-reference.d.ts","sourceRoot":"","sources":["character-reference.js"],"names":[],"mappings":"AAmBA,wBAAwB;AACxB,iCADW,SAAS,CAInB;+BAhBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/character-reference.js b/node_modules/micromark-core-commonmark/dev/lib/character-reference.js new file mode 100644 index 0000000000000000000000000000000000000000..a7091b0dc8ecd7a84eb295fd9e16586fd27b4ebe --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/character-reference.js @@ -0,0 +1,166 @@ +/** + * @import { + * Code, + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {decodeNamedCharacterReference} from 'decode-named-character-reference' +import { + asciiAlphanumeric, + asciiDigit, + asciiHexDigit +} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const characterReference = { + name: 'characterReference', + tokenize: tokenizeCharacterReference +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCharacterReference(effects, ok, nok) { + const self = this + let size = 0 + /** @type {number} */ + let max + /** @type {(code: Code) => boolean} */ + let test + + return start + + /** + * Start of character reference. + * + * ```markdown + * > | a&b + * ^ + * > | a{b + * ^ + * > | a b + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.ampersand, 'expected `&`') + effects.enter(types.characterReference) + effects.enter(types.characterReferenceMarker) + effects.consume(code) + effects.exit(types.characterReferenceMarker) + return open + } + + /** + * After `&`, at `#` for numeric references or alphanumeric for named + * references. + * + * ```markdown + * > | a&b + * ^ + * > | a{b + * ^ + * > | a b + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (code === codes.numberSign) { + effects.enter(types.characterReferenceMarkerNumeric) + effects.consume(code) + effects.exit(types.characterReferenceMarkerNumeric) + return numeric + } + + effects.enter(types.characterReferenceValue) + max = constants.characterReferenceNamedSizeMax + test = asciiAlphanumeric + return value(code) + } + + /** + * After `#`, at `x` for hexadecimals or digit for decimals. + * + * ```markdown + * > | a{b + * ^ + * > | a b + * ^ + * ``` + * + * @type {State} + */ + function numeric(code) { + if (code === codes.uppercaseX || code === codes.lowercaseX) { + effects.enter(types.characterReferenceMarkerHexadecimal) + effects.consume(code) + effects.exit(types.characterReferenceMarkerHexadecimal) + effects.enter(types.characterReferenceValue) + max = constants.characterReferenceHexadecimalSizeMax + test = asciiHexDigit + return value + } + + effects.enter(types.characterReferenceValue) + max = constants.characterReferenceDecimalSizeMax + test = asciiDigit + return value(code) + } + + /** + * After markers (`&#x`, `&#`, or `&`), in value, before `;`. + * + * The character reference kind defines what and how many characters are + * allowed. + * + * ```markdown + * > | a&b + * ^^^ + * > | a{b + * ^^^ + * > | a b + * ^ + * ``` + * + * @type {State} + */ + function value(code) { + if (code === codes.semicolon && size) { + const token = effects.exit(types.characterReferenceValue) + + if ( + test === asciiAlphanumeric && + !decodeNamedCharacterReference(self.sliceSerialize(token)) + ) { + return nok(code) + } + + // To do: `markdown-rs` uses a different name: + // `CharacterReferenceMarkerSemi`. + effects.enter(types.characterReferenceMarker) + effects.consume(code) + effects.exit(types.characterReferenceMarker) + effects.exit(types.characterReference) + return ok + } + + if (test(code) && size++ < max) { + effects.consume(code) + return value + } + + return nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-fenced.d.ts b/node_modules/micromark-core-commonmark/dev/lib/code-fenced.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..6d5f5320e90c09fc3b7e2a2b3c8748a7434aa64d --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-fenced.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const codeFenced: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=code-fenced.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-fenced.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/code-fenced.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b0c28b2d96aa42605169d38e45403610eedd7f50 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-fenced.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"code-fenced.d.ts","sourceRoot":"","sources":["code-fenced.js"],"names":[],"mappings":"AAqBA,wBAAwB;AACxB,yBADW,SAAS,CAKnB;+BAnBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-fenced.js b/node_modules/micromark-core-commonmark/dev/lib/code-fenced.js new file mode 100644 index 0000000000000000000000000000000000000000..b3e6f513886dab1d197d1b6c7956852a48ab7ba1 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-fenced.js @@ -0,0 +1,514 @@ +/** + * @import { + * Code, + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import {markdownLineEnding, markdownSpace} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +const nonLazyContinuation = { + partial: true, + tokenize: tokenizeNonLazyContinuation +} + +/** @type {Construct} */ +export const codeFenced = { + concrete: true, + name: 'codeFenced', + tokenize: tokenizeCodeFenced +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCodeFenced(effects, ok, nok) { + const self = this + /** @type {Construct} */ + const closeStart = {partial: true, tokenize: tokenizeCloseStart} + let initialPrefix = 0 + let sizeOpen = 0 + /** @type {NonNullable} */ + let marker + + return start + + /** + * Start of code. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function start(code) { + // To do: parse whitespace like `markdown-rs`. + return beforeSequenceOpen(code) + } + + /** + * In opening fence, after prefix, at sequence. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function beforeSequenceOpen(code) { + assert( + code === codes.graveAccent || code === codes.tilde, + 'expected `` ` `` or `~`' + ) + + const tail = self.events[self.events.length - 1] + initialPrefix = + tail && tail[1].type === types.linePrefix + ? tail[2].sliceSerialize(tail[1], true).length + : 0 + + marker = code + effects.enter(types.codeFenced) + effects.enter(types.codeFencedFence) + effects.enter(types.codeFencedFenceSequence) + return sequenceOpen(code) + } + + /** + * In opening fence sequence. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function sequenceOpen(code) { + if (code === marker) { + sizeOpen++ + effects.consume(code) + return sequenceOpen + } + + if (sizeOpen < constants.codeFencedSequenceSizeMin) { + return nok(code) + } + + effects.exit(types.codeFencedFenceSequence) + return markdownSpace(code) + ? factorySpace(effects, infoBefore, types.whitespace)(code) + : infoBefore(code) + } + + /** + * In opening fence, after the sequence (and optional whitespace), before info. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function infoBefore(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.codeFencedFence) + return self.interrupt + ? ok(code) + : effects.check(nonLazyContinuation, atNonLazyBreak, after)(code) + } + + effects.enter(types.codeFencedFenceInfo) + effects.enter(types.chunkString, {contentType: constants.contentTypeString}) + return info(code) + } + + /** + * In info. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function info(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.chunkString) + effects.exit(types.codeFencedFenceInfo) + return infoBefore(code) + } + + if (markdownSpace(code)) { + effects.exit(types.chunkString) + effects.exit(types.codeFencedFenceInfo) + return factorySpace(effects, metaBefore, types.whitespace)(code) + } + + if (code === codes.graveAccent && code === marker) { + return nok(code) + } + + effects.consume(code) + return info + } + + /** + * In opening fence, after info and whitespace, before meta. + * + * ```markdown + * > | ~~~js eval + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function metaBefore(code) { + if (code === codes.eof || markdownLineEnding(code)) { + return infoBefore(code) + } + + effects.enter(types.codeFencedFenceMeta) + effects.enter(types.chunkString, {contentType: constants.contentTypeString}) + return meta(code) + } + + /** + * In meta. + * + * ```markdown + * > | ~~~js eval + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function meta(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.chunkString) + effects.exit(types.codeFencedFenceMeta) + return infoBefore(code) + } + + if (code === codes.graveAccent && code === marker) { + return nok(code) + } + + effects.consume(code) + return meta + } + + /** + * At eol/eof in code, before a non-lazy closing fence or content. + * + * ```markdown + * > | ~~~js + * ^ + * > | alert(1) + * ^ + * | ~~~ + * ``` + * + * @type {State} + */ + function atNonLazyBreak(code) { + assert(markdownLineEnding(code), 'expected eol') + return effects.attempt(closeStart, after, contentBefore)(code) + } + + /** + * Before code content, not a closing fence, at eol. + * + * ```markdown + * | ~~~js + * > | alert(1) + * ^ + * | ~~~ + * ``` + * + * @type {State} + */ + function contentBefore(code) { + assert(markdownLineEnding(code), 'expected eol') + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return contentStart + } + + /** + * Before code content, not a closing fence. + * + * ```markdown + * | ~~~js + * > | alert(1) + * ^ + * | ~~~ + * ``` + * + * @type {State} + */ + function contentStart(code) { + return initialPrefix > 0 && markdownSpace(code) + ? factorySpace( + effects, + beforeContentChunk, + types.linePrefix, + initialPrefix + 1 + )(code) + : beforeContentChunk(code) + } + + /** + * Before code content, after optional prefix. + * + * ```markdown + * | ~~~js + * > | alert(1) + * ^ + * | ~~~ + * ``` + * + * @type {State} + */ + function beforeContentChunk(code) { + if (code === codes.eof || markdownLineEnding(code)) { + return effects.check(nonLazyContinuation, atNonLazyBreak, after)(code) + } + + effects.enter(types.codeFlowValue) + return contentChunk(code) + } + + /** + * In code content. + * + * ```markdown + * | ~~~js + * > | alert(1) + * ^^^^^^^^ + * | ~~~ + * ``` + * + * @type {State} + */ + function contentChunk(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.codeFlowValue) + return beforeContentChunk(code) + } + + effects.consume(code) + return contentChunk + } + + /** + * After code. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + effects.exit(types.codeFenced) + return ok(code) + } + + /** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ + function tokenizeCloseStart(effects, ok, nok) { + let size = 0 + + return startBefore + + /** + * + * + * @type {State} + */ + function startBefore(code) { + assert(markdownLineEnding(code), 'expected eol') + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return start + } + + /** + * Before closing fence, at optional whitespace. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // Always populated by defaults. + assert( + self.parser.constructs.disable.null, + 'expected `disable.null` to be populated' + ) + + // To do: `enter` here or in next state? + effects.enter(types.codeFencedFence) + return markdownSpace(code) + ? factorySpace( + effects, + beforeSequenceClose, + types.linePrefix, + self.parser.constructs.disable.null.includes('codeIndented') + ? undefined + : constants.tabSize + )(code) + : beforeSequenceClose(code) + } + + /** + * In closing fence, after optional whitespace, at sequence. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function beforeSequenceClose(code) { + if (code === marker) { + effects.enter(types.codeFencedFenceSequence) + return sequenceClose(code) + } + + return nok(code) + } + + /** + * In closing fence sequence. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function sequenceClose(code) { + if (code === marker) { + size++ + effects.consume(code) + return sequenceClose + } + + if (size >= sizeOpen) { + effects.exit(types.codeFencedFenceSequence) + return markdownSpace(code) + ? factorySpace(effects, sequenceCloseAfter, types.whitespace)(code) + : sequenceCloseAfter(code) + } + + return nok(code) + } + + /** + * After closing fence sequence, after optional whitespace. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function sequenceCloseAfter(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.codeFencedFence) + return ok(code) + } + + return nok(code) + } + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeNonLazyContinuation(effects, ok, nok) { + const self = this + + return start + + /** + * + * + * @type {State} + */ + function start(code) { + if (code === codes.eof) { + return nok(code) + } + + assert(markdownLineEnding(code), 'expected eol') + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return lineStart + } + + /** + * + * + * @type {State} + */ + function lineStart(code) { + return self.parser.lazy[self.now().line] ? nok(code) : ok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-indented.d.ts b/node_modules/micromark-core-commonmark/dev/lib/code-indented.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c06578bab6c0f9f73a7b88e3ee260db52ca5fa4 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-indented.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const codeIndented: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=code-indented.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-indented.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/code-indented.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..099be93959e1da2e65f4924ed2b38877c736b22a --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-indented.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"code-indented.d.ts","sourceRoot":"","sources":["code-indented.js"],"names":[],"mappings":"AAcA,wBAAwB;AACxB,2BADW,SAAS,CAInB;+BAZS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-indented.js b/node_modules/micromark-core-commonmark/dev/lib/code-indented.js new file mode 100644 index 0000000000000000000000000000000000000000..05e27f6ef812b8fe7cb5587238bff0c56665c660 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-indented.js @@ -0,0 +1,202 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import {markdownLineEnding, markdownSpace} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const codeIndented = { + name: 'codeIndented', + tokenize: tokenizeCodeIndented +} + +/** @type {Construct} */ +const furtherStart = {partial: true, tokenize: tokenizeFurtherStart} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCodeIndented(effects, ok, nok) { + const self = this + return start + + /** + * Start of code (indented). + * + * > **Parsing note**: it is not needed to check if this first line is a + * > filled line (that it has a non-whitespace character), because blank lines + * > are parsed already, so we never run into that. + * + * ```markdown + * > | aaa + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // To do: manually check if interrupting like `markdown-rs`. + assert(markdownSpace(code)) + effects.enter(types.codeIndented) + // To do: use an improved `space_or_tab` function like `markdown-rs`, + // so that we can drop the next state. + return factorySpace( + effects, + afterPrefix, + types.linePrefix, + constants.tabSize + 1 + )(code) + } + + /** + * At start, after 1 or 4 spaces. + * + * ```markdown + * > | aaa + * ^ + * ``` + * + * @type {State} + */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1] + return tail && + tail[1].type === types.linePrefix && + tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize + ? atBreak(code) + : nok(code) + } + + /** + * At a break. + * + * ```markdown + * > | aaa + * ^ ^ + * ``` + * + * @type {State} + */ + function atBreak(code) { + if (code === codes.eof) { + return after(code) + } + + if (markdownLineEnding(code)) { + return effects.attempt(furtherStart, atBreak, after)(code) + } + + effects.enter(types.codeFlowValue) + return inside(code) + } + + /** + * In code content. + * + * ```markdown + * > | aaa + * ^^^^ + * ``` + * + * @type {State} + */ + function inside(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.codeFlowValue) + return atBreak(code) + } + + effects.consume(code) + return inside + } + + /** @type {State} */ + function after(code) { + effects.exit(types.codeIndented) + // To do: allow interrupting like `markdown-rs`. + // Feel free to interrupt. + // tokenizer.interrupt = false + return ok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeFurtherStart(effects, ok, nok) { + const self = this + + return furtherStart + + /** + * At eol, trying to parse another indent. + * + * ```markdown + * > | aaa + * ^ + * | bbb + * ``` + * + * @type {State} + */ + function furtherStart(code) { + // To do: improve `lazy` / `pierce` handling. + // If this is a lazy line, it can’t be code. + if (self.parser.lazy[self.now().line]) { + return nok(code) + } + + if (markdownLineEnding(code)) { + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return furtherStart + } + + // To do: the code here in `micromark-js` is a bit different from + // `markdown-rs` because there it can attempt spaces. + // We can’t yet. + // + // To do: use an improved `space_or_tab` function like `markdown-rs`, + // so that we can drop the next state. + return factorySpace( + effects, + afterPrefix, + types.linePrefix, + constants.tabSize + 1 + )(code) + } + + /** + * At start, after 1 or 4 spaces. + * + * ```markdown + * > | aaa + * ^ + * ``` + * + * @type {State} + */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1] + return tail && + tail[1].type === types.linePrefix && + tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize + ? ok(code) + : markdownLineEnding(code) + ? furtherStart(code) + : nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-text.d.ts b/node_modules/micromark-core-commonmark/dev/lib/code-text.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8047b2c2204dcc2fc21094b69a06ba36881fc3fb --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-text.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const codeText: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=code-text.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-text.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/code-text.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..d5558209fb9b70b3beeee714341631158163311a --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-text.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"code-text.d.ts","sourceRoot":"","sources":["code-text.js"],"names":[],"mappings":"AAgBA,wBAAwB;AACxB,uBADW,SAAS,CAMnB;+BAbS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/code-text.js b/node_modules/micromark-core-commonmark/dev/lib/code-text.js new file mode 100644 index 0000000000000000000000000000000000000000..0f4096f7ba7d24f5e6e82cb31b55aaf7df80acd4 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/code-text.js @@ -0,0 +1,257 @@ +/** + * @import { + * Construct, + * Previous, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {markdownLineEnding} from 'micromark-util-character' +import {codes, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const codeText = { + name: 'codeText', + previous, + resolve: resolveCodeText, + tokenize: tokenizeCodeText +} + +// To do: next major: don’t resolve, like `markdown-rs`. +/** @type {Resolver} */ +function resolveCodeText(events) { + let tailExitIndex = events.length - 4 + let headEnterIndex = 3 + /** @type {number} */ + let index + /** @type {number | undefined} */ + let enter + + // If we start and end with an EOL or a space. + if ( + (events[headEnterIndex][1].type === types.lineEnding || + events[headEnterIndex][1].type === 'space') && + (events[tailExitIndex][1].type === types.lineEnding || + events[tailExitIndex][1].type === 'space') + ) { + index = headEnterIndex + + // And we have data. + while (++index < tailExitIndex) { + if (events[index][1].type === types.codeTextData) { + // Then we have padding. + events[headEnterIndex][1].type = types.codeTextPadding + events[tailExitIndex][1].type = types.codeTextPadding + headEnterIndex += 2 + tailExitIndex -= 2 + break + } + } + } + + // Merge adjacent spaces and data. + index = headEnterIndex - 1 + tailExitIndex++ + + while (++index <= tailExitIndex) { + if (enter === undefined) { + if ( + index !== tailExitIndex && + events[index][1].type !== types.lineEnding + ) { + enter = index + } + } else if ( + index === tailExitIndex || + events[index][1].type === types.lineEnding + ) { + events[enter][1].type = types.codeTextData + + if (index !== enter + 2) { + events[enter][1].end = events[index - 1][1].end + events.splice(enter + 2, index - enter - 2) + tailExitIndex -= index - enter - 2 + index = enter + 2 + } + + enter = undefined + } + } + + return events +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Previous} + */ +function previous(code) { + // If there is a previous code, there will always be a tail. + return ( + code !== codes.graveAccent || + this.events[this.events.length - 1][1].type === types.characterEscape + ) +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCodeText(effects, ok, nok) { + const self = this + let sizeOpen = 0 + /** @type {number} */ + let size + /** @type {Token} */ + let token + + return start + + /** + * Start of code (text). + * + * ```markdown + * > | `a` + * ^ + * > | \`a` + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.graveAccent, 'expected `` ` ``') + assert(previous.call(self, self.previous), 'expected correct previous') + effects.enter(types.codeText) + effects.enter(types.codeTextSequence) + return sequenceOpen(code) + } + + /** + * In opening sequence. + * + * ```markdown + * > | `a` + * ^ + * ``` + * + * @type {State} + */ + function sequenceOpen(code) { + if (code === codes.graveAccent) { + effects.consume(code) + sizeOpen++ + return sequenceOpen + } + + effects.exit(types.codeTextSequence) + return between(code) + } + + /** + * Between something and something else. + * + * ```markdown + * > | `a` + * ^^ + * ``` + * + * @type {State} + */ + function between(code) { + // EOF. + if (code === codes.eof) { + return nok(code) + } + + // To do: next major: don’t do spaces in resolve, but when compiling, + // like `markdown-rs`. + // Tabs don’t work, and virtual spaces don’t make sense. + if (code === codes.space) { + effects.enter('space') + effects.consume(code) + effects.exit('space') + return between + } + + // Closing fence? Could also be data. + if (code === codes.graveAccent) { + token = effects.enter(types.codeTextSequence) + size = 0 + return sequenceClose(code) + } + + if (markdownLineEnding(code)) { + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return between + } + + // Data. + effects.enter(types.codeTextData) + return data(code) + } + + /** + * In data. + * + * ```markdown + * > | `a` + * ^ + * ``` + * + * @type {State} + */ + function data(code) { + if ( + code === codes.eof || + code === codes.space || + code === codes.graveAccent || + markdownLineEnding(code) + ) { + effects.exit(types.codeTextData) + return between(code) + } + + effects.consume(code) + return data + } + + /** + * In closing sequence. + * + * ```markdown + * > | `a` + * ^ + * ``` + * + * @type {State} + */ + function sequenceClose(code) { + // More. + if (code === codes.graveAccent) { + effects.consume(code) + size++ + return sequenceClose + } + + // Done! + if (size === sizeOpen) { + effects.exit(types.codeTextSequence) + effects.exit(types.codeText) + return ok(code) + } + + // More or less accents: mark as data. + token.type = types.codeTextData + return data(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/content.d.ts b/node_modules/micromark-core-commonmark/dev/lib/content.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..eec537f9fdae61cfeefbff08e8211eed56228381 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/content.d.ts @@ -0,0 +1,7 @@ +/** + * No name because it must not be turned off. + * @type {Construct} + */ +export const content: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=content.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/content.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/content.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..04ed7089749a041b50aa38f1ab4e94589ebed860 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/content.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["content.js"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,sBAFU,SAAS,CAEwD;+BAbjE,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/content.js b/node_modules/micromark-core-commonmark/dev/lib/content.js new file mode 100644 index 0000000000000000000000000000000000000000..4d0c424558c687291ced50723bb3472742556c90 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/content.js @@ -0,0 +1,185 @@ +/** + * @import { + * Construct, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import {markdownLineEnding} from 'micromark-util-character' +import {subtokenize} from 'micromark-util-subtokenize' +import {codes, constants, types} from 'micromark-util-symbol' + +/** + * No name because it must not be turned off. + * @type {Construct} + */ +export const content = {resolve: resolveContent, tokenize: tokenizeContent} + +/** @type {Construct} */ +const continuationConstruct = {partial: true, tokenize: tokenizeContinuation} + +/** + * Content is transparent: it’s parsed right now. That way, definitions are also + * parsed right now: before text in paragraphs (specifically, media) are parsed. + * + * @type {Resolver} + */ +function resolveContent(events) { + subtokenize(events) + return events +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeContent(effects, ok) { + /** @type {Token | undefined} */ + let previous + + return chunkStart + + /** + * Before a content chunk. + * + * ```markdown + * > | abc + * ^ + * ``` + * + * @type {State} + */ + function chunkStart(code) { + assert( + code !== codes.eof && !markdownLineEnding(code), + 'expected no eof or eol' + ) + + effects.enter(types.content) + previous = effects.enter(types.chunkContent, { + contentType: constants.contentTypeContent + }) + return chunkInside(code) + } + + /** + * In a content chunk. + * + * ```markdown + * > | abc + * ^^^ + * ``` + * + * @type {State} + */ + function chunkInside(code) { + if (code === codes.eof) { + return contentEnd(code) + } + + // To do: in `markdown-rs`, each line is parsed on its own, and everything + // is stitched together resolving. + if (markdownLineEnding(code)) { + return effects.check( + continuationConstruct, + contentContinue, + contentEnd + )(code) + } + + // Data. + effects.consume(code) + return chunkInside + } + + /** + * + * + * @type {State} + */ + function contentEnd(code) { + effects.exit(types.chunkContent) + effects.exit(types.content) + return ok(code) + } + + /** + * + * + * @type {State} + */ + function contentContinue(code) { + assert(markdownLineEnding(code), 'expected eol') + effects.consume(code) + effects.exit(types.chunkContent) + assert(previous, 'expected previous token') + previous.next = effects.enter(types.chunkContent, { + contentType: constants.contentTypeContent, + previous + }) + previous = previous.next + return chunkInside + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeContinuation(effects, ok, nok) { + const self = this + + return startLookahead + + /** + * + * + * @type {State} + */ + function startLookahead(code) { + assert(markdownLineEnding(code), 'expected a line ending') + effects.exit(types.chunkContent) + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return factorySpace(effects, prefixed, types.linePrefix) + } + + /** + * + * + * @type {State} + */ + function prefixed(code) { + if (code === codes.eof || markdownLineEnding(code)) { + return nok(code) + } + + // Always populated by defaults. + assert( + self.parser.constructs.disable.null, + 'expected `disable.null` to be populated' + ) + + const tail = self.events[self.events.length - 1] + + if ( + !self.parser.constructs.disable.null.includes('codeIndented') && + tail && + tail[1].type === types.linePrefix && + tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize + ) { + return ok(code) + } + + return effects.interrupt(self.parser.constructs.flow, nok, ok)(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/definition.d.ts b/node_modules/micromark-core-commonmark/dev/lib/definition.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f5a46930596f28abf7c913481080928e132a4ae0 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/definition.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const definition: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=definition.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/definition.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/definition.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..46a16d3ad245346b876d819a8c326ce0d6da5d43 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/definition.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["definition.js"],"names":[],"mappings":"AAuBA,wBAAwB;AACxB,yBADW,SAAS,CACwD;+BAlBlE,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/definition.js b/node_modules/micromark-core-commonmark/dev/lib/definition.js new file mode 100644 index 0000000000000000000000000000000000000000..9df859cf6345997ddbf1631ab02facb650aa33d3 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/definition.js @@ -0,0 +1,295 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factoryDestination} from 'micromark-factory-destination' +import {factoryLabel} from 'micromark-factory-label' +import {factorySpace} from 'micromark-factory-space' +import {factoryTitle} from 'micromark-factory-title' +import {factoryWhitespace} from 'micromark-factory-whitespace' +import { + markdownLineEndingOrSpace, + markdownLineEnding, + markdownSpace +} from 'micromark-util-character' +import {normalizeIdentifier} from 'micromark-util-normalize-identifier' +import {codes, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const definition = {name: 'definition', tokenize: tokenizeDefinition} + +/** @type {Construct} */ +const titleBefore = {partial: true, tokenize: tokenizeTitleBefore} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeDefinition(effects, ok, nok) { + const self = this + /** @type {string} */ + let identifier + + return start + + /** + * At start of a definition. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // Do not interrupt paragraphs (but do follow definitions). + // To do: do `interrupt` the way `markdown-rs` does. + // To do: parse whitespace the way `markdown-rs` does. + effects.enter(types.definition) + return before(code) + } + + /** + * After optional whitespace, at `[`. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + // To do: parse whitespace the way `markdown-rs` does. + assert(code === codes.leftSquareBracket, 'expected `[`') + return factoryLabel.call( + self, + effects, + labelAfter, + // Note: we don’t need to reset the way `markdown-rs` does. + nok, + types.definitionLabel, + types.definitionLabelMarker, + types.definitionLabelString + )(code) + } + + /** + * After label. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function labelAfter(code) { + identifier = normalizeIdentifier( + self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1) + ) + + if (code === codes.colon) { + effects.enter(types.definitionMarker) + effects.consume(code) + effects.exit(types.definitionMarker) + return markerAfter + } + + return nok(code) + } + + /** + * After marker. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function markerAfter(code) { + // Note: whitespace is optional. + return markdownLineEndingOrSpace(code) + ? factoryWhitespace(effects, destinationBefore)(code) + : destinationBefore(code) + } + + /** + * Before destination. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function destinationBefore(code) { + return factoryDestination( + effects, + destinationAfter, + // Note: we don’t need to reset the way `markdown-rs` does. + nok, + types.definitionDestination, + types.definitionDestinationLiteral, + types.definitionDestinationLiteralMarker, + types.definitionDestinationRaw, + types.definitionDestinationString + )(code) + } + + /** + * After destination. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function destinationAfter(code) { + return effects.attempt(titleBefore, after, after)(code) + } + + /** + * After definition. + * + * ```markdown + * > | [a]: b + * ^ + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + return markdownSpace(code) + ? factorySpace(effects, afterWhitespace, types.whitespace)(code) + : afterWhitespace(code) + } + + /** + * After definition, after optional whitespace. + * + * ```markdown + * > | [a]: b + * ^ + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function afterWhitespace(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.definition) + + // Note: we don’t care about uniqueness. + // It’s likely that that doesn’t happen very frequently. + // It is more likely that it wastes precious time. + self.parser.defined.push(identifier) + + // To do: `markdown-rs` interrupt. + // // You’d be interrupting. + // tokenizer.interrupt = true + return ok(code) + } + + return nok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeTitleBefore(effects, ok, nok) { + return titleBefore + + /** + * After destination, at whitespace. + * + * ```markdown + * > | [a]: b + * ^ + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function titleBefore(code) { + return markdownLineEndingOrSpace(code) + ? factoryWhitespace(effects, beforeMarker)(code) + : nok(code) + } + + /** + * At title. + * + * ```markdown + * | [a]: b + * > | "c" + * ^ + * ``` + * + * @type {State} + */ + function beforeMarker(code) { + return factoryTitle( + effects, + titleAfter, + nok, + types.definitionTitle, + types.definitionTitleMarker, + types.definitionTitleString + )(code) + } + + /** + * After title. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function titleAfter(code) { + return markdownSpace(code) + ? factorySpace( + effects, + titleAfterOptionalWhitespace, + types.whitespace + )(code) + : titleAfterOptionalWhitespace(code) + } + + /** + * After title, after optional whitespace. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function titleAfterOptionalWhitespace(code) { + return code === codes.eof || markdownLineEnding(code) ? ok(code) : nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.d.ts b/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..eff01b324e2a82400b61eaecc7c842f6f8765865 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const hardBreakEscape: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=hard-break-escape.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..923753ce13d86326b96e42e9de1a5674fbad0deb --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"hard-break-escape.d.ts","sourceRoot":"","sources":["hard-break-escape.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,8BADW,SAAS,CAInB;+BAXS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.js b/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.js new file mode 100644 index 0000000000000000000000000000000000000000..ac7df7d79141514367f4b124db8f3076cebcd43d --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/hard-break-escape.js @@ -0,0 +1,65 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {markdownLineEnding} from 'micromark-util-character' +import {codes, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const hardBreakEscape = { + name: 'hardBreakEscape', + tokenize: tokenizeHardBreakEscape +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeHardBreakEscape(effects, ok, nok) { + return start + + /** + * Start of a hard break (escape). + * + * ```markdown + * > | a\ + * ^ + * | b + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.backslash, 'expected `\\`') + effects.enter(types.hardBreakEscape) + effects.consume(code) + return after + } + + /** + * After `\`, at eol. + * + * ```markdown + * > | a\ + * ^ + * | b + * ``` + * + * @type {State} + */ + function after(code) { + if (markdownLineEnding(code)) { + effects.exit(types.hardBreakEscape) + return ok(code) + } + + return nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/heading-atx.d.ts b/node_modules/micromark-core-commonmark/dev/lib/heading-atx.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a08353b6c5f1798ffd4e7ea29705a9b07d5ca9db --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/heading-atx.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const headingAtx: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=heading-atx.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/heading-atx.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/heading-atx.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..8c8eebf31f2cfe32ca43e83fba9fc5d24bf786ea --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/heading-atx.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"heading-atx.d.ts","sourceRoot":"","sources":["heading-atx.js"],"names":[],"mappings":"AAqBA,wBAAwB;AACxB,yBADW,SAAS,CAKnB;+BAlBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/heading-atx.js b/node_modules/micromark-core-commonmark/dev/lib/heading-atx.js new file mode 100644 index 0000000000000000000000000000000000000000..744e302f9811781f732af20ba2aa40790f2a0a0b --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/heading-atx.js @@ -0,0 +1,233 @@ +/** + * @import { + * Construct, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import { + markdownLineEndingOrSpace, + markdownLineEnding, + markdownSpace +} from 'micromark-util-character' +import {splice} from 'micromark-util-chunked' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const headingAtx = { + name: 'headingAtx', + resolve: resolveHeadingAtx, + tokenize: tokenizeHeadingAtx +} + +/** @type {Resolver} */ +function resolveHeadingAtx(events, context) { + let contentEnd = events.length - 2 + let contentStart = 3 + /** @type {Token} */ + let content + /** @type {Token} */ + let text + + // Prefix whitespace, part of the opening. + if (events[contentStart][1].type === types.whitespace) { + contentStart += 2 + } + + // Suffix whitespace, part of the closing. + if ( + contentEnd - 2 > contentStart && + events[contentEnd][1].type === types.whitespace + ) { + contentEnd -= 2 + } + + if ( + events[contentEnd][1].type === types.atxHeadingSequence && + (contentStart === contentEnd - 1 || + (contentEnd - 4 > contentStart && + events[contentEnd - 2][1].type === types.whitespace)) + ) { + contentEnd -= contentStart + 1 === contentEnd ? 2 : 4 + } + + if (contentEnd > contentStart) { + content = { + type: types.atxHeadingText, + start: events[contentStart][1].start, + end: events[contentEnd][1].end + } + text = { + type: types.chunkText, + start: events[contentStart][1].start, + end: events[contentEnd][1].end, + contentType: constants.contentTypeText + } + + splice(events, contentStart, contentEnd - contentStart + 1, [ + ['enter', content, context], + ['enter', text, context], + ['exit', text, context], + ['exit', content, context] + ]) + } + + return events +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeHeadingAtx(effects, ok, nok) { + let size = 0 + + return start + + /** + * Start of a heading (atx). + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // To do: parse indent like `markdown-rs`. + effects.enter(types.atxHeading) + return before(code) + } + + /** + * After optional whitespace, at `#`. + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + assert(code === codes.numberSign, 'expected `#`') + effects.enter(types.atxHeadingSequence) + return sequenceOpen(code) + } + + /** + * In opening sequence. + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function sequenceOpen(code) { + if ( + code === codes.numberSign && + size++ < constants.atxHeadingOpeningFenceSizeMax + ) { + effects.consume(code) + return sequenceOpen + } + + // Always at least one `#`. + if (code === codes.eof || markdownLineEndingOrSpace(code)) { + effects.exit(types.atxHeadingSequence) + return atBreak(code) + } + + return nok(code) + } + + /** + * After something, before something else. + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function atBreak(code) { + if (code === codes.numberSign) { + effects.enter(types.atxHeadingSequence) + return sequenceFurther(code) + } + + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.atxHeading) + // To do: interrupt like `markdown-rs`. + // // Feel free to interrupt. + // tokenizer.interrupt = false + return ok(code) + } + + if (markdownSpace(code)) { + return factorySpace(effects, atBreak, types.whitespace)(code) + } + + // To do: generate `data` tokens, add the `text` token later. + // Needs edit map, see: `markdown.rs`. + effects.enter(types.atxHeadingText) + return data(code) + } + + /** + * In further sequence (after whitespace). + * + * Could be normal “visible” hashes in the heading or a final sequence. + * + * ```markdown + * > | ## aa ## + * ^ + * ``` + * + * @type {State} + */ + function sequenceFurther(code) { + if (code === codes.numberSign) { + effects.consume(code) + return sequenceFurther + } + + effects.exit(types.atxHeadingSequence) + return atBreak(code) + } + + /** + * In text. + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function data(code) { + if ( + code === codes.eof || + code === codes.numberSign || + markdownLineEndingOrSpace(code) + ) { + effects.exit(types.atxHeadingText) + return atBreak(code) + } + + effects.consume(code) + return data + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/html-flow.d.ts b/node_modules/micromark-core-commonmark/dev/lib/html-flow.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..83fa70cd1b092c05d7d32527bc43aef4b7c4baa3 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/html-flow.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const htmlFlow: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=html-flow.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/html-flow.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/html-flow.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..1a23a6fde0f60733d2f8ab684f91172a97f1a661 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/html-flow.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"html-flow.d.ts","sourceRoot":"","sources":["html-flow.js"],"names":[],"mappings":"AAuBA,wBAAwB;AACxB,uBADW,SAAS,CAMnB;+BArBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/html-flow.js b/node_modules/micromark-core-commonmark/dev/lib/html-flow.js new file mode 100644 index 0000000000000000000000000000000000000000..254d9e32105c35541659fdafcb80e372f4b6c331 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/html-flow.js @@ -0,0 +1,989 @@ +/** + * @import { + * Code, + * Construct, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import { + asciiAlphanumeric, + asciiAlpha, + markdownLineEndingOrSpace, + markdownLineEnding, + markdownSpace +} from 'micromark-util-character' +import {htmlBlockNames, htmlRawNames} from 'micromark-util-html-tag-name' +import {codes, constants, types} from 'micromark-util-symbol' +import {blankLine} from './blank-line.js' + +/** @type {Construct} */ +export const htmlFlow = { + concrete: true, + name: 'htmlFlow', + resolveTo: resolveToHtmlFlow, + tokenize: tokenizeHtmlFlow +} + +/** @type {Construct} */ +const blankLineBefore = {partial: true, tokenize: tokenizeBlankLineBefore} +const nonLazyContinuationStart = { + partial: true, + tokenize: tokenizeNonLazyContinuationStart +} + +/** @type {Resolver} */ +function resolveToHtmlFlow(events) { + let index = events.length + + while (index--) { + if ( + events[index][0] === 'enter' && + events[index][1].type === types.htmlFlow + ) { + break + } + } + + if (index > 1 && events[index - 2][1].type === types.linePrefix) { + // Add the prefix start to the HTML token. + events[index][1].start = events[index - 2][1].start + // Add the prefix start to the HTML line token. + events[index + 1][1].start = events[index - 2][1].start + // Remove the line prefix. + events.splice(index - 2, 2) + } + + return events +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeHtmlFlow(effects, ok, nok) { + const self = this + /** @type {number} */ + let marker + /** @type {boolean} */ + let closingTag + /** @type {string} */ + let buffer + /** @type {number} */ + let index + /** @type {Code} */ + let markerB + + return start + + /** + * Start of HTML (flow). + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // To do: parse indent like `markdown-rs`. + return before(code) + } + + /** + * At `<`, after optional whitespace. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + assert(code === codes.lessThan, 'expected `<`') + effects.enter(types.htmlFlow) + effects.enter(types.htmlFlowData) + effects.consume(code) + return open + } + + /** + * After `<`, at tag name or other stuff. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (code === codes.exclamationMark) { + effects.consume(code) + return declarationOpen + } + + if (code === codes.slash) { + effects.consume(code) + closingTag = true + return tagCloseStart + } + + if (code === codes.questionMark) { + effects.consume(code) + marker = constants.htmlInstruction + // To do: + // tokenizer.concrete = true + // To do: use `markdown-rs` style interrupt. + // While we’re in an instruction instead of a declaration, we’re on a `?` + // right now, so we do need to search for `>`, similar to declarations. + return self.interrupt ? ok : continuationDeclarationInside + } + + // ASCII alphabetical. + if (asciiAlpha(code)) { + assert(code !== null) // Always the case. + effects.consume(code) + buffer = String.fromCharCode(code) + return tagName + } + + return nok(code) + } + + /** + * After ` | + * ^ + * > | + * ^ + * > | &<]]> + * ^ + * ``` + * + * @type {State} + */ + function declarationOpen(code) { + if (code === codes.dash) { + effects.consume(code) + marker = constants.htmlComment + return commentOpenInside + } + + if (code === codes.leftSquareBracket) { + effects.consume(code) + marker = constants.htmlCdata + index = 0 + return cdataOpenInside + } + + // ASCII alphabetical. + if (asciiAlpha(code)) { + effects.consume(code) + marker = constants.htmlDeclaration + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok : continuationDeclarationInside + } + + return nok(code) + } + + /** + * After ` | + * ^ + * ``` + * + * @type {State} + */ + function commentOpenInside(code) { + if (code === codes.dash) { + effects.consume(code) + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok : continuationDeclarationInside + } + + return nok(code) + } + + /** + * After ` | &<]]> + * ^^^^^^ + * ``` + * + * @type {State} + */ + function cdataOpenInside(code) { + const value = constants.cdataOpeningString + + if (code === value.charCodeAt(index++)) { + effects.consume(code) + + if (index === value.length) { + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok : continuation + } + + return cdataOpenInside + } + + return nok(code) + } + + /** + * After ` | + * ^ + * ``` + * + * @type {State} + */ + function tagCloseStart(code) { + if (asciiAlpha(code)) { + assert(code !== null) // Always the case. + effects.consume(code) + buffer = String.fromCharCode(code) + return tagName + } + + return nok(code) + } + + /** + * In tag name. + * + * ```markdown + * > | + * ^^ + * > | + * ^^ + * ``` + * + * @type {State} + */ + function tagName(code) { + if ( + code === codes.eof || + code === codes.slash || + code === codes.greaterThan || + markdownLineEndingOrSpace(code) + ) { + const slash = code === codes.slash + const name = buffer.toLowerCase() + + if (!slash && !closingTag && htmlRawNames.includes(name)) { + marker = constants.htmlRaw + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok(code) : continuation(code) + } + + if (htmlBlockNames.includes(buffer.toLowerCase())) { + marker = constants.htmlBasic + + if (slash) { + effects.consume(code) + return basicSelfClosing + } + + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok(code) : continuation(code) + } + + marker = constants.htmlComplete + // Do not support complete HTML when interrupting. + return self.interrupt && !self.parser.lazy[self.now().line] + ? nok(code) + : closingTag + ? completeClosingTagAfter(code) + : completeAttributeNameBefore(code) + } + + // ASCII alphanumerical and `-`. + if (code === codes.dash || asciiAlphanumeric(code)) { + effects.consume(code) + buffer += String.fromCharCode(code) + return tagName + } + + return nok(code) + } + + /** + * After closing slash of a basic tag name. + * + * ```markdown + * > |
+ * ^ + * ``` + * + * @type {State} + */ + function basicSelfClosing(code) { + if (code === codes.greaterThan) { + effects.consume(code) + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok : continuation + } + + return nok(code) + } + + /** + * After closing slash of a complete tag name. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeClosingTagAfter(code) { + if (markdownSpace(code)) { + effects.consume(code) + return completeClosingTagAfter + } + + return completeEnd(code) + } + + /** + * At an attribute name. + * + * At first, this state is used after a complete tag name, after whitespace, + * where it expects optional attributes or the end of the tag. + * It is also reused after attributes, when expecting more optional + * attributes. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * > | + * ^ + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeNameBefore(code) { + if (code === codes.slash) { + effects.consume(code) + return completeEnd + } + + // ASCII alphanumerical and `:` and `_`. + if (code === codes.colon || code === codes.underscore || asciiAlpha(code)) { + effects.consume(code) + return completeAttributeName + } + + if (markdownSpace(code)) { + effects.consume(code) + return completeAttributeNameBefore + } + + return completeEnd(code) + } + + /** + * In attribute name. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeName(code) { + // ASCII alphanumerical and `-`, `.`, `:`, and `_`. + if ( + code === codes.dash || + code === codes.dot || + code === codes.colon || + code === codes.underscore || + asciiAlphanumeric(code) + ) { + effects.consume(code) + return completeAttributeName + } + + return completeAttributeNameAfter(code) + } + + /** + * After attribute name, at an optional initializer, the end of the tag, or + * whitespace. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeNameAfter(code) { + if (code === codes.equalsTo) { + effects.consume(code) + return completeAttributeValueBefore + } + + if (markdownSpace(code)) { + effects.consume(code) + return completeAttributeNameAfter + } + + return completeAttributeNameBefore(code) + } + + /** + * Before unquoted, double quoted, or single quoted attribute value, allowing + * whitespace. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeValueBefore(code) { + if ( + code === codes.eof || + code === codes.lessThan || + code === codes.equalsTo || + code === codes.greaterThan || + code === codes.graveAccent + ) { + return nok(code) + } + + if (code === codes.quotationMark || code === codes.apostrophe) { + effects.consume(code) + markerB = code + return completeAttributeValueQuoted + } + + if (markdownSpace(code)) { + effects.consume(code) + return completeAttributeValueBefore + } + + return completeAttributeValueUnquoted(code) + } + + /** + * In double or single quoted attribute value. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeValueQuoted(code) { + if (code === markerB) { + effects.consume(code) + markerB = null + return completeAttributeValueQuotedAfter + } + + if (code === codes.eof || markdownLineEnding(code)) { + return nok(code) + } + + effects.consume(code) + return completeAttributeValueQuoted + } + + /** + * In unquoted attribute value. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeValueUnquoted(code) { + if ( + code === codes.eof || + code === codes.quotationMark || + code === codes.apostrophe || + code === codes.slash || + code === codes.lessThan || + code === codes.equalsTo || + code === codes.greaterThan || + code === codes.graveAccent || + markdownLineEndingOrSpace(code) + ) { + return completeAttributeNameAfter(code) + } + + effects.consume(code) + return completeAttributeValueUnquoted + } + + /** + * After double or single quoted attribute value, before whitespace or the + * end of the tag. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeValueQuotedAfter(code) { + if ( + code === codes.slash || + code === codes.greaterThan || + markdownSpace(code) + ) { + return completeAttributeNameBefore(code) + } + + return nok(code) + } + + /** + * In certain circumstances of a complete tag where only an `>` is allowed. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeEnd(code) { + if (code === codes.greaterThan) { + effects.consume(code) + return completeAfter + } + + return nok(code) + } + + /** + * After `>` in a complete tag. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAfter(code) { + if (code === codes.eof || markdownLineEnding(code)) { + // // Do not form containers. + // tokenizer.concrete = true + return continuation(code) + } + + if (markdownSpace(code)) { + effects.consume(code) + return completeAfter + } + + return nok(code) + } + + /** + * In continuation of any HTML kind. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuation(code) { + if (code === codes.dash && marker === constants.htmlComment) { + effects.consume(code) + return continuationCommentInside + } + + if (code === codes.lessThan && marker === constants.htmlRaw) { + effects.consume(code) + return continuationRawTagOpen + } + + if (code === codes.greaterThan && marker === constants.htmlDeclaration) { + effects.consume(code) + return continuationClose + } + + if (code === codes.questionMark && marker === constants.htmlInstruction) { + effects.consume(code) + return continuationDeclarationInside + } + + if (code === codes.rightSquareBracket && marker === constants.htmlCdata) { + effects.consume(code) + return continuationCdataInside + } + + if ( + markdownLineEnding(code) && + (marker === constants.htmlBasic || marker === constants.htmlComplete) + ) { + effects.exit(types.htmlFlowData) + return effects.check( + blankLineBefore, + continuationAfter, + continuationStart + )(code) + } + + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.htmlFlowData) + return continuationStart(code) + } + + effects.consume(code) + return continuation + } + + /** + * In continuation, at eol. + * + * ```markdown + * > | + * ^ + * | asd + * ``` + * + * @type {State} + */ + function continuationStart(code) { + return effects.check( + nonLazyContinuationStart, + continuationStartNonLazy, + continuationAfter + )(code) + } + + /** + * In continuation, at eol, before non-lazy content. + * + * ```markdown + * > | + * ^ + * | asd + * ``` + * + * @type {State} + */ + function continuationStartNonLazy(code) { + assert(markdownLineEnding(code)) + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return continuationBefore + } + + /** + * In continuation, before non-lazy content. + * + * ```markdown + * | + * > | asd + * ^ + * ``` + * + * @type {State} + */ + function continuationBefore(code) { + if (code === codes.eof || markdownLineEnding(code)) { + return continuationStart(code) + } + + effects.enter(types.htmlFlowData) + return continuation(code) + } + + /** + * In comment continuation, after one `-`, expecting another. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuationCommentInside(code) { + if (code === codes.dash) { + effects.consume(code) + return continuationDeclarationInside + } + + return continuation(code) + } + + /** + * In raw continuation, after `<`, at `/`. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuationRawTagOpen(code) { + if (code === codes.slash) { + effects.consume(code) + buffer = '' + return continuationRawEndTag + } + + return continuation(code) + } + + /** + * In raw continuation, after ` | + * ^^^^^^ + * ``` + * + * @type {State} + */ + function continuationRawEndTag(code) { + if (code === codes.greaterThan) { + const name = buffer.toLowerCase() + + if (htmlRawNames.includes(name)) { + effects.consume(code) + return continuationClose + } + + return continuation(code) + } + + if (asciiAlpha(code) && buffer.length < constants.htmlRawSizeMax) { + assert(code !== null) // Always the case. + effects.consume(code) + buffer += String.fromCharCode(code) + return continuationRawEndTag + } + + return continuation(code) + } + + /** + * In cdata continuation, after `]`, expecting `]>`. + * + * ```markdown + * > | &<]]> + * ^ + * ``` + * + * @type {State} + */ + function continuationCdataInside(code) { + if (code === codes.rightSquareBracket) { + effects.consume(code) + return continuationDeclarationInside + } + + return continuation(code) + } + + /** + * In declaration or instruction continuation, at `>`. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * > | + * ^ + * > | + * ^ + * > | &<]]> + * ^ + * ``` + * + * @type {State} + */ + function continuationDeclarationInside(code) { + if (code === codes.greaterThan) { + effects.consume(code) + return continuationClose + } + + // More dashes. + if (code === codes.dash && marker === constants.htmlComment) { + effects.consume(code) + return continuationDeclarationInside + } + + return continuation(code) + } + + /** + * In closed continuation: everything we get until the eol/eof is part of it. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuationClose(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.htmlFlowData) + return continuationAfter(code) + } + + effects.consume(code) + return continuationClose + } + + /** + * Done. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuationAfter(code) { + effects.exit(types.htmlFlow) + // // Feel free to interrupt. + // tokenizer.interrupt = false + // // No longer concrete. + // tokenizer.concrete = false + return ok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeNonLazyContinuationStart(effects, ok, nok) { + const self = this + + return start + + /** + * At eol, before continuation. + * + * ```markdown + * > | * ```js + * ^ + * | b + * ``` + * + * @type {State} + */ + function start(code) { + if (markdownLineEnding(code)) { + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return after + } + + return nok(code) + } + + /** + * A continuation. + * + * ```markdown + * | * ```js + * > | b + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + return self.parser.lazy[self.now().line] ? nok(code) : ok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeBlankLineBefore(effects, ok, nok) { + return start + + /** + * Before eol, expecting blank line. + * + * ```markdown + * > |
+ * ^ + * | + * ``` + * + * @type {State} + */ + function start(code) { + assert(markdownLineEnding(code), 'expected a line ending') + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return effects.attempt(blankLine, ok, nok) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/html-text.d.ts b/node_modules/micromark-core-commonmark/dev/lib/html-text.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fccb41bd58dfbdcffca207751c2ff6cf0615f046 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/html-text.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const htmlText: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=html-text.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/html-text.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/html-text.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..98d48a041e45bf766be76dafd07a44fd786229a9 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/html-text.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"html-text.d.ts","sourceRoot":"","sources":["html-text.js"],"names":[],"mappings":"AAqBA,wBAAwB;AACxB,uBADW,SAAS,CACkD;+BAf5D,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/html-text.js b/node_modules/micromark-core-commonmark/dev/lib/html-text.js new file mode 100644 index 0000000000000000000000000000000000000000..386199fd79f026cae0c05ea860be519a47dc6960 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/html-text.js @@ -0,0 +1,783 @@ +/** + * @import { + * Code, + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import { + asciiAlphanumeric, + asciiAlpha, + markdownLineEndingOrSpace, + markdownLineEnding, + markdownSpace +} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const htmlText = {name: 'htmlText', tokenize: tokenizeHtmlText} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeHtmlText(effects, ok, nok) { + const self = this + /** @type {NonNullable | undefined} */ + let marker + /** @type {number} */ + let index + /** @type {State} */ + let returnState + + return start + + /** + * Start of HTML (text). + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.lessThan, 'expected `<`') + effects.enter(types.htmlText) + effects.enter(types.htmlTextData) + effects.consume(code) + return open + } + + /** + * After `<`, at tag name or other stuff. + * + * ```markdown + * > | a c + * ^ + * > | a c + * ^ + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (code === codes.exclamationMark) { + effects.consume(code) + return declarationOpen + } + + if (code === codes.slash) { + effects.consume(code) + return tagCloseStart + } + + if (code === codes.questionMark) { + effects.consume(code) + return instruction + } + + // ASCII alphabetical. + if (asciiAlpha(code)) { + effects.consume(code) + return tagOpen + } + + return nok(code) + } + + /** + * After ` | a c + * ^ + * > | a c + * ^ + * > | a &<]]> c + * ^ + * ``` + * + * @type {State} + */ + function declarationOpen(code) { + if (code === codes.dash) { + effects.consume(code) + return commentOpenInside + } + + if (code === codes.leftSquareBracket) { + effects.consume(code) + index = 0 + return cdataOpenInside + } + + if (asciiAlpha(code)) { + effects.consume(code) + return declaration + } + + return nok(code) + } + + /** + * In a comment, after ` | a c + * ^ + * ``` + * + * @type {State} + */ + function commentOpenInside(code) { + if (code === codes.dash) { + effects.consume(code) + return commentEnd + } + + return nok(code) + } + + /** + * In comment. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function comment(code) { + if (code === codes.eof) { + return nok(code) + } + + if (code === codes.dash) { + effects.consume(code) + return commentClose + } + + if (markdownLineEnding(code)) { + returnState = comment + return lineEndingBefore(code) + } + + effects.consume(code) + return comment + } + + /** + * In comment, after `-`. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function commentClose(code) { + if (code === codes.dash) { + effects.consume(code) + return commentEnd + } + + return comment(code) + } + + /** + * In comment, after `--`. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function commentEnd(code) { + return code === codes.greaterThan + ? end(code) + : code === codes.dash + ? commentClose(code) + : comment(code) + } + + /** + * After ` | a &<]]> b + * ^^^^^^ + * ``` + * + * @type {State} + */ + function cdataOpenInside(code) { + const value = constants.cdataOpeningString + + if (code === value.charCodeAt(index++)) { + effects.consume(code) + return index === value.length ? cdata : cdataOpenInside + } + + return nok(code) + } + + /** + * In CDATA. + * + * ```markdown + * > | a &<]]> b + * ^^^ + * ``` + * + * @type {State} + */ + function cdata(code) { + if (code === codes.eof) { + return nok(code) + } + + if (code === codes.rightSquareBracket) { + effects.consume(code) + return cdataClose + } + + if (markdownLineEnding(code)) { + returnState = cdata + return lineEndingBefore(code) + } + + effects.consume(code) + return cdata + } + + /** + * In CDATA, after `]`, at another `]`. + * + * ```markdown + * > | a &<]]> b + * ^ + * ``` + * + * @type {State} + */ + function cdataClose(code) { + if (code === codes.rightSquareBracket) { + effects.consume(code) + return cdataEnd + } + + return cdata(code) + } + + /** + * In CDATA, after `]]`, at `>`. + * + * ```markdown + * > | a &<]]> b + * ^ + * ``` + * + * @type {State} + */ + function cdataEnd(code) { + if (code === codes.greaterThan) { + return end(code) + } + + if (code === codes.rightSquareBracket) { + effects.consume(code) + return cdataEnd + } + + return cdata(code) + } + + /** + * In declaration. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function declaration(code) { + if (code === codes.eof || code === codes.greaterThan) { + return end(code) + } + + if (markdownLineEnding(code)) { + returnState = declaration + return lineEndingBefore(code) + } + + effects.consume(code) + return declaration + } + + /** + * In instruction. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function instruction(code) { + if (code === codes.eof) { + return nok(code) + } + + if (code === codes.questionMark) { + effects.consume(code) + return instructionClose + } + + if (markdownLineEnding(code)) { + returnState = instruction + return lineEndingBefore(code) + } + + effects.consume(code) + return instruction + } + + /** + * In instruction, after `?`, at `>`. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function instructionClose(code) { + return code === codes.greaterThan ? end(code) : instruction(code) + } + + /** + * After ` | a c + * ^ + * ``` + * + * @type {State} + */ + function tagCloseStart(code) { + // ASCII alphabetical. + if (asciiAlpha(code)) { + effects.consume(code) + return tagClose + } + + return nok(code) + } + + /** + * After ` | a c + * ^ + * ``` + * + * @type {State} + */ + function tagClose(code) { + // ASCII alphanumerical and `-`. + if (code === codes.dash || asciiAlphanumeric(code)) { + effects.consume(code) + return tagClose + } + + return tagCloseBetween(code) + } + + /** + * In closing tag, after tag name. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function tagCloseBetween(code) { + if (markdownLineEnding(code)) { + returnState = tagCloseBetween + return lineEndingBefore(code) + } + + if (markdownSpace(code)) { + effects.consume(code) + return tagCloseBetween + } + + return end(code) + } + + /** + * After ` | a c + * ^ + * ``` + * + * @type {State} + */ + function tagOpen(code) { + // ASCII alphanumerical and `-`. + if (code === codes.dash || asciiAlphanumeric(code)) { + effects.consume(code) + return tagOpen + } + + if ( + code === codes.slash || + code === codes.greaterThan || + markdownLineEndingOrSpace(code) + ) { + return tagOpenBetween(code) + } + + return nok(code) + } + + /** + * In opening tag, after tag name. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function tagOpenBetween(code) { + if (code === codes.slash) { + effects.consume(code) + return end + } + + // ASCII alphabetical and `:` and `_`. + if (code === codes.colon || code === codes.underscore || asciiAlpha(code)) { + effects.consume(code) + return tagOpenAttributeName + } + + if (markdownLineEnding(code)) { + returnState = tagOpenBetween + return lineEndingBefore(code) + } + + if (markdownSpace(code)) { + effects.consume(code) + return tagOpenBetween + } + + return end(code) + } + + /** + * In attribute name. + * + * ```markdown + * > | a d + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeName(code) { + // ASCII alphabetical and `-`, `.`, `:`, and `_`. + if ( + code === codes.dash || + code === codes.dot || + code === codes.colon || + code === codes.underscore || + asciiAlphanumeric(code) + ) { + effects.consume(code) + return tagOpenAttributeName + } + + return tagOpenAttributeNameAfter(code) + } + + /** + * After attribute name, before initializer, the end of the tag, or + * whitespace. + * + * ```markdown + * > | a d + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeNameAfter(code) { + if (code === codes.equalsTo) { + effects.consume(code) + return tagOpenAttributeValueBefore + } + + if (markdownLineEnding(code)) { + returnState = tagOpenAttributeNameAfter + return lineEndingBefore(code) + } + + if (markdownSpace(code)) { + effects.consume(code) + return tagOpenAttributeNameAfter + } + + return tagOpenBetween(code) + } + + /** + * Before unquoted, double quoted, or single quoted attribute value, allowing + * whitespace. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeValueBefore(code) { + if ( + code === codes.eof || + code === codes.lessThan || + code === codes.equalsTo || + code === codes.greaterThan || + code === codes.graveAccent + ) { + return nok(code) + } + + if (code === codes.quotationMark || code === codes.apostrophe) { + effects.consume(code) + marker = code + return tagOpenAttributeValueQuoted + } + + if (markdownLineEnding(code)) { + returnState = tagOpenAttributeValueBefore + return lineEndingBefore(code) + } + + if (markdownSpace(code)) { + effects.consume(code) + return tagOpenAttributeValueBefore + } + + effects.consume(code) + return tagOpenAttributeValueUnquoted + } + + /** + * In double or single quoted attribute value. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeValueQuoted(code) { + if (code === marker) { + effects.consume(code) + marker = undefined + return tagOpenAttributeValueQuotedAfter + } + + if (code === codes.eof) { + return nok(code) + } + + if (markdownLineEnding(code)) { + returnState = tagOpenAttributeValueQuoted + return lineEndingBefore(code) + } + + effects.consume(code) + return tagOpenAttributeValueQuoted + } + + /** + * In unquoted attribute value. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeValueUnquoted(code) { + if ( + code === codes.eof || + code === codes.quotationMark || + code === codes.apostrophe || + code === codes.lessThan || + code === codes.equalsTo || + code === codes.graveAccent + ) { + return nok(code) + } + + if ( + code === codes.slash || + code === codes.greaterThan || + markdownLineEndingOrSpace(code) + ) { + return tagOpenBetween(code) + } + + effects.consume(code) + return tagOpenAttributeValueUnquoted + } + + /** + * After double or single quoted attribute value, before whitespace or the end + * of the tag. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeValueQuotedAfter(code) { + if ( + code === codes.slash || + code === codes.greaterThan || + markdownLineEndingOrSpace(code) + ) { + return tagOpenBetween(code) + } + + return nok(code) + } + + /** + * In certain circumstances of a tag where only an `>` is allowed. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function end(code) { + if (code === codes.greaterThan) { + effects.consume(code) + effects.exit(types.htmlTextData) + effects.exit(types.htmlText) + return ok + } + + return nok(code) + } + + /** + * At eol. + * + * > 👉 **Note**: we can’t have blank lines in text, so no need to worry about + * > empty tokens. + * + * ```markdown + * > | a + * ``` + * + * @type {State} + */ + function lineEndingBefore(code) { + assert(returnState, 'expected return state') + assert(markdownLineEnding(code), 'expected eol') + effects.exit(types.htmlTextData) + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return lineEndingAfter + } + + /** + * After eol, at optional whitespace. + * + * > 👉 **Note**: we can’t have blank lines in text, so no need to worry about + * > empty tokens. + * + * ```markdown + * | a + * ^ + * ``` + * + * @type {State} + */ + function lineEndingAfter(code) { + // Always populated by defaults. + assert( + self.parser.constructs.disable.null, + 'expected `disable.null` to be populated' + ) + return markdownSpace(code) + ? factorySpace( + effects, + lineEndingAfterPrefix, + types.linePrefix, + self.parser.constructs.disable.null.includes('codeIndented') + ? undefined + : constants.tabSize + )(code) + : lineEndingAfterPrefix(code) + } + + /** + * After eol, after optional whitespace. + * + * > 👉 **Note**: we can’t have blank lines in text, so no need to worry about + * > empty tokens. + * + * ```markdown + * | a + * ^ + * ``` + * + * @type {State} + */ + function lineEndingAfterPrefix(code) { + effects.enter(types.htmlTextData) + return returnState(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-end.d.ts b/node_modules/micromark-core-commonmark/dev/lib/label-end.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c892edb7db82843a0b29f462379a327aa2fe47f6 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-end.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const labelEnd: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=label-end.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-end.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/label-end.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..3d6348f618669da6df07fc2b5b150ac69601ef81 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-end.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"label-end.d.ts","sourceRoot":"","sources":["label-end.js"],"names":[],"mappings":"AAuBA,wBAAwB;AACxB,uBADW,SAAS,CAMnB;+BApBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-end.js b/node_modules/micromark-core-commonmark/dev/lib/label-end.js new file mode 100644 index 0000000000000000000000000000000000000000..492756f04eb7e5f0b77d0c4283692ef7457e6d7c --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-end.js @@ -0,0 +1,656 @@ +/** + * @import { + * Construct, + * Event, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factoryDestination} from 'micromark-factory-destination' +import {factoryLabel} from 'micromark-factory-label' +import {factoryTitle} from 'micromark-factory-title' +import {factoryWhitespace} from 'micromark-factory-whitespace' +import {markdownLineEndingOrSpace} from 'micromark-util-character' +import {push, splice} from 'micromark-util-chunked' +import {normalizeIdentifier} from 'micromark-util-normalize-identifier' +import {resolveAll} from 'micromark-util-resolve-all' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const labelEnd = { + name: 'labelEnd', + resolveAll: resolveAllLabelEnd, + resolveTo: resolveToLabelEnd, + tokenize: tokenizeLabelEnd +} + +/** @type {Construct} */ +const resourceConstruct = {tokenize: tokenizeResource} +/** @type {Construct} */ +const referenceFullConstruct = {tokenize: tokenizeReferenceFull} +/** @type {Construct} */ +const referenceCollapsedConstruct = {tokenize: tokenizeReferenceCollapsed} + +/** @type {Resolver} */ +function resolveAllLabelEnd(events) { + let index = -1 + /** @type {Array} */ + const newEvents = [] + while (++index < events.length) { + const token = events[index][1] + newEvents.push(events[index]) + + if ( + token.type === types.labelImage || + token.type === types.labelLink || + token.type === types.labelEnd + ) { + // Remove the marker. + const offset = token.type === types.labelImage ? 4 : 2 + token.type = types.data + index += offset + } + } + + // If the events are equal, we don't have to copy newEvents to events + if (events.length !== newEvents.length) { + splice(events, 0, events.length, newEvents) + } + + return events +} + +/** @type {Resolver} */ +function resolveToLabelEnd(events, context) { + let index = events.length + let offset = 0 + /** @type {Token} */ + let token + /** @type {number | undefined} */ + let open + /** @type {number | undefined} */ + let close + /** @type {Array} */ + let media + + // Find an opening. + while (index--) { + token = events[index][1] + + if (open) { + // If we see another link, or inactive link label, we’ve been here before. + if ( + token.type === types.link || + (token.type === types.labelLink && token._inactive) + ) { + break + } + + // Mark other link openings as inactive, as we can’t have links in + // links. + if (events[index][0] === 'enter' && token.type === types.labelLink) { + token._inactive = true + } + } else if (close) { + if ( + events[index][0] === 'enter' && + (token.type === types.labelImage || token.type === types.labelLink) && + !token._balanced + ) { + open = index + + if (token.type !== types.labelLink) { + offset = 2 + break + } + } + } else if (token.type === types.labelEnd) { + close = index + } + } + + assert(open !== undefined, '`open` is supposed to be found') + assert(close !== undefined, '`close` is supposed to be found') + + const group = { + type: events[open][1].type === types.labelLink ? types.link : types.image, + start: {...events[open][1].start}, + end: {...events[events.length - 1][1].end} + } + + const label = { + type: types.label, + start: {...events[open][1].start}, + end: {...events[close][1].end} + } + + const text = { + type: types.labelText, + start: {...events[open + offset + 2][1].end}, + end: {...events[close - 2][1].start} + } + + media = [ + ['enter', group, context], + ['enter', label, context] + ] + + // Opening marker. + media = push(media, events.slice(open + 1, open + offset + 3)) + + // Text open. + media = push(media, [['enter', text, context]]) + + // Always populated by defaults. + assert( + context.parser.constructs.insideSpan.null, + 'expected `insideSpan.null` to be populated' + ) + // Between. + media = push( + media, + resolveAll( + context.parser.constructs.insideSpan.null, + events.slice(open + offset + 4, close - 3), + context + ) + ) + + // Text close, marker close, label close. + media = push(media, [ + ['exit', text, context], + events[close - 2], + events[close - 1], + ['exit', label, context] + ]) + + // Reference, resource, or so. + media = push(media, events.slice(close + 1)) + + // Media close. + media = push(media, [['exit', group, context]]) + + splice(events, open, events.length, media) + + return events +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeLabelEnd(effects, ok, nok) { + const self = this + let index = self.events.length + /** @type {Token} */ + let labelStart + /** @type {boolean} */ + let defined + + // Find an opening. + while (index--) { + if ( + (self.events[index][1].type === types.labelImage || + self.events[index][1].type === types.labelLink) && + !self.events[index][1]._balanced + ) { + labelStart = self.events[index][1] + break + } + } + + return start + + /** + * Start of label end. + * + * ```markdown + * > | [a](b) c + * ^ + * > | [a][b] c + * ^ + * > | [a][] b + * ^ + * > | [a] b + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.rightSquareBracket, 'expected `]`') + + // If there is not an okay opening. + if (!labelStart) { + return nok(code) + } + + // If the corresponding label (link) start is marked as inactive, + // it means we’d be wrapping a link, like this: + // + // ```markdown + // > | a [b [c](d) e](f) g. + // ^ + // ``` + // + // We can’t have that, so it’s just balanced brackets. + if (labelStart._inactive) { + return labelEndNok(code) + } + + defined = self.parser.defined.includes( + normalizeIdentifier( + self.sliceSerialize({start: labelStart.end, end: self.now()}) + ) + ) + effects.enter(types.labelEnd) + effects.enter(types.labelMarker) + effects.consume(code) + effects.exit(types.labelMarker) + effects.exit(types.labelEnd) + return after + } + + /** + * After `]`. + * + * ```markdown + * > | [a](b) c + * ^ + * > | [a][b] c + * ^ + * > | [a][] b + * ^ + * > | [a] b + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + // Note: `markdown-rs` also parses GFM footnotes here, which for us is in + // an extension. + + // Resource (`[asd](fgh)`)? + if (code === codes.leftParenthesis) { + return effects.attempt( + resourceConstruct, + labelEndOk, + defined ? labelEndOk : labelEndNok + )(code) + } + + // Full (`[asd][fgh]`) or collapsed (`[asd][]`) reference? + if (code === codes.leftSquareBracket) { + return effects.attempt( + referenceFullConstruct, + labelEndOk, + defined ? referenceNotFull : labelEndNok + )(code) + } + + // Shortcut (`[asd]`) reference? + return defined ? labelEndOk(code) : labelEndNok(code) + } + + /** + * After `]`, at `[`, but not at a full reference. + * + * > 👉 **Note**: we only get here if the label is defined. + * + * ```markdown + * > | [a][] b + * ^ + * > | [a] b + * ^ + * ``` + * + * @type {State} + */ + function referenceNotFull(code) { + return effects.attempt( + referenceCollapsedConstruct, + labelEndOk, + labelEndNok + )(code) + } + + /** + * Done, we found something. + * + * ```markdown + * > | [a](b) c + * ^ + * > | [a][b] c + * ^ + * > | [a][] b + * ^ + * > | [a] b + * ^ + * ``` + * + * @type {State} + */ + function labelEndOk(code) { + // Note: `markdown-rs` does a bunch of stuff here. + return ok(code) + } + + /** + * Done, it’s nothing. + * + * There was an okay opening, but we didn’t match anything. + * + * ```markdown + * > | [a](b c + * ^ + * > | [a][b c + * ^ + * > | [a] b + * ^ + * ``` + * + * @type {State} + */ + function labelEndNok(code) { + labelStart._balanced = true + return nok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeResource(effects, ok, nok) { + return resourceStart + + /** + * At a resource. + * + * ```markdown + * > | [a](b) c + * ^ + * ``` + * + * @type {State} + */ + function resourceStart(code) { + assert(code === codes.leftParenthesis, 'expected left paren') + effects.enter(types.resource) + effects.enter(types.resourceMarker) + effects.consume(code) + effects.exit(types.resourceMarker) + return resourceBefore + } + + /** + * In resource, after `(`, at optional whitespace. + * + * ```markdown + * > | [a](b) c + * ^ + * ``` + * + * @type {State} + */ + function resourceBefore(code) { + return markdownLineEndingOrSpace(code) + ? factoryWhitespace(effects, resourceOpen)(code) + : resourceOpen(code) + } + + /** + * In resource, after optional whitespace, at `)` or a destination. + * + * ```markdown + * > | [a](b) c + * ^ + * ``` + * + * @type {State} + */ + function resourceOpen(code) { + if (code === codes.rightParenthesis) { + return resourceEnd(code) + } + + return factoryDestination( + effects, + resourceDestinationAfter, + resourceDestinationMissing, + types.resourceDestination, + types.resourceDestinationLiteral, + types.resourceDestinationLiteralMarker, + types.resourceDestinationRaw, + types.resourceDestinationString, + constants.linkResourceDestinationBalanceMax + )(code) + } + + /** + * In resource, after destination, at optional whitespace. + * + * ```markdown + * > | [a](b) c + * ^ + * ``` + * + * @type {State} + */ + function resourceDestinationAfter(code) { + return markdownLineEndingOrSpace(code) + ? factoryWhitespace(effects, resourceBetween)(code) + : resourceEnd(code) + } + + /** + * At invalid destination. + * + * ```markdown + * > | [a](<<) b + * ^ + * ``` + * + * @type {State} + */ + function resourceDestinationMissing(code) { + return nok(code) + } + + /** + * In resource, after destination and whitespace, at `(` or title. + * + * ```markdown + * > | [a](b ) c + * ^ + * ``` + * + * @type {State} + */ + function resourceBetween(code) { + if ( + code === codes.quotationMark || + code === codes.apostrophe || + code === codes.leftParenthesis + ) { + return factoryTitle( + effects, + resourceTitleAfter, + nok, + types.resourceTitle, + types.resourceTitleMarker, + types.resourceTitleString + )(code) + } + + return resourceEnd(code) + } + + /** + * In resource, after title, at optional whitespace. + * + * ```markdown + * > | [a](b "c") d + * ^ + * ``` + * + * @type {State} + */ + function resourceTitleAfter(code) { + return markdownLineEndingOrSpace(code) + ? factoryWhitespace(effects, resourceEnd)(code) + : resourceEnd(code) + } + + /** + * In resource, at `)`. + * + * ```markdown + * > | [a](b) d + * ^ + * ``` + * + * @type {State} + */ + function resourceEnd(code) { + if (code === codes.rightParenthesis) { + effects.enter(types.resourceMarker) + effects.consume(code) + effects.exit(types.resourceMarker) + effects.exit(types.resource) + return ok + } + + return nok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeReferenceFull(effects, ok, nok) { + const self = this + + return referenceFull + + /** + * In a reference (full), at the `[`. + * + * ```markdown + * > | [a][b] d + * ^ + * ``` + * + * @type {State} + */ + function referenceFull(code) { + assert(code === codes.leftSquareBracket, 'expected left bracket') + return factoryLabel.call( + self, + effects, + referenceFullAfter, + referenceFullMissing, + types.reference, + types.referenceMarker, + types.referenceString + )(code) + } + + /** + * In a reference (full), after `]`. + * + * ```markdown + * > | [a][b] d + * ^ + * ``` + * + * @type {State} + */ + function referenceFullAfter(code) { + return self.parser.defined.includes( + normalizeIdentifier( + self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1) + ) + ) + ? ok(code) + : nok(code) + } + + /** + * In reference (full) that was missing. + * + * ```markdown + * > | [a][b d + * ^ + * ``` + * + * @type {State} + */ + function referenceFullMissing(code) { + return nok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeReferenceCollapsed(effects, ok, nok) { + return referenceCollapsedStart + + /** + * In reference (collapsed), at `[`. + * + * > 👉 **Note**: we only get here if the label is defined. + * + * ```markdown + * > | [a][] d + * ^ + * ``` + * + * @type {State} + */ + function referenceCollapsedStart(code) { + // We only attempt a collapsed label if there’s a `[`. + assert(code === codes.leftSquareBracket, 'expected left bracket') + effects.enter(types.reference) + effects.enter(types.referenceMarker) + effects.consume(code) + effects.exit(types.referenceMarker) + return referenceCollapsedOpen + } + + /** + * In reference (collapsed), at `]`. + * + * > 👉 **Note**: we only get here if the label is defined. + * + * ```markdown + * > | [a][] d + * ^ + * ``` + * + * @type {State} + */ + function referenceCollapsedOpen(code) { + if (code === codes.rightSquareBracket) { + effects.enter(types.referenceMarker) + effects.consume(code) + effects.exit(types.referenceMarker) + effects.exit(types.reference) + return ok + } + + return nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-start-image.d.ts b/node_modules/micromark-core-commonmark/dev/lib/label-start-image.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..0a3c6903b673bf64e9072788ce5715586afba77d --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-start-image.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const labelStartImage: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=label-start-image.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-start-image.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/label-start-image.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..e41dbf7453b2769fdcc28edbb1febafd946a2e2b --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-start-image.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"label-start-image.d.ts","sourceRoot":"","sources":["label-start-image.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,8BADW,SAAS,CAKnB;+BAZS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-start-image.js b/node_modules/micromark-core-commonmark/dev/lib/label-start-image.js new file mode 100644 index 0000000000000000000000000000000000000000..4448cc9df858c62d9aeb06170dd1a1523323eeae --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-start-image.js @@ -0,0 +1,110 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {codes, types} from 'micromark-util-symbol' +import {labelEnd} from './label-end.js' + +/** @type {Construct} */ +export const labelStartImage = { + name: 'labelStartImage', + resolveAll: labelEnd.resolveAll, + tokenize: tokenizeLabelStartImage +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeLabelStartImage(effects, ok, nok) { + const self = this + + return start + + /** + * Start of label (image) start. + * + * ```markdown + * > | a ![b] c + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.exclamationMark, 'expected `!`') + effects.enter(types.labelImage) + effects.enter(types.labelImageMarker) + effects.consume(code) + effects.exit(types.labelImageMarker) + return open + } + + /** + * After `!`, at `[`. + * + * ```markdown + * > | a ![b] c + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (code === codes.leftSquareBracket) { + effects.enter(types.labelMarker) + effects.consume(code) + effects.exit(types.labelMarker) + effects.exit(types.labelImage) + return after + } + + return nok(code) + } + + /** + * After `![`. + * + * ```markdown + * > | a ![b] c + * ^ + * ``` + * + * This is needed in because, when GFM footnotes are enabled, images never + * form when started with a `^`. + * Instead, links form: + * + * ```markdown + * ![^a](b) + * + * ![^a][b] + * + * [b]: c + * ``` + * + * ```html + *
+ * ^ + * ``` + * + * @type {State} + */ + function basicSelfClosing(code) { + if (code === 62) { + effects.consume(code); + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok : continuation; + } + return nok(code); + } + + /** + * After closing slash of a complete tag name. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeClosingTagAfter(code) { + if (markdownSpace(code)) { + effects.consume(code); + return completeClosingTagAfter; + } + return completeEnd(code); + } + + /** + * At an attribute name. + * + * At first, this state is used after a complete tag name, after whitespace, + * where it expects optional attributes or the end of the tag. + * It is also reused after attributes, when expecting more optional + * attributes. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * > | + * ^ + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeNameBefore(code) { + if (code === 47) { + effects.consume(code); + return completeEnd; + } + + // ASCII alphanumerical and `:` and `_`. + if (code === 58 || code === 95 || asciiAlpha(code)) { + effects.consume(code); + return completeAttributeName; + } + if (markdownSpace(code)) { + effects.consume(code); + return completeAttributeNameBefore; + } + return completeEnd(code); + } + + /** + * In attribute name. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeName(code) { + // ASCII alphanumerical and `-`, `.`, `:`, and `_`. + if (code === 45 || code === 46 || code === 58 || code === 95 || asciiAlphanumeric(code)) { + effects.consume(code); + return completeAttributeName; + } + return completeAttributeNameAfter(code); + } + + /** + * After attribute name, at an optional initializer, the end of the tag, or + * whitespace. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeNameAfter(code) { + if (code === 61) { + effects.consume(code); + return completeAttributeValueBefore; + } + if (markdownSpace(code)) { + effects.consume(code); + return completeAttributeNameAfter; + } + return completeAttributeNameBefore(code); + } + + /** + * Before unquoted, double quoted, or single quoted attribute value, allowing + * whitespace. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeValueBefore(code) { + if (code === null || code === 60 || code === 61 || code === 62 || code === 96) { + return nok(code); + } + if (code === 34 || code === 39) { + effects.consume(code); + markerB = code; + return completeAttributeValueQuoted; + } + if (markdownSpace(code)) { + effects.consume(code); + return completeAttributeValueBefore; + } + return completeAttributeValueUnquoted(code); + } + + /** + * In double or single quoted attribute value. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeValueQuoted(code) { + if (code === markerB) { + effects.consume(code); + markerB = null; + return completeAttributeValueQuotedAfter; + } + if (code === null || markdownLineEnding(code)) { + return nok(code); + } + effects.consume(code); + return completeAttributeValueQuoted; + } + + /** + * In unquoted attribute value. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeValueUnquoted(code) { + if (code === null || code === 34 || code === 39 || code === 47 || code === 60 || code === 61 || code === 62 || code === 96 || markdownLineEndingOrSpace(code)) { + return completeAttributeNameAfter(code); + } + effects.consume(code); + return completeAttributeValueUnquoted; + } + + /** + * After double or single quoted attribute value, before whitespace or the + * end of the tag. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAttributeValueQuotedAfter(code) { + if (code === 47 || code === 62 || markdownSpace(code)) { + return completeAttributeNameBefore(code); + } + return nok(code); + } + + /** + * In certain circumstances of a complete tag where only an `>` is allowed. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeEnd(code) { + if (code === 62) { + effects.consume(code); + return completeAfter; + } + return nok(code); + } + + /** + * After `>` in a complete tag. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function completeAfter(code) { + if (code === null || markdownLineEnding(code)) { + // // Do not form containers. + // tokenizer.concrete = true + return continuation(code); + } + if (markdownSpace(code)) { + effects.consume(code); + return completeAfter; + } + return nok(code); + } + + /** + * In continuation of any HTML kind. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuation(code) { + if (code === 45 && marker === 2) { + effects.consume(code); + return continuationCommentInside; + } + if (code === 60 && marker === 1) { + effects.consume(code); + return continuationRawTagOpen; + } + if (code === 62 && marker === 4) { + effects.consume(code); + return continuationClose; + } + if (code === 63 && marker === 3) { + effects.consume(code); + return continuationDeclarationInside; + } + if (code === 93 && marker === 5) { + effects.consume(code); + return continuationCdataInside; + } + if (markdownLineEnding(code) && (marker === 6 || marker === 7)) { + effects.exit("htmlFlowData"); + return effects.check(blankLineBefore, continuationAfter, continuationStart)(code); + } + if (code === null || markdownLineEnding(code)) { + effects.exit("htmlFlowData"); + return continuationStart(code); + } + effects.consume(code); + return continuation; + } + + /** + * In continuation, at eol. + * + * ```markdown + * > | + * ^ + * | asd + * ``` + * + * @type {State} + */ + function continuationStart(code) { + return effects.check(nonLazyContinuationStart, continuationStartNonLazy, continuationAfter)(code); + } + + /** + * In continuation, at eol, before non-lazy content. + * + * ```markdown + * > | + * ^ + * | asd + * ``` + * + * @type {State} + */ + function continuationStartNonLazy(code) { + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return continuationBefore; + } + + /** + * In continuation, before non-lazy content. + * + * ```markdown + * | + * > | asd + * ^ + * ``` + * + * @type {State} + */ + function continuationBefore(code) { + if (code === null || markdownLineEnding(code)) { + return continuationStart(code); + } + effects.enter("htmlFlowData"); + return continuation(code); + } + + /** + * In comment continuation, after one `-`, expecting another. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuationCommentInside(code) { + if (code === 45) { + effects.consume(code); + return continuationDeclarationInside; + } + return continuation(code); + } + + /** + * In raw continuation, after `<`, at `/`. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuationRawTagOpen(code) { + if (code === 47) { + effects.consume(code); + buffer = ''; + return continuationRawEndTag; + } + return continuation(code); + } + + /** + * In raw continuation, after ` | + * ^^^^^^ + * ``` + * + * @type {State} + */ + function continuationRawEndTag(code) { + if (code === 62) { + const name = buffer.toLowerCase(); + if (htmlRawNames.includes(name)) { + effects.consume(code); + return continuationClose; + } + return continuation(code); + } + if (asciiAlpha(code) && buffer.length < 8) { + // Always the case. + effects.consume(code); + buffer += String.fromCharCode(code); + return continuationRawEndTag; + } + return continuation(code); + } + + /** + * In cdata continuation, after `]`, expecting `]>`. + * + * ```markdown + * > | &<]]> + * ^ + * ``` + * + * @type {State} + */ + function continuationCdataInside(code) { + if (code === 93) { + effects.consume(code); + return continuationDeclarationInside; + } + return continuation(code); + } + + /** + * In declaration or instruction continuation, at `>`. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * > | + * ^ + * > | + * ^ + * > | &<]]> + * ^ + * ``` + * + * @type {State} + */ + function continuationDeclarationInside(code) { + if (code === 62) { + effects.consume(code); + return continuationClose; + } + + // More dashes. + if (code === 45 && marker === 2) { + effects.consume(code); + return continuationDeclarationInside; + } + return continuation(code); + } + + /** + * In closed continuation: everything we get until the eol/eof is part of it. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuationClose(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("htmlFlowData"); + return continuationAfter(code); + } + effects.consume(code); + return continuationClose; + } + + /** + * Done. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function continuationAfter(code) { + effects.exit("htmlFlow"); + // // Feel free to interrupt. + // tokenizer.interrupt = false + // // No longer concrete. + // tokenizer.concrete = false + return ok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeNonLazyContinuationStart(effects, ok, nok) { + const self = this; + return start; + + /** + * At eol, before continuation. + * + * ```markdown + * > | * ```js + * ^ + * | b + * ``` + * + * @type {State} + */ + function start(code) { + if (markdownLineEnding(code)) { + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return after; + } + return nok(code); + } + + /** + * A continuation. + * + * ```markdown + * | * ```js + * > | b + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + return self.parser.lazy[self.now().line] ? nok(code) : ok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeBlankLineBefore(effects, ok, nok) { + return start; + + /** + * Before eol, expecting blank line. + * + * ```markdown + * > |
+ * ^ + * | + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return effects.attempt(blankLine, ok, nok); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/html-text.d.ts b/node_modules/micromark-core-commonmark/lib/html-text.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fccb41bd58dfbdcffca207751c2ff6cf0615f046 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/html-text.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const htmlText: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=html-text.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/html-text.d.ts.map b/node_modules/micromark-core-commonmark/lib/html-text.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..98d48a041e45bf766be76dafd07a44fd786229a9 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/html-text.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"html-text.d.ts","sourceRoot":"","sources":["html-text.js"],"names":[],"mappings":"AAqBA,wBAAwB;AACxB,uBADW,SAAS,CACkD;+BAf5D,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/html-text.js b/node_modules/micromark-core-commonmark/lib/html-text.js new file mode 100644 index 0000000000000000000000000000000000000000..a455bb09227fc88e0e72932bdd1a3daa00885910 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/html-text.js @@ -0,0 +1,678 @@ +/** + * @import { + * Code, + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { asciiAlphanumeric, asciiAlpha, markdownLineEndingOrSpace, markdownLineEnding, markdownSpace } from 'micromark-util-character'; +/** @type {Construct} */ +export const htmlText = { + name: 'htmlText', + tokenize: tokenizeHtmlText +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeHtmlText(effects, ok, nok) { + const self = this; + /** @type {NonNullable | undefined} */ + let marker; + /** @type {number} */ + let index; + /** @type {State} */ + let returnState; + return start; + + /** + * Start of HTML (text). + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("htmlText"); + effects.enter("htmlTextData"); + effects.consume(code); + return open; + } + + /** + * After `<`, at tag name or other stuff. + * + * ```markdown + * > | a c + * ^ + * > | a c + * ^ + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (code === 33) { + effects.consume(code); + return declarationOpen; + } + if (code === 47) { + effects.consume(code); + return tagCloseStart; + } + if (code === 63) { + effects.consume(code); + return instruction; + } + + // ASCII alphabetical. + if (asciiAlpha(code)) { + effects.consume(code); + return tagOpen; + } + return nok(code); + } + + /** + * After ` | a c + * ^ + * > | a c + * ^ + * > | a &<]]> c + * ^ + * ``` + * + * @type {State} + */ + function declarationOpen(code) { + if (code === 45) { + effects.consume(code); + return commentOpenInside; + } + if (code === 91) { + effects.consume(code); + index = 0; + return cdataOpenInside; + } + if (asciiAlpha(code)) { + effects.consume(code); + return declaration; + } + return nok(code); + } + + /** + * In a comment, after ` | a c + * ^ + * ``` + * + * @type {State} + */ + function commentOpenInside(code) { + if (code === 45) { + effects.consume(code); + return commentEnd; + } + return nok(code); + } + + /** + * In comment. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function comment(code) { + if (code === null) { + return nok(code); + } + if (code === 45) { + effects.consume(code); + return commentClose; + } + if (markdownLineEnding(code)) { + returnState = comment; + return lineEndingBefore(code); + } + effects.consume(code); + return comment; + } + + /** + * In comment, after `-`. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function commentClose(code) { + if (code === 45) { + effects.consume(code); + return commentEnd; + } + return comment(code); + } + + /** + * In comment, after `--`. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function commentEnd(code) { + return code === 62 ? end(code) : code === 45 ? commentClose(code) : comment(code); + } + + /** + * After ` | a &<]]> b + * ^^^^^^ + * ``` + * + * @type {State} + */ + function cdataOpenInside(code) { + const value = "CDATA["; + if (code === value.charCodeAt(index++)) { + effects.consume(code); + return index === value.length ? cdata : cdataOpenInside; + } + return nok(code); + } + + /** + * In CDATA. + * + * ```markdown + * > | a &<]]> b + * ^^^ + * ``` + * + * @type {State} + */ + function cdata(code) { + if (code === null) { + return nok(code); + } + if (code === 93) { + effects.consume(code); + return cdataClose; + } + if (markdownLineEnding(code)) { + returnState = cdata; + return lineEndingBefore(code); + } + effects.consume(code); + return cdata; + } + + /** + * In CDATA, after `]`, at another `]`. + * + * ```markdown + * > | a &<]]> b + * ^ + * ``` + * + * @type {State} + */ + function cdataClose(code) { + if (code === 93) { + effects.consume(code); + return cdataEnd; + } + return cdata(code); + } + + /** + * In CDATA, after `]]`, at `>`. + * + * ```markdown + * > | a &<]]> b + * ^ + * ``` + * + * @type {State} + */ + function cdataEnd(code) { + if (code === 62) { + return end(code); + } + if (code === 93) { + effects.consume(code); + return cdataEnd; + } + return cdata(code); + } + + /** + * In declaration. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function declaration(code) { + if (code === null || code === 62) { + return end(code); + } + if (markdownLineEnding(code)) { + returnState = declaration; + return lineEndingBefore(code); + } + effects.consume(code); + return declaration; + } + + /** + * In instruction. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function instruction(code) { + if (code === null) { + return nok(code); + } + if (code === 63) { + effects.consume(code); + return instructionClose; + } + if (markdownLineEnding(code)) { + returnState = instruction; + return lineEndingBefore(code); + } + effects.consume(code); + return instruction; + } + + /** + * In instruction, after `?`, at `>`. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function instructionClose(code) { + return code === 62 ? end(code) : instruction(code); + } + + /** + * After ` | a c + * ^ + * ``` + * + * @type {State} + */ + function tagCloseStart(code) { + // ASCII alphabetical. + if (asciiAlpha(code)) { + effects.consume(code); + return tagClose; + } + return nok(code); + } + + /** + * After ` | a c + * ^ + * ``` + * + * @type {State} + */ + function tagClose(code) { + // ASCII alphanumerical and `-`. + if (code === 45 || asciiAlphanumeric(code)) { + effects.consume(code); + return tagClose; + } + return tagCloseBetween(code); + } + + /** + * In closing tag, after tag name. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function tagCloseBetween(code) { + if (markdownLineEnding(code)) { + returnState = tagCloseBetween; + return lineEndingBefore(code); + } + if (markdownSpace(code)) { + effects.consume(code); + return tagCloseBetween; + } + return end(code); + } + + /** + * After ` | a c + * ^ + * ``` + * + * @type {State} + */ + function tagOpen(code) { + // ASCII alphanumerical and `-`. + if (code === 45 || asciiAlphanumeric(code)) { + effects.consume(code); + return tagOpen; + } + if (code === 47 || code === 62 || markdownLineEndingOrSpace(code)) { + return tagOpenBetween(code); + } + return nok(code); + } + + /** + * In opening tag, after tag name. + * + * ```markdown + * > | a c + * ^ + * ``` + * + * @type {State} + */ + function tagOpenBetween(code) { + if (code === 47) { + effects.consume(code); + return end; + } + + // ASCII alphabetical and `:` and `_`. + if (code === 58 || code === 95 || asciiAlpha(code)) { + effects.consume(code); + return tagOpenAttributeName; + } + if (markdownLineEnding(code)) { + returnState = tagOpenBetween; + return lineEndingBefore(code); + } + if (markdownSpace(code)) { + effects.consume(code); + return tagOpenBetween; + } + return end(code); + } + + /** + * In attribute name. + * + * ```markdown + * > | a d + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeName(code) { + // ASCII alphabetical and `-`, `.`, `:`, and `_`. + if (code === 45 || code === 46 || code === 58 || code === 95 || asciiAlphanumeric(code)) { + effects.consume(code); + return tagOpenAttributeName; + } + return tagOpenAttributeNameAfter(code); + } + + /** + * After attribute name, before initializer, the end of the tag, or + * whitespace. + * + * ```markdown + * > | a d + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeNameAfter(code) { + if (code === 61) { + effects.consume(code); + return tagOpenAttributeValueBefore; + } + if (markdownLineEnding(code)) { + returnState = tagOpenAttributeNameAfter; + return lineEndingBefore(code); + } + if (markdownSpace(code)) { + effects.consume(code); + return tagOpenAttributeNameAfter; + } + return tagOpenBetween(code); + } + + /** + * Before unquoted, double quoted, or single quoted attribute value, allowing + * whitespace. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeValueBefore(code) { + if (code === null || code === 60 || code === 61 || code === 62 || code === 96) { + return nok(code); + } + if (code === 34 || code === 39) { + effects.consume(code); + marker = code; + return tagOpenAttributeValueQuoted; + } + if (markdownLineEnding(code)) { + returnState = tagOpenAttributeValueBefore; + return lineEndingBefore(code); + } + if (markdownSpace(code)) { + effects.consume(code); + return tagOpenAttributeValueBefore; + } + effects.consume(code); + return tagOpenAttributeValueUnquoted; + } + + /** + * In double or single quoted attribute value. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeValueQuoted(code) { + if (code === marker) { + effects.consume(code); + marker = undefined; + return tagOpenAttributeValueQuotedAfter; + } + if (code === null) { + return nok(code); + } + if (markdownLineEnding(code)) { + returnState = tagOpenAttributeValueQuoted; + return lineEndingBefore(code); + } + effects.consume(code); + return tagOpenAttributeValueQuoted; + } + + /** + * In unquoted attribute value. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeValueUnquoted(code) { + if (code === null || code === 34 || code === 39 || code === 60 || code === 61 || code === 96) { + return nok(code); + } + if (code === 47 || code === 62 || markdownLineEndingOrSpace(code)) { + return tagOpenBetween(code); + } + effects.consume(code); + return tagOpenAttributeValueUnquoted; + } + + /** + * After double or single quoted attribute value, before whitespace or the end + * of the tag. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function tagOpenAttributeValueQuotedAfter(code) { + if (code === 47 || code === 62 || markdownLineEndingOrSpace(code)) { + return tagOpenBetween(code); + } + return nok(code); + } + + /** + * In certain circumstances of a tag where only an `>` is allowed. + * + * ```markdown + * > | a e + * ^ + * ``` + * + * @type {State} + */ + function end(code) { + if (code === 62) { + effects.consume(code); + effects.exit("htmlTextData"); + effects.exit("htmlText"); + return ok; + } + return nok(code); + } + + /** + * At eol. + * + * > 👉 **Note**: we can’t have blank lines in text, so no need to worry about + * > empty tokens. + * + * ```markdown + * > | a + * ``` + * + * @type {State} + */ + function lineEndingBefore(code) { + effects.exit("htmlTextData"); + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return lineEndingAfter; + } + + /** + * After eol, at optional whitespace. + * + * > 👉 **Note**: we can’t have blank lines in text, so no need to worry about + * > empty tokens. + * + * ```markdown + * | a + * ^ + * ``` + * + * @type {State} + */ + function lineEndingAfter(code) { + // Always populated by defaults. + + return markdownSpace(code) ? factorySpace(effects, lineEndingAfterPrefix, "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4)(code) : lineEndingAfterPrefix(code); + } + + /** + * After eol, after optional whitespace. + * + * > 👉 **Note**: we can’t have blank lines in text, so no need to worry about + * > empty tokens. + * + * ```markdown + * | a + * ^ + * ``` + * + * @type {State} + */ + function lineEndingAfterPrefix(code) { + effects.enter("htmlTextData"); + return returnState(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-end.d.ts b/node_modules/micromark-core-commonmark/lib/label-end.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c892edb7db82843a0b29f462379a327aa2fe47f6 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-end.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const labelEnd: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=label-end.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-end.d.ts.map b/node_modules/micromark-core-commonmark/lib/label-end.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..3d6348f618669da6df07fc2b5b150ac69601ef81 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-end.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"label-end.d.ts","sourceRoot":"","sources":["label-end.js"],"names":[],"mappings":"AAuBA,wBAAwB;AACxB,uBADW,SAAS,CAMnB;+BApBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-end.js b/node_modules/micromark-core-commonmark/lib/label-end.js new file mode 100644 index 0000000000000000000000000000000000000000..927808f648bac3803c8149d3b24c97e6def7e103 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-end.js @@ -0,0 +1,560 @@ +/** + * @import { + * Construct, + * Event, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import { factoryDestination } from 'micromark-factory-destination'; +import { factoryLabel } from 'micromark-factory-label'; +import { factoryTitle } from 'micromark-factory-title'; +import { factoryWhitespace } from 'micromark-factory-whitespace'; +import { markdownLineEndingOrSpace } from 'micromark-util-character'; +import { push, splice } from 'micromark-util-chunked'; +import { normalizeIdentifier } from 'micromark-util-normalize-identifier'; +import { resolveAll } from 'micromark-util-resolve-all'; +/** @type {Construct} */ +export const labelEnd = { + name: 'labelEnd', + resolveAll: resolveAllLabelEnd, + resolveTo: resolveToLabelEnd, + tokenize: tokenizeLabelEnd +}; + +/** @type {Construct} */ +const resourceConstruct = { + tokenize: tokenizeResource +}; +/** @type {Construct} */ +const referenceFullConstruct = { + tokenize: tokenizeReferenceFull +}; +/** @type {Construct} */ +const referenceCollapsedConstruct = { + tokenize: tokenizeReferenceCollapsed +}; + +/** @type {Resolver} */ +function resolveAllLabelEnd(events) { + let index = -1; + /** @type {Array} */ + const newEvents = []; + while (++index < events.length) { + const token = events[index][1]; + newEvents.push(events[index]); + if (token.type === "labelImage" || token.type === "labelLink" || token.type === "labelEnd") { + // Remove the marker. + const offset = token.type === "labelImage" ? 4 : 2; + token.type = "data"; + index += offset; + } + } + + // If the events are equal, we don't have to copy newEvents to events + if (events.length !== newEvents.length) { + splice(events, 0, events.length, newEvents); + } + return events; +} + +/** @type {Resolver} */ +function resolveToLabelEnd(events, context) { + let index = events.length; + let offset = 0; + /** @type {Token} */ + let token; + /** @type {number | undefined} */ + let open; + /** @type {number | undefined} */ + let close; + /** @type {Array} */ + let media; + + // Find an opening. + while (index--) { + token = events[index][1]; + if (open) { + // If we see another link, or inactive link label, we’ve been here before. + if (token.type === "link" || token.type === "labelLink" && token._inactive) { + break; + } + + // Mark other link openings as inactive, as we can’t have links in + // links. + if (events[index][0] === 'enter' && token.type === "labelLink") { + token._inactive = true; + } + } else if (close) { + if (events[index][0] === 'enter' && (token.type === "labelImage" || token.type === "labelLink") && !token._balanced) { + open = index; + if (token.type !== "labelLink") { + offset = 2; + break; + } + } + } else if (token.type === "labelEnd") { + close = index; + } + } + const group = { + type: events[open][1].type === "labelLink" ? "link" : "image", + start: { + ...events[open][1].start + }, + end: { + ...events[events.length - 1][1].end + } + }; + const label = { + type: "label", + start: { + ...events[open][1].start + }, + end: { + ...events[close][1].end + } + }; + const text = { + type: "labelText", + start: { + ...events[open + offset + 2][1].end + }, + end: { + ...events[close - 2][1].start + } + }; + media = [['enter', group, context], ['enter', label, context]]; + + // Opening marker. + media = push(media, events.slice(open + 1, open + offset + 3)); + + // Text open. + media = push(media, [['enter', text, context]]); + + // Always populated by defaults. + + // Between. + media = push(media, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open + offset + 4, close - 3), context)); + + // Text close, marker close, label close. + media = push(media, [['exit', text, context], events[close - 2], events[close - 1], ['exit', label, context]]); + + // Reference, resource, or so. + media = push(media, events.slice(close + 1)); + + // Media close. + media = push(media, [['exit', group, context]]); + splice(events, open, events.length, media); + return events; +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeLabelEnd(effects, ok, nok) { + const self = this; + let index = self.events.length; + /** @type {Token} */ + let labelStart; + /** @type {boolean} */ + let defined; + + // Find an opening. + while (index--) { + if ((self.events[index][1].type === "labelImage" || self.events[index][1].type === "labelLink") && !self.events[index][1]._balanced) { + labelStart = self.events[index][1]; + break; + } + } + return start; + + /** + * Start of label end. + * + * ```markdown + * > | [a](b) c + * ^ + * > | [a][b] c + * ^ + * > | [a][] b + * ^ + * > | [a] b + * ``` + * + * @type {State} + */ + function start(code) { + // If there is not an okay opening. + if (!labelStart) { + return nok(code); + } + + // If the corresponding label (link) start is marked as inactive, + // it means we’d be wrapping a link, like this: + // + // ```markdown + // > | a [b [c](d) e](f) g. + // ^ + // ``` + // + // We can’t have that, so it’s just balanced brackets. + if (labelStart._inactive) { + return labelEndNok(code); + } + defined = self.parser.defined.includes(normalizeIdentifier(self.sliceSerialize({ + start: labelStart.end, + end: self.now() + }))); + effects.enter("labelEnd"); + effects.enter("labelMarker"); + effects.consume(code); + effects.exit("labelMarker"); + effects.exit("labelEnd"); + return after; + } + + /** + * After `]`. + * + * ```markdown + * > | [a](b) c + * ^ + * > | [a][b] c + * ^ + * > | [a][] b + * ^ + * > | [a] b + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + // Note: `markdown-rs` also parses GFM footnotes here, which for us is in + // an extension. + + // Resource (`[asd](fgh)`)? + if (code === 40) { + return effects.attempt(resourceConstruct, labelEndOk, defined ? labelEndOk : labelEndNok)(code); + } + + // Full (`[asd][fgh]`) or collapsed (`[asd][]`) reference? + if (code === 91) { + return effects.attempt(referenceFullConstruct, labelEndOk, defined ? referenceNotFull : labelEndNok)(code); + } + + // Shortcut (`[asd]`) reference? + return defined ? labelEndOk(code) : labelEndNok(code); + } + + /** + * After `]`, at `[`, but not at a full reference. + * + * > 👉 **Note**: we only get here if the label is defined. + * + * ```markdown + * > | [a][] b + * ^ + * > | [a] b + * ^ + * ``` + * + * @type {State} + */ + function referenceNotFull(code) { + return effects.attempt(referenceCollapsedConstruct, labelEndOk, labelEndNok)(code); + } + + /** + * Done, we found something. + * + * ```markdown + * > | [a](b) c + * ^ + * > | [a][b] c + * ^ + * > | [a][] b + * ^ + * > | [a] b + * ^ + * ``` + * + * @type {State} + */ + function labelEndOk(code) { + // Note: `markdown-rs` does a bunch of stuff here. + return ok(code); + } + + /** + * Done, it’s nothing. + * + * There was an okay opening, but we didn’t match anything. + * + * ```markdown + * > | [a](b c + * ^ + * > | [a][b c + * ^ + * > | [a] b + * ^ + * ``` + * + * @type {State} + */ + function labelEndNok(code) { + labelStart._balanced = true; + return nok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeResource(effects, ok, nok) { + return resourceStart; + + /** + * At a resource. + * + * ```markdown + * > | [a](b) c + * ^ + * ``` + * + * @type {State} + */ + function resourceStart(code) { + effects.enter("resource"); + effects.enter("resourceMarker"); + effects.consume(code); + effects.exit("resourceMarker"); + return resourceBefore; + } + + /** + * In resource, after `(`, at optional whitespace. + * + * ```markdown + * > | [a](b) c + * ^ + * ``` + * + * @type {State} + */ + function resourceBefore(code) { + return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, resourceOpen)(code) : resourceOpen(code); + } + + /** + * In resource, after optional whitespace, at `)` or a destination. + * + * ```markdown + * > | [a](b) c + * ^ + * ``` + * + * @type {State} + */ + function resourceOpen(code) { + if (code === 41) { + return resourceEnd(code); + } + return factoryDestination(effects, resourceDestinationAfter, resourceDestinationMissing, "resourceDestination", "resourceDestinationLiteral", "resourceDestinationLiteralMarker", "resourceDestinationRaw", "resourceDestinationString", 32)(code); + } + + /** + * In resource, after destination, at optional whitespace. + * + * ```markdown + * > | [a](b) c + * ^ + * ``` + * + * @type {State} + */ + function resourceDestinationAfter(code) { + return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, resourceBetween)(code) : resourceEnd(code); + } + + /** + * At invalid destination. + * + * ```markdown + * > | [a](<<) b + * ^ + * ``` + * + * @type {State} + */ + function resourceDestinationMissing(code) { + return nok(code); + } + + /** + * In resource, after destination and whitespace, at `(` or title. + * + * ```markdown + * > | [a](b ) c + * ^ + * ``` + * + * @type {State} + */ + function resourceBetween(code) { + if (code === 34 || code === 39 || code === 40) { + return factoryTitle(effects, resourceTitleAfter, nok, "resourceTitle", "resourceTitleMarker", "resourceTitleString")(code); + } + return resourceEnd(code); + } + + /** + * In resource, after title, at optional whitespace. + * + * ```markdown + * > | [a](b "c") d + * ^ + * ``` + * + * @type {State} + */ + function resourceTitleAfter(code) { + return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, resourceEnd)(code) : resourceEnd(code); + } + + /** + * In resource, at `)`. + * + * ```markdown + * > | [a](b) d + * ^ + * ``` + * + * @type {State} + */ + function resourceEnd(code) { + if (code === 41) { + effects.enter("resourceMarker"); + effects.consume(code); + effects.exit("resourceMarker"); + effects.exit("resource"); + return ok; + } + return nok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeReferenceFull(effects, ok, nok) { + const self = this; + return referenceFull; + + /** + * In a reference (full), at the `[`. + * + * ```markdown + * > | [a][b] d + * ^ + * ``` + * + * @type {State} + */ + function referenceFull(code) { + return factoryLabel.call(self, effects, referenceFullAfter, referenceFullMissing, "reference", "referenceMarker", "referenceString")(code); + } + + /** + * In a reference (full), after `]`. + * + * ```markdown + * > | [a][b] d + * ^ + * ``` + * + * @type {State} + */ + function referenceFullAfter(code) { + return self.parser.defined.includes(normalizeIdentifier(self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1))) ? ok(code) : nok(code); + } + + /** + * In reference (full) that was missing. + * + * ```markdown + * > | [a][b d + * ^ + * ``` + * + * @type {State} + */ + function referenceFullMissing(code) { + return nok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeReferenceCollapsed(effects, ok, nok) { + return referenceCollapsedStart; + + /** + * In reference (collapsed), at `[`. + * + * > 👉 **Note**: we only get here if the label is defined. + * + * ```markdown + * > | [a][] d + * ^ + * ``` + * + * @type {State} + */ + function referenceCollapsedStart(code) { + // We only attempt a collapsed label if there’s a `[`. + + effects.enter("reference"); + effects.enter("referenceMarker"); + effects.consume(code); + effects.exit("referenceMarker"); + return referenceCollapsedOpen; + } + + /** + * In reference (collapsed), at `]`. + * + * > 👉 **Note**: we only get here if the label is defined. + * + * ```markdown + * > | [a][] d + * ^ + * ``` + * + * @type {State} + */ + function referenceCollapsedOpen(code) { + if (code === 93) { + effects.enter("referenceMarker"); + effects.consume(code); + effects.exit("referenceMarker"); + effects.exit("reference"); + return ok; + } + return nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-start-image.d.ts b/node_modules/micromark-core-commonmark/lib/label-start-image.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..0a3c6903b673bf64e9072788ce5715586afba77d --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-start-image.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const labelStartImage: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=label-start-image.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-start-image.d.ts.map b/node_modules/micromark-core-commonmark/lib/label-start-image.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..e41dbf7453b2769fdcc28edbb1febafd946a2e2b --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-start-image.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"label-start-image.d.ts","sourceRoot":"","sources":["label-start-image.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,8BADW,SAAS,CAKnB;+BAZS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-start-image.js b/node_modules/micromark-core-commonmark/lib/label-start-image.js new file mode 100644 index 0000000000000000000000000000000000000000..064080a6d43025768d6465f74321d22ed95a16ef --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-start-image.js @@ -0,0 +1,102 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { labelEnd } from './label-end.js'; + +/** @type {Construct} */ +export const labelStartImage = { + name: 'labelStartImage', + resolveAll: labelEnd.resolveAll, + tokenize: tokenizeLabelStartImage +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeLabelStartImage(effects, ok, nok) { + const self = this; + return start; + + /** + * Start of label (image) start. + * + * ```markdown + * > | a ![b] c + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("labelImage"); + effects.enter("labelImageMarker"); + effects.consume(code); + effects.exit("labelImageMarker"); + return open; + } + + /** + * After `!`, at `[`. + * + * ```markdown + * > | a ![b] c + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (code === 91) { + effects.enter("labelMarker"); + effects.consume(code); + effects.exit("labelMarker"); + effects.exit("labelImage"); + return after; + } + return nok(code); + } + + /** + * After `![`. + * + * ```markdown + * > | a ![b] c + * ^ + * ``` + * + * This is needed in because, when GFM footnotes are enabled, images never + * form when started with a `^`. + * Instead, links form: + * + * ```markdown + * ![^a](b) + * + * ![^a][b] + * + * [b]: c + * ``` + * + * ```html + *

!^a

+ *

!^a

+ * ``` + * + * @type {State} + */ + function after(code) { + // To do: use a new field to do this, this is still needed for + // `micromark-extension-gfm-footnote`, but the `label-start-link` + // behavior isn’t. + // Hidden footnotes hook. + /* c8 ignore next 3 */ + return code === 94 && '_hiddenFootnoteSupport' in self.parser.constructs ? nok(code) : ok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-start-link.d.ts b/node_modules/micromark-core-commonmark/lib/label-start-link.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..955c873ff3dcafb631cec59cf7b54512272d4aba --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-start-link.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const labelStartLink: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=label-start-link.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-start-link.d.ts.map b/node_modules/micromark-core-commonmark/lib/label-start-link.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b242831ba15fac1a3725811dea1e9d32d39b02d7 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-start-link.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"label-start-link.d.ts","sourceRoot":"","sources":["label-start-link.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,6BADW,SAAS,CAKnB;+BAZS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/label-start-link.js b/node_modules/micromark-core-commonmark/lib/label-start-link.js new file mode 100644 index 0000000000000000000000000000000000000000..2792d87ac75869ce1692455732b446ba14f4590a --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/label-start-link.js @@ -0,0 +1,55 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { labelEnd } from './label-end.js'; + +/** @type {Construct} */ +export const labelStartLink = { + name: 'labelStartLink', + resolveAll: labelEnd.resolveAll, + tokenize: tokenizeLabelStartLink +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeLabelStartLink(effects, ok, nok) { + const self = this; + return start; + + /** + * Start of label (link) start. + * + * ```markdown + * > | a [b] c + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("labelLink"); + effects.enter("labelMarker"); + effects.consume(code); + effects.exit("labelMarker"); + effects.exit("labelLink"); + return after; + } + + /** @type {State} */ + function after(code) { + // To do: this isn’t needed in `micromark-extension-gfm-footnote`, + // remove. + // Hidden footnotes hook. + /* c8 ignore next 3 */ + return code === 94 && '_hiddenFootnoteSupport' in self.parser.constructs ? nok(code) : ok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/line-ending.d.ts b/node_modules/micromark-core-commonmark/lib/line-ending.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3eb4a88afb8ec44f64729914b561e9fc5eb38d02 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/line-ending.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const lineEnding: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=line-ending.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/line-ending.d.ts.map b/node_modules/micromark-core-commonmark/lib/line-ending.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..22bb64a5bed6c25aded0771488c316b138f07c05 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/line-ending.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"line-ending.d.ts","sourceRoot":"","sources":["line-ending.js"],"names":[],"mappings":"AAcA,wBAAwB;AACxB,yBADW,SAAS,CACwD;+BATlE,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/line-ending.js b/node_modules/micromark-core-commonmark/lib/line-ending.js new file mode 100644 index 0000000000000000000000000000000000000000..4df14d6f8dfcf6a24ffa3fbca639a2d6ded334ec --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/line-ending.js @@ -0,0 +1,33 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding } from 'micromark-util-character'; +/** @type {Construct} */ +export const lineEnding = { + name: 'lineEnding', + tokenize: tokenizeLineEnding +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeLineEnding(effects, ok) { + return start; + + /** @type {State} */ + function start(code) { + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return factorySpace(effects, ok, "linePrefix"); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/list.d.ts b/node_modules/micromark-core-commonmark/lib/list.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ebecfda629530ee4e2f129755d795c8111ee5879 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/list.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const list: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=list.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/list.d.ts.map b/node_modules/micromark-core-commonmark/lib/list.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..8731fa642c91a3f999c2781be6c26ce41e253ba3 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/list.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["list.js"],"names":[],"mappings":"AAkBA,wBAAwB;AACxB,mBADW,SAAS,CAMnB;+BAhBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/list.js b/node_modules/micromark-core-commonmark/lib/list.js new file mode 100644 index 0000000000000000000000000000000000000000..dd3368ecbc8a1995cfdaab38b08738f01b4c02b1 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/list.js @@ -0,0 +1,213 @@ +/** + * @import { + * Code, + * Construct, + * Exiter, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { asciiDigit, markdownSpace } from 'micromark-util-character'; +import { blankLine } from './blank-line.js'; +import { thematicBreak } from './thematic-break.js'; + +/** @type {Construct} */ +export const list = { + continuation: { + tokenize: tokenizeListContinuation + }, + exit: tokenizeListEnd, + name: 'list', + tokenize: tokenizeListStart +}; + +/** @type {Construct} */ +const listItemPrefixWhitespaceConstruct = { + partial: true, + tokenize: tokenizeListItemPrefixWhitespace +}; + +/** @type {Construct} */ +const indentConstruct = { + partial: true, + tokenize: tokenizeIndent +}; + +// To do: `markdown-rs` parses list items on their own and later stitches them +// together. + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeListStart(effects, ok, nok) { + const self = this; + const tail = self.events[self.events.length - 1]; + let initialSize = tail && tail[1].type === "linePrefix" ? tail[2].sliceSerialize(tail[1], true).length : 0; + let size = 0; + return start; + + /** @type {State} */ + function start(code) { + const kind = self.containerState.type || (code === 42 || code === 43 || code === 45 ? "listUnordered" : "listOrdered"); + if (kind === "listUnordered" ? !self.containerState.marker || code === self.containerState.marker : asciiDigit(code)) { + if (!self.containerState.type) { + self.containerState.type = kind; + effects.enter(kind, { + _container: true + }); + } + if (kind === "listUnordered") { + effects.enter("listItemPrefix"); + return code === 42 || code === 45 ? effects.check(thematicBreak, nok, atMarker)(code) : atMarker(code); + } + if (!self.interrupt || code === 49) { + effects.enter("listItemPrefix"); + effects.enter("listItemValue"); + return inside(code); + } + } + return nok(code); + } + + /** @type {State} */ + function inside(code) { + if (asciiDigit(code) && ++size < 10) { + effects.consume(code); + return inside; + } + if ((!self.interrupt || size < 2) && (self.containerState.marker ? code === self.containerState.marker : code === 41 || code === 46)) { + effects.exit("listItemValue"); + return atMarker(code); + } + return nok(code); + } + + /** + * @type {State} + **/ + function atMarker(code) { + effects.enter("listItemMarker"); + effects.consume(code); + effects.exit("listItemMarker"); + self.containerState.marker = self.containerState.marker || code; + return effects.check(blankLine, + // Can’t be empty when interrupting. + self.interrupt ? nok : onBlank, effects.attempt(listItemPrefixWhitespaceConstruct, endOfPrefix, otherPrefix)); + } + + /** @type {State} */ + function onBlank(code) { + self.containerState.initialBlankLine = true; + initialSize++; + return endOfPrefix(code); + } + + /** @type {State} */ + function otherPrefix(code) { + if (markdownSpace(code)) { + effects.enter("listItemPrefixWhitespace"); + effects.consume(code); + effects.exit("listItemPrefixWhitespace"); + return endOfPrefix; + } + return nok(code); + } + + /** @type {State} */ + function endOfPrefix(code) { + self.containerState.size = initialSize + self.sliceSerialize(effects.exit("listItemPrefix"), true).length; + return ok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeListContinuation(effects, ok, nok) { + const self = this; + self.containerState._closeFlow = undefined; + return effects.check(blankLine, onBlank, notBlank); + + /** @type {State} */ + function onBlank(code) { + self.containerState.furtherBlankLines = self.containerState.furtherBlankLines || self.containerState.initialBlankLine; + + // We have a blank line. + // Still, try to consume at most the items size. + return factorySpace(effects, ok, "listItemIndent", self.containerState.size + 1)(code); + } + + /** @type {State} */ + function notBlank(code) { + if (self.containerState.furtherBlankLines || !markdownSpace(code)) { + self.containerState.furtherBlankLines = undefined; + self.containerState.initialBlankLine = undefined; + return notInCurrentItem(code); + } + self.containerState.furtherBlankLines = undefined; + self.containerState.initialBlankLine = undefined; + return effects.attempt(indentConstruct, ok, notInCurrentItem)(code); + } + + /** @type {State} */ + function notInCurrentItem(code) { + // While we do continue, we signal that the flow should be closed. + self.containerState._closeFlow = true; + // As we’re closing flow, we’re no longer interrupting. + self.interrupt = undefined; + // Always populated by defaults. + + return factorySpace(effects, effects.attempt(list, ok, nok), "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4)(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeIndent(effects, ok, nok) { + const self = this; + return factorySpace(effects, afterPrefix, "listItemIndent", self.containerState.size + 1); + + /** @type {State} */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1]; + return tail && tail[1].type === "listItemIndent" && tail[2].sliceSerialize(tail[1], true).length === self.containerState.size ? ok(code) : nok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Exiter} + */ +function tokenizeListEnd(effects) { + effects.exit(this.containerState.type); +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeListItemPrefixWhitespace(effects, ok, nok) { + const self = this; + + // Always populated by defaults. + + return factorySpace(effects, afterPrefix, "listItemPrefixWhitespace", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4 + 1); + + /** @type {State} */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1]; + return !markdownSpace(code) && tail && tail[1].type === "listItemPrefixWhitespace" ? ok(code) : nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/setext-underline.d.ts b/node_modules/micromark-core-commonmark/lib/setext-underline.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d7ca340f4f659fa79d6438660bcdd3a0c8583a21 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/setext-underline.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const setextUnderline: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=setext-underline.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/setext-underline.d.ts.map b/node_modules/micromark-core-commonmark/lib/setext-underline.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..296f7c681e31b0a670a4a5091c194be9a77d82ae --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/setext-underline.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"setext-underline.d.ts","sourceRoot":"","sources":["setext-underline.js"],"names":[],"mappings":"AAgBA,wBAAwB;AACxB,8BADW,SAAS,CAKnB;+BAbS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/setext-underline.js b/node_modules/micromark-core-commonmark/lib/setext-underline.js new file mode 100644 index 0000000000000000000000000000000000000000..5660dd97328b05c3512c6b431919f0c1dba655a3 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/setext-underline.js @@ -0,0 +1,185 @@ +/** + * @import { + * Code, + * Construct, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding, markdownSpace } from 'micromark-util-character'; +/** @type {Construct} */ +export const setextUnderline = { + name: 'setextUnderline', + resolveTo: resolveToSetextUnderline, + tokenize: tokenizeSetextUnderline +}; + +/** @type {Resolver} */ +function resolveToSetextUnderline(events, context) { + // To do: resolve like `markdown-rs`. + let index = events.length; + /** @type {number | undefined} */ + let content; + /** @type {number | undefined} */ + let text; + /** @type {number | undefined} */ + let definition; + + // Find the opening of the content. + // It’ll always exist: we don’t tokenize if it isn’t there. + while (index--) { + if (events[index][0] === 'enter') { + if (events[index][1].type === "content") { + content = index; + break; + } + if (events[index][1].type === "paragraph") { + text = index; + } + } + // Exit + else { + if (events[index][1].type === "content") { + // Remove the content end (if needed we’ll add it later) + events.splice(index, 1); + } + if (!definition && events[index][1].type === "definition") { + definition = index; + } + } + } + const heading = { + type: "setextHeading", + start: { + ...events[content][1].start + }, + end: { + ...events[events.length - 1][1].end + } + }; + + // Change the paragraph to setext heading text. + events[text][1].type = "setextHeadingText"; + + // If we have definitions in the content, we’ll keep on having content, + // but we need move it. + if (definition) { + events.splice(text, 0, ['enter', heading, context]); + events.splice(definition + 1, 0, ['exit', events[content][1], context]); + events[content][1].end = { + ...events[definition][1].end + }; + } else { + events[content][1] = heading; + } + + // Add the heading exit at the end. + events.push(['exit', heading, context]); + return events; +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeSetextUnderline(effects, ok, nok) { + const self = this; + /** @type {NonNullable} */ + let marker; + return start; + + /** + * At start of heading (setext) underline. + * + * ```markdown + * | aa + * > | == + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + let index = self.events.length; + /** @type {boolean | undefined} */ + let paragraph; + // Find an opening. + while (index--) { + // Skip enter/exit of line ending, line prefix, and content. + // We can now either have a definition or a paragraph. + if (self.events[index][1].type !== "lineEnding" && self.events[index][1].type !== "linePrefix" && self.events[index][1].type !== "content") { + paragraph = self.events[index][1].type === "paragraph"; + break; + } + } + + // To do: handle lazy/pierce like `markdown-rs`. + // To do: parse indent like `markdown-rs`. + if (!self.parser.lazy[self.now().line] && (self.interrupt || paragraph)) { + effects.enter("setextHeadingLine"); + marker = code; + return before(code); + } + return nok(code); + } + + /** + * After optional whitespace, at `-` or `=`. + * + * ```markdown + * | aa + * > | == + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + effects.enter("setextHeadingLineSequence"); + return inside(code); + } + + /** + * In sequence. + * + * ```markdown + * | aa + * > | == + * ^ + * ``` + * + * @type {State} + */ + function inside(code) { + if (code === marker) { + effects.consume(code); + return inside; + } + effects.exit("setextHeadingLineSequence"); + return markdownSpace(code) ? factorySpace(effects, after, "lineSuffix")(code) : after(code); + } + + /** + * After sequence, after optional whitespace. + * + * ```markdown + * | aa + * > | == + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("setextHeadingLine"); + return ok(code); + } + return nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/thematic-break.d.ts b/node_modules/micromark-core-commonmark/lib/thematic-break.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..51e9e97c650792cb0bc40c6e7065c1705796c4ac --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/thematic-break.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const thematicBreak: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=thematic-break.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/thematic-break.d.ts.map b/node_modules/micromark-core-commonmark/lib/thematic-break.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..d10a65bbc279681c956eddb067552b05eb8ba5a3 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/thematic-break.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"thematic-break.d.ts","sourceRoot":"","sources":["thematic-break.js"],"names":[],"mappings":"AAeA,wBAAwB;AACxB,4BADW,SAAS,CAInB;+BAZS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/thematic-break.js b/node_modules/micromark-core-commonmark/lib/thematic-break.js new file mode 100644 index 0000000000000000000000000000000000000000..ba3fb1990204a9568574067fbe95f49fe06a7f67 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/thematic-break.js @@ -0,0 +1,102 @@ +/** + * @import { + * Code, + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding, markdownSpace } from 'micromark-util-character'; +/** @type {Construct} */ +export const thematicBreak = { + name: 'thematicBreak', + tokenize: tokenizeThematicBreak +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeThematicBreak(effects, ok, nok) { + let size = 0; + /** @type {NonNullable} */ + let marker; + return start; + + /** + * Start of thematic break. + * + * ```markdown + * > | *** + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("thematicBreak"); + // To do: parse indent like `markdown-rs`. + return before(code); + } + + /** + * After optional whitespace, at marker. + * + * ```markdown + * > | *** + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + marker = code; + return atBreak(code); + } + + /** + * After something, before something else. + * + * ```markdown + * > | *** + * ^ + * ``` + * + * @type {State} + */ + function atBreak(code) { + if (code === marker) { + effects.enter("thematicBreakSequence"); + return sequence(code); + } + if (size >= 3 && (code === null || markdownLineEnding(code))) { + effects.exit("thematicBreak"); + return ok(code); + } + return nok(code); + } + + /** + * In sequence. + * + * ```markdown + * > | *** + * ^ + * ``` + * + * @type {State} + */ + function sequence(code) { + if (code === marker) { + effects.consume(code); + size++; + return sequence; + } + effects.exit("thematicBreakSequence"); + return markdownSpace(code) ? factorySpace(effects, atBreak, "whitespace")(code) : atBreak(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/license b/node_modules/micromark-core-commonmark/license new file mode 100644 index 0000000000000000000000000000000000000000..bc8f165a62768a19de38901d81ac662c51ff29db --- /dev/null +++ b/node_modules/micromark-core-commonmark/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark-core-commonmark/package.json b/node_modules/micromark-core-commonmark/package.json new file mode 100644 index 0000000000000000000000000000000000000000..3798a68ef0d83cdbf01dff525041286f4cd9ba43 --- /dev/null +++ b/node_modules/micromark-core-commonmark/package.json @@ -0,0 +1,74 @@ +{ + "name": "micromark-core-commonmark", + "version": "2.0.3", + "description": "The CommonMark markdown constructs", + "license": "MIT", + "keywords": [ + "micromark", + "core", + "commonmark" + ], + "repository": "https://github.com/micromark/micromark/tree/main/packages/micromark-core-commonmark", + "bugs": "https://github.com/micromark/micromark/issues", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "files": [ + "dev/", + "lib/", + "index.d.ts.map", + "index.d.ts", + "index.js" + ], + "exports": { + "development": "./dev/index.js", + "default": "./index.js" + }, + "dependencies": { + "decode-named-character-reference": "^1.0.0", + "devlop": "^1.0.0", + "micromark-factory-destination": "^2.0.0", + "micromark-factory-label": "^2.0.0", + "micromark-factory-space": "^2.0.0", + "micromark-factory-title": "^2.0.0", + "micromark-factory-whitespace": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-chunked": "^2.0.0", + "micromark-util-classify-character": "^2.0.0", + "micromark-util-html-tag-name": "^2.0.0", + "micromark-util-normalize-identifier": "^2.0.0", + "micromark-util-resolve-all": "^2.0.0", + "micromark-util-subtokenize": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + }, + "scripts": { + "build": "micromark-build" + }, + "xo": { + "envs": [ + "shared-node-browser" + ], + "prettier": true, + "rules": { + "logical-assignment-operators": "off", + "max-depth": "off", + "unicorn/no-this-assignment": "off", + "unicorn/prefer-at": "off", + "unicorn/prefer-code-point": "off" + } + } +} diff --git a/node_modules/micromark-core-commonmark/readme.md b/node_modules/micromark-core-commonmark/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..5cc8b7cafb443a124ffbe1859e03a4a51b9afd47 --- /dev/null +++ b/node_modules/micromark-core-commonmark/readme.md @@ -0,0 +1,171 @@ +# micromark-core-commonmark + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][bundle-size-badge]][bundle-size] +[![Sponsors][sponsors-badge]][opencollective] +[![Backers][backers-badge]][opencollective] +[![Chat][chat-badge]][chat] + +[micromark][] constructs that make up the core of CommonMark. +Some of these can be [turned off][disable], but they are often essential to +markdown and weird things might happen. + +## Contents + +* [What is this?](#what-is-this) +* [When should I use this?](#when-should-i-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package exposes the default constructs. + +## When should I use this? + +This package is useful when you are making your own micromark extensions. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install micromark-core-commonmark +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import * as core from 'https://esm.sh/micromark-core-commonmark@1' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +```js +import {autolink} from 'micromark-core-commonmark' + +console.log(autolink) // Do things with `autolink`. +``` + +## API + +This module exports the following identifiers: `attention`, `autolink`, +`blankLine`, `blockQuote`, `characterEscape`, `characterReference`, +`codeFenced`, `codeIndented`, `codeText`, `content`, `definition`, +`hardBreakEscape`, `headingAtx`, `htmlFlow`, `htmlText`, `labelEnd`, +`labelStartImage`, `labelStartLink`, `lineEnding`, `list`, `setextUnderline`, +`thematicBreak`. +There is no default export. + +Each identifier refers to a [construct][]. + +See the code for more on the exported constructs. + +## Types + +This package is fully typed with [TypeScript][]. +It exports no additional types. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`micromark-core-commonmark@2`, compatible with Node.js 16. +This package works with `micromark@3`. + +## Security + +This package is safe. +See [`security.md`][securitymd] in [`micromark/.github`][health] for how to +submit a security report. + +## Contribute + +See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways +to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organisation, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[author]: https://wooorm.com + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[build]: https://github.com/micromark/micromark/actions + +[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg + +[bundle-size]: https://bundlejs.com/?q=micromark-core-commonmark + +[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-core-commonmark + +[chat]: https://github.com/micromark/micromark/discussions + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md + +[construct]: https://github.com/micromark/micromark#constructs + +[contributing]: https://github.com/micromark/.github/blob/main/contributing.md + +[coverage]: https://codecov.io/github/micromark/micromark + +[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg + +[disable]: https://github.com/micromark/micromark#case-turn-off-constructs + +[downloads]: https://www.npmjs.com/package/micromark-core-commonmark + +[downloads-badge]: https://img.shields.io/npm/dm/micromark-core-commonmark.svg + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[health]: https://github.com/micromark/.github + +[license]: https://github.com/micromark/micromark/blob/main/license + +[micromark]: https://github.com/micromark/micromark + +[npm]: https://docs.npmjs.com/cli/install + +[opencollective]: https://opencollective.com/unified + +[securitymd]: https://github.com/micromark/.github/blob/main/security.md + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[support]: https://github.com/micromark/.github/blob/main/support.md + +[typescript]: https://www.typescriptlang.org diff --git a/node_modules/micromark-extension-gfm-autolink-literal/dev/index.d.ts b/node_modules/micromark-extension-gfm-autolink-literal/dev/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..36f53b55bf7d7494d1ed6a8b21564825e385142f --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/dev/index.d.ts @@ -0,0 +1,24 @@ +export {gfmAutolinkLiteral} from './lib/syntax.js' +export {gfmAutolinkLiteralHtml} from './lib/html.js' + +/** + * Augment types. + */ +declare module 'micromark-util-types' { + /** + * Augment token with a field to improve performance. + */ + interface Token { + _gfmAutolinkLiteralWalkedInto?: boolean + } + + /** + * Token types. + */ + interface TokenTypeMap { + literalAutolink: 'literalAutolink' + literalAutolinkEmail: 'literalAutolinkEmail' + literalAutolinkHttp: 'literalAutolinkHttp' + literalAutolinkWww: 'literalAutolinkWww' + } +} diff --git a/node_modules/micromark-extension-gfm-autolink-literal/dev/index.js b/node_modules/micromark-extension-gfm-autolink-literal/dev/index.js new file mode 100644 index 0000000000000000000000000000000000000000..928d4456ab6b3955721b70f09fb05d1bdf22e8b0 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/dev/index.js @@ -0,0 +1,2 @@ +export {gfmAutolinkLiteral} from './lib/syntax.js' +export {gfmAutolinkLiteralHtml} from './lib/html.js' diff --git a/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/html.d.ts b/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..250ffc8fbe401c34891c4a5aed329cad6ec49f25 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/html.d.ts @@ -0,0 +1,10 @@ +/** + * Create an HTML extension for `micromark` to support GitHub autolink literal + * when serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GitHub autolink literal when serializing to HTML. + */ +export function gfmAutolinkLiteralHtml(): HtmlExtension; +import type { HtmlExtension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/html.js b/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..7b8145b346651fd9abc0089c5371f39383839555 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/html.js @@ -0,0 +1,56 @@ +/** + * @import {CompileContext, Handle, HtmlExtension, Token} from 'micromark-util-types' + */ + +import {sanitizeUri} from 'micromark-util-sanitize-uri' + +/** + * Create an HTML extension for `micromark` to support GitHub autolink literal + * when serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GitHub autolink literal when serializing to HTML. + */ +export function gfmAutolinkLiteralHtml() { + return { + exit: {literalAutolinkEmail, literalAutolinkHttp, literalAutolinkWww} + } +} + +/** + * @this {CompileContext} + * @type {Handle} + */ +function literalAutolinkWww(token) { + anchorFromToken.call(this, token, 'http://') +} + +/** + * @this {CompileContext} + * @type {Handle} + */ +function literalAutolinkEmail(token) { + anchorFromToken.call(this, token, 'mailto:') +} + +/** + * @this {CompileContext} + * @type {Handle} + */ +function literalAutolinkHttp(token) { + anchorFromToken.call(this, token) +} + +/** + * @this CompileContext + * @param {Token} token + * @param {string | null | undefined} [protocol] + * @returns {undefined} + */ +function anchorFromToken(token, protocol) { + const url = this.sliceSerialize(token) + this.tag('') + this.raw(this.encode(url)) + this.tag('') +} diff --git a/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fc2ddfab5391b1bb2036725392923572bff608e4 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/syntax.d.ts @@ -0,0 +1,10 @@ +/** + * Create an extension for `micromark` to support GitHub autolink literal + * syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * autolink literal syntax. + */ +export function gfmAutolinkLiteral(): Extension; +import type { Extension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/syntax.js b/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..904e27200ae4980183beda525d33feef70c2e7f7 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/dev/lib/syntax.js @@ -0,0 +1,983 @@ +/** + * @import {Code, ConstructRecord, Event, Extension, Previous, State, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +import { + asciiAlpha, + asciiAlphanumeric, + asciiControl, + markdownLineEndingOrSpace, + unicodePunctuation, + unicodeWhitespace +} from 'micromark-util-character' +import {codes} from 'micromark-util-symbol' + +const wwwPrefix = {tokenize: tokenizeWwwPrefix, partial: true} +const domain = {tokenize: tokenizeDomain, partial: true} +const path = {tokenize: tokenizePath, partial: true} +const trail = {tokenize: tokenizeTrail, partial: true} +const emailDomainDotTrail = { + tokenize: tokenizeEmailDomainDotTrail, + partial: true +} + +const wwwAutolink = { + name: 'wwwAutolink', + tokenize: tokenizeWwwAutolink, + previous: previousWww +} + +const protocolAutolink = { + name: 'protocolAutolink', + tokenize: tokenizeProtocolAutolink, + previous: previousProtocol +} + +const emailAutolink = { + name: 'emailAutolink', + tokenize: tokenizeEmailAutolink, + previous: previousEmail +} + +/** @type {ConstructRecord} */ +const text = {} + +/** + * Create an extension for `micromark` to support GitHub autolink literal + * syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * autolink literal syntax. + */ +export function gfmAutolinkLiteral() { + return {text} +} + +/** @type {Code} */ +let code = codes.digit0 + +// Add alphanumerics. +while (code < codes.leftCurlyBrace) { + text[code] = emailAutolink + code++ + if (code === codes.colon) code = codes.uppercaseA + else if (code === codes.leftSquareBracket) code = codes.lowercaseA +} + +text[codes.plusSign] = emailAutolink +text[codes.dash] = emailAutolink +text[codes.dot] = emailAutolink +text[codes.underscore] = emailAutolink +text[codes.uppercaseH] = [emailAutolink, protocolAutolink] +text[codes.lowercaseH] = [emailAutolink, protocolAutolink] +text[codes.uppercaseW] = [emailAutolink, wwwAutolink] +text[codes.lowercaseW] = [emailAutolink, wwwAutolink] + +// To do: perform email autolink literals on events, afterwards. +// That’s where `markdown-rs` and `cmark-gfm` perform it. +// It should look for `@`, then for atext backwards, and then for a label +// forwards. +// To do: `mailto:`, `xmpp:` protocol as prefix. + +/** + * Email autolink literal. + * + * ```markdown + * > | a contact@example.org b + * ^^^^^^^^^^^^^^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeEmailAutolink(effects, ok, nok) { + const self = this + /** @type {boolean | undefined} */ + let dot + /** @type {boolean} */ + let data + + return start + + /** + * Start of email autolink literal. + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + if ( + !gfmAtext(code) || + !previousEmail.call(self, self.previous) || + previousUnbalanced(self.events) + ) { + return nok(code) + } + + effects.enter('literalAutolink') + effects.enter('literalAutolinkEmail') + return atext(code) + } + + /** + * In email atext. + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function atext(code) { + if (gfmAtext(code)) { + effects.consume(code) + return atext + } + + if (code === codes.atSign) { + effects.consume(code) + return emailDomain + } + + return nok(code) + } + + /** + * In email domain. + * + * The reference code is a bit overly complex as it handles the `@`, of which + * there may be just one. + * Source: + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function emailDomain(code) { + // Dot followed by alphanumerical (not `-` or `_`). + if (code === codes.dot) { + return effects.check( + emailDomainDotTrail, + emailDomainAfter, + emailDomainDot + )(code) + } + + // Alphanumerical, `-`, and `_`. + if ( + code === codes.dash || + code === codes.underscore || + asciiAlphanumeric(code) + ) { + data = true + effects.consume(code) + return emailDomain + } + + // To do: `/` if xmpp. + + // Note: normally we’d truncate trailing punctuation from the link. + // However, email autolink literals cannot contain any of those markers, + // except for `.`, but that can only occur if it isn’t trailing. + // So we can ignore truncating! + return emailDomainAfter(code) + } + + /** + * In email domain, on dot that is not a trail. + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function emailDomainDot(code) { + effects.consume(code) + dot = true + return emailDomain + } + + /** + * After email domain. + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function emailDomainAfter(code) { + // Domain must not be empty, must include a dot, and must end in alphabetical. + // Source: . + if (data && dot && asciiAlpha(self.previous)) { + effects.exit('literalAutolinkEmail') + effects.exit('literalAutolink') + return ok(code) + } + + return nok(code) + } +} + +/** + * `www` autolink literal. + * + * ```markdown + * > | a www.example.org b + * ^^^^^^^^^^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeWwwAutolink(effects, ok, nok) { + const self = this + + return wwwStart + + /** + * Start of www autolink literal. + * + * ```markdown + * > | www.example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function wwwStart(code) { + if ( + (code !== codes.uppercaseW && code !== codes.lowercaseW) || + !previousWww.call(self, self.previous) || + previousUnbalanced(self.events) + ) { + return nok(code) + } + + effects.enter('literalAutolink') + effects.enter('literalAutolinkWww') + // Note: we *check*, so we can discard the `www.` we parsed. + // If it worked, we consider it as a part of the domain. + return effects.check( + wwwPrefix, + effects.attempt(domain, effects.attempt(path, wwwAfter), nok), + nok + )(code) + } + + /** + * After a www autolink literal. + * + * ```markdown + * > | www.example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function wwwAfter(code) { + effects.exit('literalAutolinkWww') + effects.exit('literalAutolink') + return ok(code) + } +} + +/** + * Protocol autolink literal. + * + * ```markdown + * > | a https://example.org b + * ^^^^^^^^^^^^^^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeProtocolAutolink(effects, ok, nok) { + const self = this + let buffer = '' + let seen = false + + return protocolStart + + /** + * Start of protocol autolink literal. + * + * ```markdown + * > | https://example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function protocolStart(code) { + if ( + (code === codes.uppercaseH || code === codes.lowercaseH) && + previousProtocol.call(self, self.previous) && + !previousUnbalanced(self.events) + ) { + effects.enter('literalAutolink') + effects.enter('literalAutolinkHttp') + buffer += String.fromCodePoint(code) + effects.consume(code) + return protocolPrefixInside + } + + return nok(code) + } + + /** + * In protocol. + * + * ```markdown + * > | https://example.com/a?b#c + * ^^^^^ + * ``` + * + * @type {State} + */ + function protocolPrefixInside(code) { + // `5` is size of `https` + if (asciiAlpha(code) && buffer.length < 5) { + // @ts-expect-error: definitely number. + buffer += String.fromCodePoint(code) + effects.consume(code) + return protocolPrefixInside + } + + if (code === codes.colon) { + const protocol = buffer.toLowerCase() + + if (protocol === 'http' || protocol === 'https') { + effects.consume(code) + return protocolSlashesInside + } + } + + return nok(code) + } + + /** + * In slashes. + * + * ```markdown + * > | https://example.com/a?b#c + * ^^ + * ``` + * + * @type {State} + */ + function protocolSlashesInside(code) { + if (code === codes.slash) { + effects.consume(code) + + if (seen) { + return afterProtocol + } + + seen = true + return protocolSlashesInside + } + + return nok(code) + } + + /** + * After protocol, before domain. + * + * ```markdown + * > | https://example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function afterProtocol(code) { + // To do: this is different from `markdown-rs`: + // https://github.com/wooorm/markdown-rs/blob/b3a921c761309ae00a51fe348d8a43adbc54b518/src/construct/gfm_autolink_literal.rs#L172-L182 + return code === codes.eof || + asciiControl(code) || + markdownLineEndingOrSpace(code) || + unicodeWhitespace(code) || + unicodePunctuation(code) + ? nok(code) + : effects.attempt(domain, effects.attempt(path, protocolAfter), nok)(code) + } + + /** + * After a protocol autolink literal. + * + * ```markdown + * > | https://example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function protocolAfter(code) { + effects.exit('literalAutolinkHttp') + effects.exit('literalAutolink') + return ok(code) + } +} + +/** + * `www` prefix. + * + * ```markdown + * > | a www.example.org b + * ^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeWwwPrefix(effects, ok, nok) { + let size = 0 + + return wwwPrefixInside + + /** + * In www prefix. + * + * ```markdown + * > | www.example.com + * ^^^^ + * ``` + * + * @type {State} + */ + function wwwPrefixInside(code) { + if ((code === codes.uppercaseW || code === codes.lowercaseW) && size < 3) { + size++ + effects.consume(code) + return wwwPrefixInside + } + + if (code === codes.dot && size === 3) { + effects.consume(code) + return wwwPrefixAfter + } + + return nok(code) + } + + /** + * After www prefix. + * + * ```markdown + * > | www.example.com + * ^ + * ``` + * + * @type {State} + */ + function wwwPrefixAfter(code) { + // If there is *anything*, we can link. + return code === codes.eof ? nok(code) : ok(code) + } +} + +/** + * Domain. + * + * ```markdown + * > | a https://example.org b + * ^^^^^^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeDomain(effects, ok, nok) { + /** @type {boolean | undefined} */ + let underscoreInLastSegment + /** @type {boolean | undefined} */ + let underscoreInLastLastSegment + /** @type {boolean | undefined} */ + let seen + + return domainInside + + /** + * In domain. + * + * ```markdown + * > | https://example.com/a + * ^^^^^^^^^^^ + * ``` + * + * @type {State} + */ + function domainInside(code) { + // Check whether this marker, which is a trailing punctuation + // marker, optionally followed by more trailing markers, and then + // followed by an end. + if (code === codes.dot || code === codes.underscore) { + return effects.check(trail, domainAfter, domainAtPunctuation)(code) + } + + // GH documents that only alphanumerics (other than `-`, `.`, and `_`) can + // occur, which sounds like ASCII only, but they also support `www.點看.com`, + // so that’s Unicode. + // Instead of some new production for Unicode alphanumerics, markdown + // already has that for Unicode punctuation and whitespace, so use those. + // Source: . + if ( + code === codes.eof || + markdownLineEndingOrSpace(code) || + unicodeWhitespace(code) || + (code !== codes.dash && unicodePunctuation(code)) + ) { + return domainAfter(code) + } + + seen = true + effects.consume(code) + return domainInside + } + + /** + * In domain, at potential trailing punctuation, that was not trailing. + * + * ```markdown + * > | https://example.com + * ^ + * ``` + * + * @type {State} + */ + function domainAtPunctuation(code) { + // There is an underscore in the last segment of the domain + if (code === codes.underscore) { + underscoreInLastSegment = true + } + // Otherwise, it’s a `.`: save the last segment underscore in the + // penultimate segment slot. + else { + underscoreInLastLastSegment = underscoreInLastSegment + underscoreInLastSegment = undefined + } + + effects.consume(code) + return domainInside + } + + /** + * After domain. + * + * ```markdown + * > | https://example.com/a + * ^ + * ``` + * + * @type {State} */ + function domainAfter(code) { + // Note: that’s GH says a dot is needed, but it’s not true: + // + if (underscoreInLastLastSegment || underscoreInLastSegment || !seen) { + return nok(code) + } + + return ok(code) + } +} + +/** + * Path. + * + * ```markdown + * > | a https://example.org/stuff b + * ^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizePath(effects, ok) { + let sizeOpen = 0 + let sizeClose = 0 + + return pathInside + + /** + * In path. + * + * ```markdown + * > | https://example.com/a + * ^^ + * ``` + * + * @type {State} + */ + function pathInside(code) { + if (code === codes.leftParenthesis) { + sizeOpen++ + effects.consume(code) + return pathInside + } + + // To do: `markdown-rs` also needs this. + // If this is a paren, and there are less closings than openings, + // we don’t check for a trail. + if (code === codes.rightParenthesis && sizeClose < sizeOpen) { + return pathAtPunctuation(code) + } + + // Check whether this trailing punctuation marker is optionally + // followed by more trailing markers, and then followed + // by an end. + if ( + code === codes.exclamationMark || + code === codes.quotationMark || + code === codes.ampersand || + code === codes.apostrophe || + code === codes.rightParenthesis || + code === codes.asterisk || + code === codes.comma || + code === codes.dot || + code === codes.colon || + code === codes.semicolon || + code === codes.lessThan || + code === codes.questionMark || + code === codes.rightSquareBracket || + code === codes.underscore || + code === codes.tilde + ) { + return effects.check(trail, ok, pathAtPunctuation)(code) + } + + if ( + code === codes.eof || + markdownLineEndingOrSpace(code) || + unicodeWhitespace(code) + ) { + return ok(code) + } + + effects.consume(code) + return pathInside + } + + /** + * In path, at potential trailing punctuation, that was not trailing. + * + * ```markdown + * > | https://example.com/a"b + * ^ + * ``` + * + * @type {State} + */ + function pathAtPunctuation(code) { + // Count closing parens. + if (code === codes.rightParenthesis) { + sizeClose++ + } + + effects.consume(code) + return pathInside + } +} + +/** + * Trail. + * + * This calls `ok` if this *is* the trail, followed by an end, which means + * the entire trail is not part of the link. + * It calls `nok` if this *is* part of the link. + * + * ```markdown + * > | https://example.com"). + * ^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeTrail(effects, ok, nok) { + return trail + + /** + * In trail of domain or path. + * + * ```markdown + * > | https://example.com"). + * ^ + * ``` + * + * @type {State} + */ + function trail(code) { + // Regular trailing punctuation. + if ( + code === codes.exclamationMark || + code === codes.quotationMark || + code === codes.apostrophe || + code === codes.rightParenthesis || + code === codes.asterisk || + code === codes.comma || + code === codes.dot || + code === codes.colon || + code === codes.semicolon || + code === codes.questionMark || + code === codes.underscore || + code === codes.tilde + ) { + effects.consume(code) + return trail + } + + // `&` followed by one or more alphabeticals and then a `;`, is + // as a whole considered as trailing punctuation. + // In all other cases, it is considered as continuation of the URL. + if (code === codes.ampersand) { + effects.consume(code) + return trailCharacterReferenceStart + } + + // Needed because we allow literals after `[`, as we fix: + // . + // Check that it is not followed by `(` or `[`. + if (code === codes.rightSquareBracket) { + effects.consume(code) + return trailBracketAfter + } + + if ( + // `<` is an end. + code === codes.lessThan || + // So is whitespace. + code === codes.eof || + markdownLineEndingOrSpace(code) || + unicodeWhitespace(code) + ) { + return ok(code) + } + + return nok(code) + } + + /** + * In trail, after `]`. + * + * > 👉 **Note**: this deviates from `cmark-gfm` to fix a bug. + * > See end of for more. + * + * ```markdown + * > | https://example.com]( + * ^ + * ``` + * + * @type {State} + */ + function trailBracketAfter(code) { + // Whitespace or something that could start a resource or reference is the end. + // Switch back to trail otherwise. + if ( + code === codes.eof || + code === codes.leftParenthesis || + code === codes.leftSquareBracket || + markdownLineEndingOrSpace(code) || + unicodeWhitespace(code) + ) { + return ok(code) + } + + return trail(code) + } + + /** + * In character-reference like trail, after `&`. + * + * ```markdown + * > | https://example.com&). + * ^ + * ``` + * + * @type {State} + */ + function trailCharacterReferenceStart(code) { + // When non-alpha, it’s not a trail. + return asciiAlpha(code) ? trailCharacterReferenceInside(code) : nok(code) + } + + /** + * In character-reference like trail. + * + * ```markdown + * > | https://example.com&). + * ^ + * ``` + * + * @type {State} + */ + function trailCharacterReferenceInside(code) { + // Switch back to trail if this is well-formed. + if (code === codes.semicolon) { + effects.consume(code) + return trail + } + + if (asciiAlpha(code)) { + effects.consume(code) + return trailCharacterReferenceInside + } + + // It’s not a trail. + return nok(code) + } +} + +/** + * Dot in email domain trail. + * + * This calls `ok` if this *is* the trail, followed by an end, which means + * the trail is not part of the link. + * It calls `nok` if this *is* part of the link. + * + * ```markdown + * > | contact@example.org. + * ^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeEmailDomainDotTrail(effects, ok, nok) { + return start + + /** + * Dot. + * + * ```markdown + * > | contact@example.org. + * ^ ^ + * ``` + * + * @type {State} + */ + function start(code) { + // Must be dot. + effects.consume(code) + return after + } + + /** + * After dot. + * + * ```markdown + * > | contact@example.org. + * ^ ^ + * ``` + * + * @type {State} + */ + function after(code) { + // Not a trail if alphanumeric. + return asciiAlphanumeric(code) ? nok(code) : ok(code) + } +} + +/** + * See: + * . + * + * @type {Previous} + */ +function previousWww(code) { + return ( + code === codes.eof || + code === codes.leftParenthesis || + code === codes.asterisk || + code === codes.underscore || + code === codes.leftSquareBracket || + code === codes.rightSquareBracket || + code === codes.tilde || + markdownLineEndingOrSpace(code) + ) +} + +/** + * See: + * . + * + * @type {Previous} + */ +function previousProtocol(code) { + return !asciiAlpha(code) +} + +/** + * @this {TokenizeContext} + * @type {Previous} + */ +function previousEmail(code) { + // Do not allow a slash “inside” atext. + // The reference code is a bit weird, but that’s what it results in. + // Source: . + // Other than slash, every preceding character is allowed. + return !(code === codes.slash || gfmAtext(code)) +} + +/** + * @param {Code} code + * @returns {boolean} + */ +function gfmAtext(code) { + return ( + code === codes.plusSign || + code === codes.dash || + code === codes.dot || + code === codes.underscore || + asciiAlphanumeric(code) + ) +} + +/** + * @param {Array} events + * @returns {boolean} + */ +function previousUnbalanced(events) { + let index = events.length + let result = false + + while (index--) { + const token = events[index][1] + + if ( + (token.type === 'labelLink' || token.type === 'labelImage') && + !token._balanced + ) { + result = true + break + } + + // If we’ve seen this token, and it was marked as not having any unbalanced + // bracket before it, we can exit. + if (token._gfmAutolinkLiteralWalkedInto) { + result = false + break + } + } + + if (events.length > 0 && !result) { + // Mark the last token as “walked into” w/o finding + // anything. + events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true + } + + return result +} diff --git a/node_modules/micromark-extension-gfm-autolink-literal/index.d.ts b/node_modules/micromark-extension-gfm-autolink-literal/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..36f53b55bf7d7494d1ed6a8b21564825e385142f --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/index.d.ts @@ -0,0 +1,24 @@ +export {gfmAutolinkLiteral} from './lib/syntax.js' +export {gfmAutolinkLiteralHtml} from './lib/html.js' + +/** + * Augment types. + */ +declare module 'micromark-util-types' { + /** + * Augment token with a field to improve performance. + */ + interface Token { + _gfmAutolinkLiteralWalkedInto?: boolean + } + + /** + * Token types. + */ + interface TokenTypeMap { + literalAutolink: 'literalAutolink' + literalAutolinkEmail: 'literalAutolinkEmail' + literalAutolinkHttp: 'literalAutolinkHttp' + literalAutolinkWww: 'literalAutolinkWww' + } +} diff --git a/node_modules/micromark-extension-gfm-autolink-literal/index.js b/node_modules/micromark-extension-gfm-autolink-literal/index.js new file mode 100644 index 0000000000000000000000000000000000000000..5194682ad940eb2402efb1de1b57b76fbc082c6e --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/index.js @@ -0,0 +1,2 @@ +export { gfmAutolinkLiteral } from './lib/syntax.js'; +export { gfmAutolinkLiteralHtml } from './lib/html.js'; \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-autolink-literal/lib/html.d.ts b/node_modules/micromark-extension-gfm-autolink-literal/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..250ffc8fbe401c34891c4a5aed329cad6ec49f25 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/lib/html.d.ts @@ -0,0 +1,10 @@ +/** + * Create an HTML extension for `micromark` to support GitHub autolink literal + * when serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GitHub autolink literal when serializing to HTML. + */ +export function gfmAutolinkLiteralHtml(): HtmlExtension; +import type { HtmlExtension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-autolink-literal/lib/html.js b/node_modules/micromark-extension-gfm-autolink-literal/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..e0b3c3d21fa8d7f7b6596145d6f817c4089a0614 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/lib/html.js @@ -0,0 +1,60 @@ +/** + * @import {CompileContext, Handle, HtmlExtension, Token} from 'micromark-util-types' + */ + +import { sanitizeUri } from 'micromark-util-sanitize-uri'; + +/** + * Create an HTML extension for `micromark` to support GitHub autolink literal + * when serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GitHub autolink literal when serializing to HTML. + */ +export function gfmAutolinkLiteralHtml() { + return { + exit: { + literalAutolinkEmail, + literalAutolinkHttp, + literalAutolinkWww + } + }; +} + +/** + * @this {CompileContext} + * @type {Handle} + */ +function literalAutolinkWww(token) { + anchorFromToken.call(this, token, 'http://'); +} + +/** + * @this {CompileContext} + * @type {Handle} + */ +function literalAutolinkEmail(token) { + anchorFromToken.call(this, token, 'mailto:'); +} + +/** + * @this {CompileContext} + * @type {Handle} + */ +function literalAutolinkHttp(token) { + anchorFromToken.call(this, token); +} + +/** + * @this CompileContext + * @param {Token} token + * @param {string | null | undefined} [protocol] + * @returns {undefined} + */ +function anchorFromToken(token, protocol) { + const url = this.sliceSerialize(token); + this.tag(''); + this.raw(this.encode(url)); + this.tag(''); +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-autolink-literal/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-autolink-literal/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..fc2ddfab5391b1bb2036725392923572bff608e4 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/lib/syntax.d.ts @@ -0,0 +1,10 @@ +/** + * Create an extension for `micromark` to support GitHub autolink literal + * syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * autolink literal syntax. + */ +export function gfmAutolinkLiteral(): Extension; +import type { Extension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-autolink-literal/lib/syntax.js b/node_modules/micromark-extension-gfm-autolink-literal/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..dffbaf15146b34d3b3f634286629ccb148866f4c --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/lib/syntax.js @@ -0,0 +1,854 @@ +/** + * @import {Code, ConstructRecord, Event, Extension, Previous, State, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +import { asciiAlpha, asciiAlphanumeric, asciiControl, markdownLineEndingOrSpace, unicodePunctuation, unicodeWhitespace } from 'micromark-util-character'; +const wwwPrefix = { + tokenize: tokenizeWwwPrefix, + partial: true +}; +const domain = { + tokenize: tokenizeDomain, + partial: true +}; +const path = { + tokenize: tokenizePath, + partial: true +}; +const trail = { + tokenize: tokenizeTrail, + partial: true +}; +const emailDomainDotTrail = { + tokenize: tokenizeEmailDomainDotTrail, + partial: true +}; +const wwwAutolink = { + name: 'wwwAutolink', + tokenize: tokenizeWwwAutolink, + previous: previousWww +}; +const protocolAutolink = { + name: 'protocolAutolink', + tokenize: tokenizeProtocolAutolink, + previous: previousProtocol +}; +const emailAutolink = { + name: 'emailAutolink', + tokenize: tokenizeEmailAutolink, + previous: previousEmail +}; + +/** @type {ConstructRecord} */ +const text = {}; + +/** + * Create an extension for `micromark` to support GitHub autolink literal + * syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * autolink literal syntax. + */ +export function gfmAutolinkLiteral() { + return { + text + }; +} + +/** @type {Code} */ +let code = 48; + +// Add alphanumerics. +while (code < 123) { + text[code] = emailAutolink; + code++; + if (code === 58) code = 65;else if (code === 91) code = 97; +} +text[43] = emailAutolink; +text[45] = emailAutolink; +text[46] = emailAutolink; +text[95] = emailAutolink; +text[72] = [emailAutolink, protocolAutolink]; +text[104] = [emailAutolink, protocolAutolink]; +text[87] = [emailAutolink, wwwAutolink]; +text[119] = [emailAutolink, wwwAutolink]; + +// To do: perform email autolink literals on events, afterwards. +// That’s where `markdown-rs` and `cmark-gfm` perform it. +// It should look for `@`, then for atext backwards, and then for a label +// forwards. +// To do: `mailto:`, `xmpp:` protocol as prefix. + +/** + * Email autolink literal. + * + * ```markdown + * > | a contact@example.org b + * ^^^^^^^^^^^^^^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeEmailAutolink(effects, ok, nok) { + const self = this; + /** @type {boolean | undefined} */ + let dot; + /** @type {boolean} */ + let data; + return start; + + /** + * Start of email autolink literal. + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + if (!gfmAtext(code) || !previousEmail.call(self, self.previous) || previousUnbalanced(self.events)) { + return nok(code); + } + effects.enter('literalAutolink'); + effects.enter('literalAutolinkEmail'); + return atext(code); + } + + /** + * In email atext. + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function atext(code) { + if (gfmAtext(code)) { + effects.consume(code); + return atext; + } + if (code === 64) { + effects.consume(code); + return emailDomain; + } + return nok(code); + } + + /** + * In email domain. + * + * The reference code is a bit overly complex as it handles the `@`, of which + * there may be just one. + * Source: + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function emailDomain(code) { + // Dot followed by alphanumerical (not `-` or `_`). + if (code === 46) { + return effects.check(emailDomainDotTrail, emailDomainAfter, emailDomainDot)(code); + } + + // Alphanumerical, `-`, and `_`. + if (code === 45 || code === 95 || asciiAlphanumeric(code)) { + data = true; + effects.consume(code); + return emailDomain; + } + + // To do: `/` if xmpp. + + // Note: normally we’d truncate trailing punctuation from the link. + // However, email autolink literals cannot contain any of those markers, + // except for `.`, but that can only occur if it isn’t trailing. + // So we can ignore truncating! + return emailDomainAfter(code); + } + + /** + * In email domain, on dot that is not a trail. + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function emailDomainDot(code) { + effects.consume(code); + dot = true; + return emailDomain; + } + + /** + * After email domain. + * + * ```markdown + * > | a contact@example.org b + * ^ + * ``` + * + * @type {State} + */ + function emailDomainAfter(code) { + // Domain must not be empty, must include a dot, and must end in alphabetical. + // Source: . + if (data && dot && asciiAlpha(self.previous)) { + effects.exit('literalAutolinkEmail'); + effects.exit('literalAutolink'); + return ok(code); + } + return nok(code); + } +} + +/** + * `www` autolink literal. + * + * ```markdown + * > | a www.example.org b + * ^^^^^^^^^^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeWwwAutolink(effects, ok, nok) { + const self = this; + return wwwStart; + + /** + * Start of www autolink literal. + * + * ```markdown + * > | www.example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function wwwStart(code) { + if (code !== 87 && code !== 119 || !previousWww.call(self, self.previous) || previousUnbalanced(self.events)) { + return nok(code); + } + effects.enter('literalAutolink'); + effects.enter('literalAutolinkWww'); + // Note: we *check*, so we can discard the `www.` we parsed. + // If it worked, we consider it as a part of the domain. + return effects.check(wwwPrefix, effects.attempt(domain, effects.attempt(path, wwwAfter), nok), nok)(code); + } + + /** + * After a www autolink literal. + * + * ```markdown + * > | www.example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function wwwAfter(code) { + effects.exit('literalAutolinkWww'); + effects.exit('literalAutolink'); + return ok(code); + } +} + +/** + * Protocol autolink literal. + * + * ```markdown + * > | a https://example.org b + * ^^^^^^^^^^^^^^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeProtocolAutolink(effects, ok, nok) { + const self = this; + let buffer = ''; + let seen = false; + return protocolStart; + + /** + * Start of protocol autolink literal. + * + * ```markdown + * > | https://example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function protocolStart(code) { + if ((code === 72 || code === 104) && previousProtocol.call(self, self.previous) && !previousUnbalanced(self.events)) { + effects.enter('literalAutolink'); + effects.enter('literalAutolinkHttp'); + buffer += String.fromCodePoint(code); + effects.consume(code); + return protocolPrefixInside; + } + return nok(code); + } + + /** + * In protocol. + * + * ```markdown + * > | https://example.com/a?b#c + * ^^^^^ + * ``` + * + * @type {State} + */ + function protocolPrefixInside(code) { + // `5` is size of `https` + if (asciiAlpha(code) && buffer.length < 5) { + // @ts-expect-error: definitely number. + buffer += String.fromCodePoint(code); + effects.consume(code); + return protocolPrefixInside; + } + if (code === 58) { + const protocol = buffer.toLowerCase(); + if (protocol === 'http' || protocol === 'https') { + effects.consume(code); + return protocolSlashesInside; + } + } + return nok(code); + } + + /** + * In slashes. + * + * ```markdown + * > | https://example.com/a?b#c + * ^^ + * ``` + * + * @type {State} + */ + function protocolSlashesInside(code) { + if (code === 47) { + effects.consume(code); + if (seen) { + return afterProtocol; + } + seen = true; + return protocolSlashesInside; + } + return nok(code); + } + + /** + * After protocol, before domain. + * + * ```markdown + * > | https://example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function afterProtocol(code) { + // To do: this is different from `markdown-rs`: + // https://github.com/wooorm/markdown-rs/blob/b3a921c761309ae00a51fe348d8a43adbc54b518/src/construct/gfm_autolink_literal.rs#L172-L182 + return code === null || asciiControl(code) || markdownLineEndingOrSpace(code) || unicodeWhitespace(code) || unicodePunctuation(code) ? nok(code) : effects.attempt(domain, effects.attempt(path, protocolAfter), nok)(code); + } + + /** + * After a protocol autolink literal. + * + * ```markdown + * > | https://example.com/a?b#c + * ^ + * ``` + * + * @type {State} + */ + function protocolAfter(code) { + effects.exit('literalAutolinkHttp'); + effects.exit('literalAutolink'); + return ok(code); + } +} + +/** + * `www` prefix. + * + * ```markdown + * > | a www.example.org b + * ^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeWwwPrefix(effects, ok, nok) { + let size = 0; + return wwwPrefixInside; + + /** + * In www prefix. + * + * ```markdown + * > | www.example.com + * ^^^^ + * ``` + * + * @type {State} + */ + function wwwPrefixInside(code) { + if ((code === 87 || code === 119) && size < 3) { + size++; + effects.consume(code); + return wwwPrefixInside; + } + if (code === 46 && size === 3) { + effects.consume(code); + return wwwPrefixAfter; + } + return nok(code); + } + + /** + * After www prefix. + * + * ```markdown + * > | www.example.com + * ^ + * ``` + * + * @type {State} + */ + function wwwPrefixAfter(code) { + // If there is *anything*, we can link. + return code === null ? nok(code) : ok(code); + } +} + +/** + * Domain. + * + * ```markdown + * > | a https://example.org b + * ^^^^^^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeDomain(effects, ok, nok) { + /** @type {boolean | undefined} */ + let underscoreInLastSegment; + /** @type {boolean | undefined} */ + let underscoreInLastLastSegment; + /** @type {boolean | undefined} */ + let seen; + return domainInside; + + /** + * In domain. + * + * ```markdown + * > | https://example.com/a + * ^^^^^^^^^^^ + * ``` + * + * @type {State} + */ + function domainInside(code) { + // Check whether this marker, which is a trailing punctuation + // marker, optionally followed by more trailing markers, and then + // followed by an end. + if (code === 46 || code === 95) { + return effects.check(trail, domainAfter, domainAtPunctuation)(code); + } + + // GH documents that only alphanumerics (other than `-`, `.`, and `_`) can + // occur, which sounds like ASCII only, but they also support `www.點看.com`, + // so that’s Unicode. + // Instead of some new production for Unicode alphanumerics, markdown + // already has that for Unicode punctuation and whitespace, so use those. + // Source: . + if (code === null || markdownLineEndingOrSpace(code) || unicodeWhitespace(code) || code !== 45 && unicodePunctuation(code)) { + return domainAfter(code); + } + seen = true; + effects.consume(code); + return domainInside; + } + + /** + * In domain, at potential trailing punctuation, that was not trailing. + * + * ```markdown + * > | https://example.com + * ^ + * ``` + * + * @type {State} + */ + function domainAtPunctuation(code) { + // There is an underscore in the last segment of the domain + if (code === 95) { + underscoreInLastSegment = true; + } + // Otherwise, it’s a `.`: save the last segment underscore in the + // penultimate segment slot. + else { + underscoreInLastLastSegment = underscoreInLastSegment; + underscoreInLastSegment = undefined; + } + effects.consume(code); + return domainInside; + } + + /** + * After domain. + * + * ```markdown + * > | https://example.com/a + * ^ + * ``` + * + * @type {State} */ + function domainAfter(code) { + // Note: that’s GH says a dot is needed, but it’s not true: + // + if (underscoreInLastLastSegment || underscoreInLastSegment || !seen) { + return nok(code); + } + return ok(code); + } +} + +/** + * Path. + * + * ```markdown + * > | a https://example.org/stuff b + * ^^^^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizePath(effects, ok) { + let sizeOpen = 0; + let sizeClose = 0; + return pathInside; + + /** + * In path. + * + * ```markdown + * > | https://example.com/a + * ^^ + * ``` + * + * @type {State} + */ + function pathInside(code) { + if (code === 40) { + sizeOpen++; + effects.consume(code); + return pathInside; + } + + // To do: `markdown-rs` also needs this. + // If this is a paren, and there are less closings than openings, + // we don’t check for a trail. + if (code === 41 && sizeClose < sizeOpen) { + return pathAtPunctuation(code); + } + + // Check whether this trailing punctuation marker is optionally + // followed by more trailing markers, and then followed + // by an end. + if (code === 33 || code === 34 || code === 38 || code === 39 || code === 41 || code === 42 || code === 44 || code === 46 || code === 58 || code === 59 || code === 60 || code === 63 || code === 93 || code === 95 || code === 126) { + return effects.check(trail, ok, pathAtPunctuation)(code); + } + if (code === null || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) { + return ok(code); + } + effects.consume(code); + return pathInside; + } + + /** + * In path, at potential trailing punctuation, that was not trailing. + * + * ```markdown + * > | https://example.com/a"b + * ^ + * ``` + * + * @type {State} + */ + function pathAtPunctuation(code) { + // Count closing parens. + if (code === 41) { + sizeClose++; + } + effects.consume(code); + return pathInside; + } +} + +/** + * Trail. + * + * This calls `ok` if this *is* the trail, followed by an end, which means + * the entire trail is not part of the link. + * It calls `nok` if this *is* part of the link. + * + * ```markdown + * > | https://example.com"). + * ^^^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeTrail(effects, ok, nok) { + return trail; + + /** + * In trail of domain or path. + * + * ```markdown + * > | https://example.com"). + * ^ + * ``` + * + * @type {State} + */ + function trail(code) { + // Regular trailing punctuation. + if (code === 33 || code === 34 || code === 39 || code === 41 || code === 42 || code === 44 || code === 46 || code === 58 || code === 59 || code === 63 || code === 95 || code === 126) { + effects.consume(code); + return trail; + } + + // `&` followed by one or more alphabeticals and then a `;`, is + // as a whole considered as trailing punctuation. + // In all other cases, it is considered as continuation of the URL. + if (code === 38) { + effects.consume(code); + return trailCharacterReferenceStart; + } + + // Needed because we allow literals after `[`, as we fix: + // . + // Check that it is not followed by `(` or `[`. + if (code === 93) { + effects.consume(code); + return trailBracketAfter; + } + if ( + // `<` is an end. + code === 60 || + // So is whitespace. + code === null || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) { + return ok(code); + } + return nok(code); + } + + /** + * In trail, after `]`. + * + * > 👉 **Note**: this deviates from `cmark-gfm` to fix a bug. + * > See end of for more. + * + * ```markdown + * > | https://example.com]( + * ^ + * ``` + * + * @type {State} + */ + function trailBracketAfter(code) { + // Whitespace or something that could start a resource or reference is the end. + // Switch back to trail otherwise. + if (code === null || code === 40 || code === 91 || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) { + return ok(code); + } + return trail(code); + } + + /** + * In character-reference like trail, after `&`. + * + * ```markdown + * > | https://example.com&). + * ^ + * ``` + * + * @type {State} + */ + function trailCharacterReferenceStart(code) { + // When non-alpha, it’s not a trail. + return asciiAlpha(code) ? trailCharacterReferenceInside(code) : nok(code); + } + + /** + * In character-reference like trail. + * + * ```markdown + * > | https://example.com&). + * ^ + * ``` + * + * @type {State} + */ + function trailCharacterReferenceInside(code) { + // Switch back to trail if this is well-formed. + if (code === 59) { + effects.consume(code); + return trail; + } + if (asciiAlpha(code)) { + effects.consume(code); + return trailCharacterReferenceInside; + } + + // It’s not a trail. + return nok(code); + } +} + +/** + * Dot in email domain trail. + * + * This calls `ok` if this *is* the trail, followed by an end, which means + * the trail is not part of the link. + * It calls `nok` if this *is* part of the link. + * + * ```markdown + * > | contact@example.org. + * ^ + * ``` + * + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeEmailDomainDotTrail(effects, ok, nok) { + return start; + + /** + * Dot. + * + * ```markdown + * > | contact@example.org. + * ^ ^ + * ``` + * + * @type {State} + */ + function start(code) { + // Must be dot. + effects.consume(code); + return after; + } + + /** + * After dot. + * + * ```markdown + * > | contact@example.org. + * ^ ^ + * ``` + * + * @type {State} + */ + function after(code) { + // Not a trail if alphanumeric. + return asciiAlphanumeric(code) ? nok(code) : ok(code); + } +} + +/** + * See: + * . + * + * @type {Previous} + */ +function previousWww(code) { + return code === null || code === 40 || code === 42 || code === 95 || code === 91 || code === 93 || code === 126 || markdownLineEndingOrSpace(code); +} + +/** + * See: + * . + * + * @type {Previous} + */ +function previousProtocol(code) { + return !asciiAlpha(code); +} + +/** + * @this {TokenizeContext} + * @type {Previous} + */ +function previousEmail(code) { + // Do not allow a slash “inside” atext. + // The reference code is a bit weird, but that’s what it results in. + // Source: . + // Other than slash, every preceding character is allowed. + return !(code === 47 || gfmAtext(code)); +} + +/** + * @param {Code} code + * @returns {boolean} + */ +function gfmAtext(code) { + return code === 43 || code === 45 || code === 46 || code === 95 || asciiAlphanumeric(code); +} + +/** + * @param {Array} events + * @returns {boolean} + */ +function previousUnbalanced(events) { + let index = events.length; + let result = false; + while (index--) { + const token = events[index][1]; + if ((token.type === 'labelLink' || token.type === 'labelImage') && !token._balanced) { + result = true; + break; + } + + // If we’ve seen this token, and it was marked as not having any unbalanced + // bracket before it, we can exit. + if (token._gfmAutolinkLiteralWalkedInto) { + result = false; + break; + } + } + if (events.length > 0 && !result) { + // Mark the last token as “walked into” w/o finding + // anything. + events[events.length - 1][1]._gfmAutolinkLiteralWalkedInto = true; + } + return result; +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-autolink-literal/license b/node_modules/micromark-extension-gfm-autolink-literal/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark-extension-gfm-autolink-literal/package.json b/node_modules/micromark-extension-gfm-autolink-literal/package.json new file mode 100644 index 0000000000000000000000000000000000000000..2b1b6bd476485d6470ad8f2955c1a9bf3ad511ba --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/package.json @@ -0,0 +1,116 @@ +{ + "name": "micromark-extension-gfm-autolink-literal", + "version": "2.1.0", + "description": "micromark extension to support GFM autolink literals", + "license": "MIT", + "keywords": [ + "micromark", + "micromark-extension", + "literal", + "url", + "autolink", + "auto", + "link", + "gfm", + "markdown", + "unified" + ], + "repository": "micromark/micromark-extension-gfm-autolink-literal", + "bugs": "https://github.com/micromark/micromark-extension-gfm-autolink-literal/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "files": [ + "dev/", + "lib/", + "index.d.ts", + "index.js" + ], + "exports": { + "development": "./dev/index.js", + "default": "./index.js" + }, + "dependencies": { + "micromark-util-character": "^2.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^10.0.0", + "create-gfm-fixtures": "^1.0.0", + "micromark": "^4.0.0", + "micromark-build": "^2.0.0", + "prettier": "^3.0.0", + "rehype": "^13.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.58.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage && micromark-build", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api-prod": "node --conditions production test/index.js", + "test-api-dev": "node --conditions development test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "prettier": true, + "rules": { + "complexity": "off", + "unicorn/no-this-assignment": "off", + "unicorn/prefer-at": "off", + "unicorn/prefer-string-replace-all": "off" + }, + "overrides": [ + { + "files": [ + "**/*.ts" + ], + "rules": { + "@typescript-eslint/consistent-type-definitions": 0 + } + }, + { + "files": [ + "test/**/*.js" + ], + "rules": { + "no-await-in-loop": 0 + } + } + ] + } +} diff --git a/node_modules/micromark-extension-gfm-autolink-literal/readme.md b/node_modules/micromark-extension-gfm-autolink-literal/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..61651de01a7ae52b97ac8e9977ad3d6fcf651535 --- /dev/null +++ b/node_modules/micromark-extension-gfm-autolink-literal/readme.md @@ -0,0 +1,422 @@ +# micromark-extension-gfm-autolink-literal + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[micromark][] extensions to support GFM [literal autolinks][spec]. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmAutolinkLiteral()`](#gfmautolinkliteral) + * [`gfmAutolinkLiteralHtml()`](#gfmautolinkliteralhtml) +* [Bugs](#bugs) +* [Authoring](#authoring) +* [HTML](#html) +* [CSS](#css) +* [Syntax](#syntax) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains extensions that add support for the extra autolink syntax +enabled by GFM to [`micromark`][micromark]. + +GitHub employs different algorithms to autolink: one at parse time and one at +transform time (similar to how @mentions are done at transform time). +This difference can be observed because character references and escapes are +handled differently. +But also because issues/PRs/comments omit (perhaps by accident?) the second +algorithm for `www.`, `http://`, and `https://` links (but not for email links). + +As this is a syntax extension, it focuses on the first algorithm. +The second algorithm is performed by +[`mdast-util-gfm-autolink-literal`][mdast-util-gfm-autolink-literal]. +The `html` part of this micromark extension does not operate on an AST and hence +can’t perform the second algorithm. + +The implementation of autolink literal on github.com is currently buggy. +The bugs have been reported on [`cmark-gfm`][cmark-gfm]. +This micromark extension matches github.com except for its bugs. + +## When to use this + +This project is useful when you want to support autolink literals in markdown. + +You can use these extensions when you are working with [`micromark`][micromark]. +To support all GFM features, use +[`micromark-extension-gfm`][micromark-extension-gfm] instead. + +When you need a syntax tree, combine this package with +[`mdast-util-gfm-autolink-literal`][mdast-util-gfm-autolink-literal]. + +All these packages are used in [`remark-gfm`][remark-gfm], which focusses on +making it easier to transform content by abstracting these internals away. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install micromark-extension-gfm-autolink-literal +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmAutolinkLiteral, gfmAutolinkLiteralHtml} from 'https://esm.sh/micromark-extension-gfm-autolink-literal@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +```js +import {micromark} from 'micromark' +import { + gfmAutolinkLiteral, + gfmAutolinkLiteralHtml +} from 'micromark-extension-gfm-autolink-literal' + +const output = micromark('Just a URL: www.example.com.', { + extensions: [gfmAutolinkLiteral()], + htmlExtensions: [gfmAutolinkLiteralHtml()] +}) + +console.log(output) +``` + +Yields: + +```html +

Just a URL: www.example.com.

+``` + +## API + +This package exports the identifiers +[`gfmAutolinkLiteral`][api-gfm-autolink-literal] and +[`gfmAutolinkLiteralHtml`][api-gfm-autolink-literal-html]. +There is no default export. + +The export map supports the [`development` condition][development]. +Run `node --conditions development module.js` to get instrumented dev code. +Without this condition, production code is loaded. + +### `gfmAutolinkLiteral()` + +Create an extension for `micromark` to support GitHub autolink literal +syntax. + +###### Parameters + +Extension for `micromark` that can be passed in `extensions` to enable GFM +autolink literal syntax ([`Extension`][micromark-extension]). + +### `gfmAutolinkLiteralHtml()` + +Create an HTML extension for `micromark` to support GitHub autolink literal +when serializing to HTML. + +###### Parameters + +Extension for `micromark` that can be passed in `htmlExtensions` to support +GitHub autolink literal when serializing to HTML +([`HtmlExtension`][micromark-html-extension]). + +## Bugs + +GitHub’s own algorithm to parse autolink literals contains three bugs. +A smaller bug is left unfixed in this project for consistency. +Two main bugs are not present in this project. +The issues relating to autolink literals are: + +* [GFM autolink extension (`www.`, `https?://` parts): links don’t work when + after bracket](https://github.com/github/cmark-gfm/issues/278)\ + fixed here ✅ +* [GFM autolink extension (`www.` part): uppercase does not match on + issues/PRs/comments](https://github.com/github/cmark-gfm/issues/280)\ + fixed here ✅ +* [GFM autolink extension (`www.` part): the word `www` + matches](https://github.com/github/cmark-gfm/issues/279)\ + present here for consistency + +## Authoring + +It is recommended to use labels, either with a resource or a definition, +instead of autolink literals, as those allow relative URLs and descriptive +text to explain the URL in prose. + +## HTML + +GFM autolink literals relate to the `` element in HTML. +See [*§ 4.5.1 The `a` element*][html-a] in the HTML spec for more info. +When an email autolink is used, the string `mailto:` is prepended when +generating the `href` attribute of the hyperlink. +When a www autolink is used, the string `http://` is prepended. + +## CSS + +As hyperlinks are the fundamental thing that makes the web, you will most +definitely have CSS for `a` elements already. +The same CSS can be used for autolink literals, too. + +GitHub itself does not apply interesting CSS to autolink literals. +For any link, it currently (June 2022) [uses][css]: + +```css +a { + background-color: transparent; + color: #58a6ff; + text-decoration: none; +} + +a:active, +a:hover { + outline-width: 0; +} + +a:hover { + text-decoration: underline; +} + +a:not([href]) { + color: inherit; + text-decoration: none; +} +``` + +## Syntax + +Autolink literals form with, roughly, the following BNF: + +```bnf +gfm_autolink_literal ::= gfm_protocol_autolink | gfm_www_autolink | gfm_email_autolink + +; Restriction: the code before must be `www_autolink_before`. +; Restriction: the code after `.` must not be eof. +www_autolink ::= 3('w' | 'W') '.' [domain [path]] +www_autolink_before ::= eof | eol | space_or_tab | '(' | '*' | '_' | '[' | ']' | '~' + +; Restriction: the code before must be `http_autolink_before`. +; Restriction: the code after the protocol must be `http_autolink_protocol_after`. +http_autolink ::= ('h' | 'H') 2('t' | 'T') ('p' | 'P') ['s' | 'S'] ':' 2'/' domain [path] +http_autolink_before ::= byte - ascii_alpha +http_autolink_protocol_after ::= byte - eof - eol - ascii_control - unicode_whitespace - ode_punctuation + +; Restriction: the code before must be `email_autolink_before`. +; Restriction: `ascii_digit` may not occur in the last label part of the label. +email_autolink ::= 1*('+' | '-' | '.' | '_' | ascii_alphanumeric) '@' 1*(1*label_segment l_dot_cont) 1*label_segment +email_autolink_before ::= byte - ascii_alpha - '/' + +; Restriction: `_` may not occur in the last two domain parts. +domain ::= 1*(url_ampt_cont | domain_punct_cont | '-' | byte - eof - ascii_control - ode_whitespace - unicode_punctuation) +; Restriction: must not be followed by `punct`. +domain_punct_cont ::= '.' | '_' +; Restriction: must not be followed by `char-ref`. +url_ampt_cont ::= '&' + +; Restriction: a counter `balance = 0` is increased for every `(`, and decreased for every `)`. +; Restriction: `)` must not be `paren_at_end`. +path ::= 1*(url_ampt_cont | path_punctuation_cont | '(' | ')' | byte - eof - eol - space_or_tab) +; Restriction: must not be followed by `punct`. +path_punctuation_cont ::= trailing_punctuation - '<' +; Restriction: must be followed by `punct` and `balance` must be less than `0`. +paren_at_end ::= ')' + +label_segment ::= label_dash_underscore_cont | ascii_alpha | ascii_digit +; Restriction: if followed by `punct`, the whole email autolink is invalid. +label_dash_underscore_cont ::= '-' | '_' +; Restriction: must not be followed by `punct`. +label_dot_cont ::= '.' + +punct ::= *trailing_punctuation ( byte - eof - eol - space_or_tab - '<' ) +char_ref ::= *ascii_alpha ';' path_end +trailing_punctuation ::= '!' | '"' | '\'' | ')' | '*' | ',' | '.' | ':' | ';' | '<' | '?' | '_' | '~' +``` + +The grammar for GFM autolink literal is very relaxed: basically anything +except for whitespace is allowed after a prefix. +To use whitespace characters and otherwise impossible characters, in URLs, +you can use percent encoding: + +```markdown +https://example.com/alpha%20bravo +``` + +Yields: + +```html +

https://example.com/alpha%20bravo

+``` + +There are several cases where incorrect encoding of URLs would, in other +languages, result in a parse error. +In markdown, there are no errors, and URLs are normalized. +In addition, many characters are percent encoded +([`sanitizeUri`][micromark-util-sanitize-uri]). +For example: + +```markdown +www.a👍b% +``` + +Yields: + +```html +

www.a👍b%

+``` + +There is a big difference between how www and protocol literals work +compared to how email literals work. +The first two are done when parsing, and work like anything else in +markdown. +But email literals are handled afterwards: when everything is parsed, we +look back at the events to figure out if there were email addresses. +This particularly affects how they interleave with character escapes and +character references. + +## Types + +This package is fully typed with [TypeScript][]. +It exports no additional types. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`micromark-extension-gfm-autolink-literal@^2`, compatible with Node.js 16. + +This package works with `micromark` version `3` and later. + +## Security + +This package is safe. +Unlike other links in CommonMark, which allow arbitrary protocols, this +construct always produces safe links. + +## Related + +* [`micromark-extension-gfm`][micromark-extension-gfm] + — support all of GFM +* [`mdast-util-gfm-autolink-literal`][mdast-util-gfm-autolink-literal] + — support all of GFM in mdast +* [`mdast-util-gfm`][mdast-util-gfm] + — support all of GFM in mdast +* [`remark-gfm`][remark-gfm] + — support all of GFM in remark + +## Contribute + +See [`contributing.md` in `micromark/.github`][contributing] for ways to get +started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/micromark/micromark-extension-gfm-autolink-literal/workflows/main/badge.svg + +[build]: https://github.com/micromark/micromark-extension-gfm-autolink-literal/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm-autolink-literal.svg + +[coverage]: https://codecov.io/github/micromark/micromark-extension-gfm-autolink-literal + +[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm-autolink-literal.svg + +[downloads]: https://www.npmjs.com/package/micromark-extension-gfm-autolink-literal + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-gfm-autolink-literal + +[size]: https://bundlejs.com/?q=micromark-extension-gfm-autolink-literal + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/micromark/micromark/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esmsh]: https://esm.sh + +[license]: license + +[author]: https://wooorm.com + +[contributing]: https://github.com/micromark/.github/blob/main/contributing.md + +[support]: https://github.com/micromark/.github/blob/main/support.md + +[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[typescript]: https://www.typescriptlang.org + +[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions + +[micromark]: https://github.com/micromark/micromark + +[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm + +[micromark-util-sanitize-uri]: https://github.com/micromark/micromark/tree/main/packages/micromark-util-sanitize-uri + +[micromark-extension]: https://github.com/micromark/micromark#syntaxextension + +[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[mdast-util-gfm-autolink-literal]: https://github.com/syntax-tree/mdast-util-gfm-autolink-literal + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[spec]: https://github.github.com/gfm/#autolinks-extension- + +[html-a]: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element + +[css]: https://github.com/sindresorhus/github-markdown-css + +[cmark-gfm]: https://github.com/github/cmark-gfm + +[api-gfm-autolink-literal]: #gfmautolinkliteral + +[api-gfm-autolink-literal-html]: #gfmautolinkliteralhtml diff --git a/node_modules/micromark-extension-gfm-footnote/dev/index.d.ts b/node_modules/micromark-extension-gfm-footnote/dev/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1be286871d3a5984a0f8fd12c9a1aef63e1d0af2 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/dev/index.d.ts @@ -0,0 +1,164 @@ +export {gfmFootnoteHtml, defaultBackLabel} from './lib/html.js' +export {gfmFootnote} from './lib/syntax.js' + +/** + * Generate a back label dynamically. + * + * For the following markdown: + * + * ```markdown + * Alpha[^micromark], bravo[^micromark], and charlie[^remark]. + * + * [^remark]: things about remark + * [^micromark]: things about micromark + * ``` + * + * This function will be called with: + * + * * `0` and `0` for the backreference from `things about micromark` to + * `alpha`, as it is the first used definition, and the first call to it + * * `0` and `1` for the backreference from `things about micromark` to + * `bravo`, as it is the first used definition, and the second call to it + * * `1` and `0` for the backreference from `things about remark` to + * `charlie`, as it is the second used definition + * + * @param referenceIndex + * Index of the definition in the order that they are first referenced, + * 0-indexed. + * @param rereferenceIndex + * Index of calls to the same definition, 0-indexed. + * @returns + * Back label to use when linking back from definitions to their reference. + */ +export type BackLabelTemplate = ( + referenceIndex: number, + rereferenceIndex: number +) => string + +/** + * Configuration. + */ +export interface HtmlOptions { + /** + * Prefix to use before the `id` attribute on footnotes to prevent them from + * *clobbering* (default: `'user-content-'`). + * + * Pass `''` for trusted markdown and when you are careful with + * polyfilling. + * You could pass a different prefix. + * + * DOM clobbering is this: + * + * ```html + *

+ * + * ``` + * + * The above example shows that elements are made available by browsers, by + * their ID, on the `window` object. + * This is a security risk because you might be expecting some other variable + * at that place. + * It can also break polyfills. + * Using a prefix solves these problems. + */ + clobberPrefix?: string | null | undefined + /** + * Textual label to use for the footnotes section (default: `'Footnotes'`). + * + * Change it when the markdown is not in English. + * + * This label is typically hidden visually (assuming a `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass different attributes with the `labelAttributes` option. + */ + label?: string | null | undefined + /** + * Attributes to use on the footnote label (default: `'class="sr-only"'`). + * + * Change it to show the label and add other attributes. + * + * This label is typically hidden visually (assuming an `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass an empty string. + * You can also add different attributes. + * + * > 👉 **Note**: `id="footnote-label"` is always added, because footnote + * > calls use it with `aria-describedby` to provide an accessible label. + */ + labelAttributes?: string | null | undefined + /** + * HTML tag name to use for the footnote label element (default: `'h2'`). + * + * Change it to match your document structure. + * + * This label is typically hidden visually (assuming a `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass different attributes with the `labelAttributes` option. + */ + labelTagName?: string | null | undefined + /** + * Textual label to describe the backreference back to references (default: + * `defaultBackLabel`). + * + * The default value is: + * + * ```js + * function defaultBackLabel(referenceIndex, rereferenceIndex) { + * return ( + * 'Back to reference ' + + * (referenceIndex + 1) + + * (rereferenceIndex > 1 ? '-' + rereferenceIndex : '') + * ) + * } + * ``` + * + * Change it when the markdown is not in English. + * + * This label is used in the `aria-label` attribute on each backreference + * (the `↩` links). + * It affects users of assistive technology. + */ + backLabel?: BackLabelTemplate | string | null | undefined +} + +/** + * Augment types. + */ +declare module 'micromark-util-types' { + /** + * Compile data. + */ + interface CompileData { + gfmFootnoteDefinitions?: Record + gfmFootnoteDefinitionStack?: Array + gfmFootnoteCallCounts?: Record + gfmFootnoteCallOrder?: Array + } + + /** + * Parse context. + */ + interface ParseContext { + gfmFootnotes?: Array + } + + /** + * Token types. + */ + interface TokenTypeMap { + gfmFootnoteCall: 'gfmFootnoteCall' + gfmFootnoteCallLabelMarker: 'gfmFootnoteCallLabelMarker' + gfmFootnoteCallMarker: 'gfmFootnoteCallMarker' + gfmFootnoteCallString: 'gfmFootnoteCallString' + gfmFootnoteDefinition: 'gfmFootnoteDefinition' + gfmFootnoteDefinitionIndent: 'gfmFootnoteDefinitionIndent' + gfmFootnoteDefinitionLabel: 'gfmFootnoteDefinitionLabel' + gfmFootnoteDefinitionLabelMarker: 'gfmFootnoteDefinitionLabelMarker' + gfmFootnoteDefinitionLabelString: 'gfmFootnoteDefinitionLabelString' + gfmFootnoteDefinitionMarker: 'gfmFootnoteDefinitionMarker' + gfmFootnoteDefinitionWhitespace: 'gfmFootnoteDefinitionWhitespace' + } +} diff --git a/node_modules/micromark-extension-gfm-footnote/dev/index.js b/node_modules/micromark-extension-gfm-footnote/dev/index.js new file mode 100644 index 0000000000000000000000000000000000000000..a399a81f450889e81de56b02e02c7b3b8d54e5cf --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/dev/index.js @@ -0,0 +1,3 @@ +// Note: types are exported from `dev/index.d.ts`. +export {gfmFootnote} from './lib/syntax.js' +export {gfmFootnoteHtml, defaultBackLabel} from './lib/html.js' diff --git a/node_modules/micromark-extension-gfm-footnote/dev/lib/html.d.ts b/node_modules/micromark-extension-gfm-footnote/dev/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..dbcd2a6c8435163363ee5ee95a301fd91258147d --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/dev/lib/html.d.ts @@ -0,0 +1,25 @@ +/** + * Generate the default label that GitHub uses on backreferences. + * + * @param {number} referenceIndex + * Index of the definition in the order that they are first referenced, + * 0-indexed. + * @param {number} rereferenceIndex + * Index of calls to the same definition, 0-indexed. + * @returns {string} + * Default label. + */ +export function defaultBackLabel(referenceIndex: number, rereferenceIndex: number): string; +/** + * Create an extension for `micromark` to support GFM footnotes when + * serializing to HTML. + * + * @param {Options | null | undefined} [options={}] + * Configuration (optional). + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM footnotes when serializing to HTML. + */ +export function gfmFootnoteHtml(options?: Options | null | undefined): HtmlExtension; +import type { HtmlOptions as Options } from 'micromark-extension-gfm-footnote'; +import type { HtmlExtension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-footnote/dev/lib/html.js b/node_modules/micromark-extension-gfm-footnote/dev/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..d02ffed73da977fc66e30e8b47773ab0a47a6216 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/dev/lib/html.js @@ -0,0 +1,226 @@ +/** + * @import {HtmlOptions as Options} from 'micromark-extension-gfm-footnote' + * @import {HtmlExtension} from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {normalizeIdentifier} from 'micromark-util-normalize-identifier' +import {sanitizeUri} from 'micromark-util-sanitize-uri' + +const own = {}.hasOwnProperty + +/** @type {Options} */ +const emptyOptions = {} + +/** + * Generate the default label that GitHub uses on backreferences. + * + * @param {number} referenceIndex + * Index of the definition in the order that they are first referenced, + * 0-indexed. + * @param {number} rereferenceIndex + * Index of calls to the same definition, 0-indexed. + * @returns {string} + * Default label. + */ +export function defaultBackLabel(referenceIndex, rereferenceIndex) { + return ( + 'Back to reference ' + + (referenceIndex + 1) + + (rereferenceIndex > 1 ? '-' + rereferenceIndex : '') + ) +} + +/** + * Create an extension for `micromark` to support GFM footnotes when + * serializing to HTML. + * + * @param {Options | null | undefined} [options={}] + * Configuration (optional). + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM footnotes when serializing to HTML. + */ +export function gfmFootnoteHtml(options) { + const config = options || emptyOptions + const label = config.label || 'Footnotes' + const labelTagName = config.labelTagName || 'h2' + const labelAttributes = + config.labelAttributes === null || config.labelAttributes === undefined + ? 'class="sr-only"' + : config.labelAttributes + const backLabel = config.backLabel || defaultBackLabel + const clobberPrefix = + config.clobberPrefix === null || config.clobberPrefix === undefined + ? 'user-content-' + : config.clobberPrefix + return { + enter: { + gfmFootnoteDefinition() { + const stack = this.getData('tightStack') + stack.push(false) + }, + gfmFootnoteDefinitionLabelString() { + this.buffer() + }, + gfmFootnoteCallString() { + this.buffer() + } + }, + exit: { + gfmFootnoteDefinition() { + let definitions = this.getData('gfmFootnoteDefinitions') + const footnoteStack = this.getData('gfmFootnoteDefinitionStack') + assert(footnoteStack, 'expected `footnoteStack`') + const tightStack = this.getData('tightStack') + const current = footnoteStack.pop() + const value = this.resume() + + assert(current, 'expected to be in a footnote') + + if (!definitions) { + this.setData('gfmFootnoteDefinitions', (definitions = {})) + } + + if (!own.call(definitions, current)) definitions[current] = value + + tightStack.pop() + this.setData('slurpOneLineEnding', true) + // “Hack” to prevent a line ending from showing up if we’re in a definition in + // an empty list item. + this.setData('lastWasTag') + }, + gfmFootnoteDefinitionLabelString(token) { + let footnoteStack = this.getData('gfmFootnoteDefinitionStack') + + if (!footnoteStack) { + this.setData('gfmFootnoteDefinitionStack', (footnoteStack = [])) + } + + footnoteStack.push(normalizeIdentifier(this.sliceSerialize(token))) + this.resume() // Drop the label. + this.buffer() // Get ready for a value. + }, + gfmFootnoteCallString(token) { + let calls = this.getData('gfmFootnoteCallOrder') + let counts = this.getData('gfmFootnoteCallCounts') + const id = normalizeIdentifier(this.sliceSerialize(token)) + /** @type {number} */ + let counter + + this.resume() + + if (!calls) this.setData('gfmFootnoteCallOrder', (calls = [])) + if (!counts) this.setData('gfmFootnoteCallCounts', (counts = {})) + + const index = calls.indexOf(id) + const safeId = sanitizeUri(id.toLowerCase()) + + if (index === -1) { + calls.push(id) + counts[id] = 1 + counter = calls.length + } else { + counts[id]++ + counter = index + 1 + } + + const reuseCounter = counts[id] + + this.tag( + '' + + String(counter) + + '' + ) + }, + null() { + const calls = this.getData('gfmFootnoteCallOrder') || [] + const counts = this.getData('gfmFootnoteCallCounts') || {} + const definitions = this.getData('gfmFootnoteDefinitions') || {} + let index = -1 + + if (calls.length > 0) { + this.lineEndingIfNeeded() + this.tag( + '
<' + + labelTagName + + ' id="footnote-label"' + + (labelAttributes ? ' ' + labelAttributes : '') + + '>' + ) + this.raw(this.encode(label)) + this.tag('') + this.lineEndingIfNeeded() + this.tag('
    ') + } + + while (++index < calls.length) { + // Called definitions are always defined. + const id = calls[index] + const safeId = sanitizeUri(id.toLowerCase()) + let referenceIndex = 0 + /** @type {Array} */ + const references = [] + + while (++referenceIndex <= counts[id]) { + references.push( + '↩' + + (referenceIndex > 1 + ? '' + referenceIndex + '' + : '') + + '' + ) + } + + const reference = references.join(' ') + let injected = false + + this.lineEndingIfNeeded() + this.tag('
  1. ') + this.lineEndingIfNeeded() + this.tag( + definitions[id].replace(/<\/p>(?:\r?\n|\r)?$/, function ($0) { + injected = true + return ' ' + reference + $0 + }) + ) + + if (!injected) { + this.lineEndingIfNeeded() + this.tag(reference) + } + + this.lineEndingIfNeeded() + this.tag('
  2. ') + } + + if (calls.length > 0) { + this.lineEndingIfNeeded() + this.tag('
') + this.lineEndingIfNeeded() + this.tag('
') + } + } + } + } +} diff --git a/node_modules/micromark-extension-gfm-footnote/dev/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-footnote/dev/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0daa354cd943bd9eec26282f6e7e0ad2b79bca6 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/dev/lib/syntax.d.ts @@ -0,0 +1,9 @@ +/** + * Create an extension for `micromark` to enable GFM footnote syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to + * enable GFM footnote syntax. + */ +export function gfmFootnote(): Extension; +import type { Extension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-footnote/dev/lib/syntax.js b/node_modules/micromark-extension-gfm-footnote/dev/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..caf14864b88a30af515a578a9536444d54c8a9f8 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/dev/lib/syntax.js @@ -0,0 +1,558 @@ +/** + * @import {Event, Exiter, Extension, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {blankLine} from 'micromark-core-commonmark' +import {factorySpace} from 'micromark-factory-space' +import {markdownLineEndingOrSpace} from 'micromark-util-character' +import {normalizeIdentifier} from 'micromark-util-normalize-identifier' +import {codes, constants, types} from 'micromark-util-symbol' + +const indent = {tokenize: tokenizeIndent, partial: true} + +// To do: micromark should support a `_hiddenGfmFootnoteSupport`, which only +// affects label start (image). +// That will let us drop `tokenizePotentialGfmFootnote*`. +// It currently has a `_hiddenFootnoteSupport`, which affects that and more. +// That can be removed when `micromark-extension-footnote` is archived. + +/** + * Create an extension for `micromark` to enable GFM footnote syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to + * enable GFM footnote syntax. + */ +export function gfmFootnote() { + /** @type {Extension} */ + return { + document: { + [codes.leftSquareBracket]: { + name: 'gfmFootnoteDefinition', + tokenize: tokenizeDefinitionStart, + continuation: {tokenize: tokenizeDefinitionContinuation}, + exit: gfmFootnoteDefinitionEnd + } + }, + text: { + [codes.leftSquareBracket]: { + name: 'gfmFootnoteCall', + tokenize: tokenizeGfmFootnoteCall + }, + [codes.rightSquareBracket]: { + name: 'gfmPotentialFootnoteCall', + add: 'after', + tokenize: tokenizePotentialGfmFootnoteCall, + resolveTo: resolveToPotentialGfmFootnoteCall + } + } + } +} + +// To do: remove after micromark update. +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizePotentialGfmFootnoteCall(effects, ok, nok) { + const self = this + let index = self.events.length + const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []) + /** @type {Token} */ + let labelStart + + // Find an opening. + while (index--) { + const token = self.events[index][1] + + if (token.type === types.labelImage) { + labelStart = token + break + } + + // Exit if we’ve walked far enough. + if ( + token.type === 'gfmFootnoteCall' || + token.type === types.labelLink || + token.type === types.label || + token.type === types.image || + token.type === types.link + ) { + break + } + } + + return start + + /** + * @type {State} + */ + function start(code) { + assert(code === codes.rightSquareBracket, 'expected `]`') + + if (!labelStart || !labelStart._balanced) { + return nok(code) + } + + const id = normalizeIdentifier( + self.sliceSerialize({start: labelStart.end, end: self.now()}) + ) + + if (id.codePointAt(0) !== codes.caret || !defined.includes(id.slice(1))) { + return nok(code) + } + + effects.enter('gfmFootnoteCallLabelMarker') + effects.consume(code) + effects.exit('gfmFootnoteCallLabelMarker') + return ok(code) + } +} + +// To do: remove after micromark update. +/** @type {Resolver} */ +function resolveToPotentialGfmFootnoteCall(events, context) { + let index = events.length + /** @type {Token | undefined} */ + let labelStart + + // Find an opening. + while (index--) { + if ( + events[index][1].type === types.labelImage && + events[index][0] === 'enter' + ) { + labelStart = events[index][1] + break + } + } + + assert(labelStart, 'expected `labelStart` to resolve') + + // Change the `labelImageMarker` to a `data`. + events[index + 1][1].type = types.data + events[index + 3][1].type = 'gfmFootnoteCallLabelMarker' + + // The whole (without `!`): + /** @type {Token} */ + const call = { + type: 'gfmFootnoteCall', + start: Object.assign({}, events[index + 3][1].start), + end: Object.assign({}, events[events.length - 1][1].end) + } + // The `^` marker + /** @type {Token} */ + const marker = { + type: 'gfmFootnoteCallMarker', + start: Object.assign({}, events[index + 3][1].end), + end: Object.assign({}, events[index + 3][1].end) + } + // Increment the end 1 character. + marker.end.column++ + marker.end.offset++ + marker.end._bufferIndex++ + /** @type {Token} */ + const string = { + type: 'gfmFootnoteCallString', + start: Object.assign({}, marker.end), + end: Object.assign({}, events[events.length - 1][1].start) + } + /** @type {Token} */ + const chunk = { + type: types.chunkString, + contentType: 'string', + start: Object.assign({}, string.start), + end: Object.assign({}, string.end) + } + + /** @type {Array} */ + const replacement = [ + // Take the `labelImageMarker` (now `data`, the `!`) + events[index + 1], + events[index + 2], + ['enter', call, context], + // The `[` + events[index + 3], + events[index + 4], + // The `^`. + ['enter', marker, context], + ['exit', marker, context], + // Everything in between. + ['enter', string, context], + ['enter', chunk, context], + ['exit', chunk, context], + ['exit', string, context], + // The ending (`]`, properly parsed and labelled). + events[events.length - 2], + events[events.length - 1], + ['exit', call, context] + ] + + events.splice(index, events.length - index + 1, ...replacement) + + return events +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeGfmFootnoteCall(effects, ok, nok) { + const self = this + const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []) + let size = 0 + /** @type {boolean} */ + let data + + // Note: the implementation of `markdown-rs` is different, because it houses + // core *and* extensions in one project. + // Therefore, it can include footnote logic inside `label-end`. + // We can’t do that, but luckily, we can parse footnotes in a simpler way than + // needed for labels. + return start + + /** + * Start of footnote label. + * + * ```markdown + * > | a [^b] c + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.leftSquareBracket, 'expected `[`') + effects.enter('gfmFootnoteCall') + effects.enter('gfmFootnoteCallLabelMarker') + effects.consume(code) + effects.exit('gfmFootnoteCallLabelMarker') + return callStart + } + + /** + * After `[`, at `^`. + * + * ```markdown + * > | a [^b] c + * ^ + * ``` + * + * @type {State} + */ + function callStart(code) { + if (code !== codes.caret) return nok(code) + + effects.enter('gfmFootnoteCallMarker') + effects.consume(code) + effects.exit('gfmFootnoteCallMarker') + effects.enter('gfmFootnoteCallString') + effects.enter('chunkString').contentType = 'string' + return callData + } + + /** + * In label. + * + * ```markdown + * > | a [^b] c + * ^ + * ``` + * + * @type {State} + */ + function callData(code) { + if ( + // Too long. + size > constants.linkReferenceSizeMax || + // Closing brace with nothing. + (code === codes.rightSquareBracket && !data) || + // Space or tab is not supported by GFM for some reason. + // `\n` and `[` not being supported makes sense. + code === codes.eof || + code === codes.leftSquareBracket || + markdownLineEndingOrSpace(code) + ) { + return nok(code) + } + + if (code === codes.rightSquareBracket) { + effects.exit('chunkString') + const token = effects.exit('gfmFootnoteCallString') + + if (!defined.includes(normalizeIdentifier(self.sliceSerialize(token)))) { + return nok(code) + } + + effects.enter('gfmFootnoteCallLabelMarker') + effects.consume(code) + effects.exit('gfmFootnoteCallLabelMarker') + effects.exit('gfmFootnoteCall') + return ok + } + + if (!markdownLineEndingOrSpace(code)) { + data = true + } + + size++ + effects.consume(code) + return code === codes.backslash ? callEscape : callData + } + + /** + * On character after escape. + * + * ```markdown + * > | a [^b\c] d + * ^ + * ``` + * + * @type {State} + */ + function callEscape(code) { + if ( + code === codes.leftSquareBracket || + code === codes.backslash || + code === codes.rightSquareBracket + ) { + effects.consume(code) + size++ + return callData + } + + return callData(code) + } +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeDefinitionStart(effects, ok, nok) { + const self = this + const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []) + /** @type {string} */ + let identifier + let size = 0 + /** @type {boolean | undefined} */ + let data + + return start + + /** + * Start of GFM footnote definition. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.leftSquareBracket, 'expected `[`') + effects.enter('gfmFootnoteDefinition')._container = true + effects.enter('gfmFootnoteDefinitionLabel') + effects.enter('gfmFootnoteDefinitionLabelMarker') + effects.consume(code) + effects.exit('gfmFootnoteDefinitionLabelMarker') + return labelAtMarker + } + + /** + * In label, at caret. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function labelAtMarker(code) { + if (code === codes.caret) { + effects.enter('gfmFootnoteDefinitionMarker') + effects.consume(code) + effects.exit('gfmFootnoteDefinitionMarker') + effects.enter('gfmFootnoteDefinitionLabelString') + effects.enter('chunkString').contentType = 'string' + return labelInside + } + + return nok(code) + } + + /** + * In label. + * + * > 👉 **Note**: `cmark-gfm` prevents whitespace from occurring in footnote + * > definition labels. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function labelInside(code) { + if ( + // Too long. + size > constants.linkReferenceSizeMax || + // Closing brace with nothing. + (code === codes.rightSquareBracket && !data) || + // Space or tab is not supported by GFM for some reason. + // `\n` and `[` not being supported makes sense. + code === codes.eof || + code === codes.leftSquareBracket || + markdownLineEndingOrSpace(code) + ) { + return nok(code) + } + + if (code === codes.rightSquareBracket) { + effects.exit('chunkString') + const token = effects.exit('gfmFootnoteDefinitionLabelString') + identifier = normalizeIdentifier(self.sliceSerialize(token)) + effects.enter('gfmFootnoteDefinitionLabelMarker') + effects.consume(code) + effects.exit('gfmFootnoteDefinitionLabelMarker') + effects.exit('gfmFootnoteDefinitionLabel') + return labelAfter + } + + if (!markdownLineEndingOrSpace(code)) { + data = true + } + + size++ + effects.consume(code) + return code === codes.backslash ? labelEscape : labelInside + } + + /** + * After `\`, at a special character. + * + * > 👉 **Note**: `cmark-gfm` currently does not support escaped brackets: + * > + * + * ```markdown + * > | [^a\*b]: c + * ^ + * ``` + * + * @type {State} + */ + function labelEscape(code) { + if ( + code === codes.leftSquareBracket || + code === codes.backslash || + code === codes.rightSquareBracket + ) { + effects.consume(code) + size++ + return labelInside + } + + return labelInside(code) + } + + /** + * After definition label. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function labelAfter(code) { + if (code === codes.colon) { + effects.enter('definitionMarker') + effects.consume(code) + effects.exit('definitionMarker') + + if (!defined.includes(identifier)) { + defined.push(identifier) + } + + // Any whitespace after the marker is eaten, forming indented code + // is not possible. + // No space is also fine, just like a block quote marker. + return factorySpace( + effects, + whitespaceAfter, + 'gfmFootnoteDefinitionWhitespace' + ) + } + + return nok(code) + } + + /** + * After definition prefix. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function whitespaceAfter(code) { + // `markdown-rs` has a wrapping token for the prefix that is closed here. + return ok(code) + } +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeDefinitionContinuation(effects, ok, nok) { + /// Start of footnote definition continuation. + /// + /// ```markdown + /// | [^a]: b + /// > | c + /// ^ + /// ``` + // + // Either a blank line, which is okay, or an indented thing. + return effects.check(blankLine, ok, effects.attempt(indent, ok, nok)) +} + +/** @type {Exiter} */ +function gfmFootnoteDefinitionEnd(effects) { + effects.exit('gfmFootnoteDefinition') +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeIndent(effects, ok, nok) { + const self = this + + return factorySpace( + effects, + afterPrefix, + 'gfmFootnoteDefinitionIndent', + constants.tabSize + 1 + ) + + /** + * @type {State} + */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1] + return tail && + tail[1].type === 'gfmFootnoteDefinitionIndent' && + tail[2].sliceSerialize(tail[1], true).length === constants.tabSize + ? ok(code) + : nok(code) + } +} diff --git a/node_modules/micromark-extension-gfm-footnote/index.d.ts b/node_modules/micromark-extension-gfm-footnote/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1be286871d3a5984a0f8fd12c9a1aef63e1d0af2 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/index.d.ts @@ -0,0 +1,164 @@ +export {gfmFootnoteHtml, defaultBackLabel} from './lib/html.js' +export {gfmFootnote} from './lib/syntax.js' + +/** + * Generate a back label dynamically. + * + * For the following markdown: + * + * ```markdown + * Alpha[^micromark], bravo[^micromark], and charlie[^remark]. + * + * [^remark]: things about remark + * [^micromark]: things about micromark + * ``` + * + * This function will be called with: + * + * * `0` and `0` for the backreference from `things about micromark` to + * `alpha`, as it is the first used definition, and the first call to it + * * `0` and `1` for the backreference from `things about micromark` to + * `bravo`, as it is the first used definition, and the second call to it + * * `1` and `0` for the backreference from `things about remark` to + * `charlie`, as it is the second used definition + * + * @param referenceIndex + * Index of the definition in the order that they are first referenced, + * 0-indexed. + * @param rereferenceIndex + * Index of calls to the same definition, 0-indexed. + * @returns + * Back label to use when linking back from definitions to their reference. + */ +export type BackLabelTemplate = ( + referenceIndex: number, + rereferenceIndex: number +) => string + +/** + * Configuration. + */ +export interface HtmlOptions { + /** + * Prefix to use before the `id` attribute on footnotes to prevent them from + * *clobbering* (default: `'user-content-'`). + * + * Pass `''` for trusted markdown and when you are careful with + * polyfilling. + * You could pass a different prefix. + * + * DOM clobbering is this: + * + * ```html + *

+ * + * ``` + * + * The above example shows that elements are made available by browsers, by + * their ID, on the `window` object. + * This is a security risk because you might be expecting some other variable + * at that place. + * It can also break polyfills. + * Using a prefix solves these problems. + */ + clobberPrefix?: string | null | undefined + /** + * Textual label to use for the footnotes section (default: `'Footnotes'`). + * + * Change it when the markdown is not in English. + * + * This label is typically hidden visually (assuming a `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass different attributes with the `labelAttributes` option. + */ + label?: string | null | undefined + /** + * Attributes to use on the footnote label (default: `'class="sr-only"'`). + * + * Change it to show the label and add other attributes. + * + * This label is typically hidden visually (assuming an `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass an empty string. + * You can also add different attributes. + * + * > 👉 **Note**: `id="footnote-label"` is always added, because footnote + * > calls use it with `aria-describedby` to provide an accessible label. + */ + labelAttributes?: string | null | undefined + /** + * HTML tag name to use for the footnote label element (default: `'h2'`). + * + * Change it to match your document structure. + * + * This label is typically hidden visually (assuming a `sr-only` CSS class + * is defined that does that) and so affects screen readers only. + * If you do have such a class, but want to show this section to everyone, + * pass different attributes with the `labelAttributes` option. + */ + labelTagName?: string | null | undefined + /** + * Textual label to describe the backreference back to references (default: + * `defaultBackLabel`). + * + * The default value is: + * + * ```js + * function defaultBackLabel(referenceIndex, rereferenceIndex) { + * return ( + * 'Back to reference ' + + * (referenceIndex + 1) + + * (rereferenceIndex > 1 ? '-' + rereferenceIndex : '') + * ) + * } + * ``` + * + * Change it when the markdown is not in English. + * + * This label is used in the `aria-label` attribute on each backreference + * (the `↩` links). + * It affects users of assistive technology. + */ + backLabel?: BackLabelTemplate | string | null | undefined +} + +/** + * Augment types. + */ +declare module 'micromark-util-types' { + /** + * Compile data. + */ + interface CompileData { + gfmFootnoteDefinitions?: Record + gfmFootnoteDefinitionStack?: Array + gfmFootnoteCallCounts?: Record + gfmFootnoteCallOrder?: Array + } + + /** + * Parse context. + */ + interface ParseContext { + gfmFootnotes?: Array + } + + /** + * Token types. + */ + interface TokenTypeMap { + gfmFootnoteCall: 'gfmFootnoteCall' + gfmFootnoteCallLabelMarker: 'gfmFootnoteCallLabelMarker' + gfmFootnoteCallMarker: 'gfmFootnoteCallMarker' + gfmFootnoteCallString: 'gfmFootnoteCallString' + gfmFootnoteDefinition: 'gfmFootnoteDefinition' + gfmFootnoteDefinitionIndent: 'gfmFootnoteDefinitionIndent' + gfmFootnoteDefinitionLabel: 'gfmFootnoteDefinitionLabel' + gfmFootnoteDefinitionLabelMarker: 'gfmFootnoteDefinitionLabelMarker' + gfmFootnoteDefinitionLabelString: 'gfmFootnoteDefinitionLabelString' + gfmFootnoteDefinitionMarker: 'gfmFootnoteDefinitionMarker' + gfmFootnoteDefinitionWhitespace: 'gfmFootnoteDefinitionWhitespace' + } +} diff --git a/node_modules/micromark-extension-gfm-footnote/index.js b/node_modules/micromark-extension-gfm-footnote/index.js new file mode 100644 index 0000000000000000000000000000000000000000..b210cb3dae964bfce62711003eed842d481528e1 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/index.js @@ -0,0 +1,3 @@ +// Note: types are exported from `dev/index.d.ts`. +export { gfmFootnote } from './lib/syntax.js'; +export { gfmFootnoteHtml, defaultBackLabel } from './lib/html.js'; \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-footnote/lib/html.d.ts b/node_modules/micromark-extension-gfm-footnote/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..dbcd2a6c8435163363ee5ee95a301fd91258147d --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/lib/html.d.ts @@ -0,0 +1,25 @@ +/** + * Generate the default label that GitHub uses on backreferences. + * + * @param {number} referenceIndex + * Index of the definition in the order that they are first referenced, + * 0-indexed. + * @param {number} rereferenceIndex + * Index of calls to the same definition, 0-indexed. + * @returns {string} + * Default label. + */ +export function defaultBackLabel(referenceIndex: number, rereferenceIndex: number): string; +/** + * Create an extension for `micromark` to support GFM footnotes when + * serializing to HTML. + * + * @param {Options | null | undefined} [options={}] + * Configuration (optional). + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM footnotes when serializing to HTML. + */ +export function gfmFootnoteHtml(options?: Options | null | undefined): HtmlExtension; +import type { HtmlOptions as Options } from 'micromark-extension-gfm-footnote'; +import type { HtmlExtension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-footnote/lib/html.js b/node_modules/micromark-extension-gfm-footnote/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..815e4021be5e4ad6e388186f1ca1f7f466a551bd --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/lib/html.js @@ -0,0 +1,154 @@ +/** + * @import {HtmlOptions as Options} from 'micromark-extension-gfm-footnote' + * @import {HtmlExtension} from 'micromark-util-types' + */ + +import { normalizeIdentifier } from 'micromark-util-normalize-identifier'; +import { sanitizeUri } from 'micromark-util-sanitize-uri'; +const own = {}.hasOwnProperty; + +/** @type {Options} */ +const emptyOptions = {}; + +/** + * Generate the default label that GitHub uses on backreferences. + * + * @param {number} referenceIndex + * Index of the definition in the order that they are first referenced, + * 0-indexed. + * @param {number} rereferenceIndex + * Index of calls to the same definition, 0-indexed. + * @returns {string} + * Default label. + */ +export function defaultBackLabel(referenceIndex, rereferenceIndex) { + return 'Back to reference ' + (referenceIndex + 1) + (rereferenceIndex > 1 ? '-' + rereferenceIndex : ''); +} + +/** + * Create an extension for `micromark` to support GFM footnotes when + * serializing to HTML. + * + * @param {Options | null | undefined} [options={}] + * Configuration (optional). + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM footnotes when serializing to HTML. + */ +export function gfmFootnoteHtml(options) { + const config = options || emptyOptions; + const label = config.label || 'Footnotes'; + const labelTagName = config.labelTagName || 'h2'; + const labelAttributes = config.labelAttributes === null || config.labelAttributes === undefined ? 'class="sr-only"' : config.labelAttributes; + const backLabel = config.backLabel || defaultBackLabel; + const clobberPrefix = config.clobberPrefix === null || config.clobberPrefix === undefined ? 'user-content-' : config.clobberPrefix; + return { + enter: { + gfmFootnoteDefinition() { + const stack = this.getData('tightStack'); + stack.push(false); + }, + gfmFootnoteDefinitionLabelString() { + this.buffer(); + }, + gfmFootnoteCallString() { + this.buffer(); + } + }, + exit: { + gfmFootnoteDefinition() { + let definitions = this.getData('gfmFootnoteDefinitions'); + const footnoteStack = this.getData('gfmFootnoteDefinitionStack'); + const tightStack = this.getData('tightStack'); + const current = footnoteStack.pop(); + const value = this.resume(); + if (!definitions) { + this.setData('gfmFootnoteDefinitions', definitions = {}); + } + if (!own.call(definitions, current)) definitions[current] = value; + tightStack.pop(); + this.setData('slurpOneLineEnding', true); + // “Hack” to prevent a line ending from showing up if we’re in a definition in + // an empty list item. + this.setData('lastWasTag'); + }, + gfmFootnoteDefinitionLabelString(token) { + let footnoteStack = this.getData('gfmFootnoteDefinitionStack'); + if (!footnoteStack) { + this.setData('gfmFootnoteDefinitionStack', footnoteStack = []); + } + footnoteStack.push(normalizeIdentifier(this.sliceSerialize(token))); + this.resume(); // Drop the label. + this.buffer(); // Get ready for a value. + }, + gfmFootnoteCallString(token) { + let calls = this.getData('gfmFootnoteCallOrder'); + let counts = this.getData('gfmFootnoteCallCounts'); + const id = normalizeIdentifier(this.sliceSerialize(token)); + /** @type {number} */ + let counter; + this.resume(); + if (!calls) this.setData('gfmFootnoteCallOrder', calls = []); + if (!counts) this.setData('gfmFootnoteCallCounts', counts = {}); + const index = calls.indexOf(id); + const safeId = sanitizeUri(id.toLowerCase()); + if (index === -1) { + calls.push(id); + counts[id] = 1; + counter = calls.length; + } else { + counts[id]++; + counter = index + 1; + } + const reuseCounter = counts[id]; + this.tag('' + String(counter) + ''); + }, + null() { + const calls = this.getData('gfmFootnoteCallOrder') || []; + const counts = this.getData('gfmFootnoteCallCounts') || {}; + const definitions = this.getData('gfmFootnoteDefinitions') || {}; + let index = -1; + if (calls.length > 0) { + this.lineEndingIfNeeded(); + this.tag('
<' + labelTagName + ' id="footnote-label"' + (labelAttributes ? ' ' + labelAttributes : '') + '>'); + this.raw(this.encode(label)); + this.tag(''); + this.lineEndingIfNeeded(); + this.tag('
    '); + } + while (++index < calls.length) { + // Called definitions are always defined. + const id = calls[index]; + const safeId = sanitizeUri(id.toLowerCase()); + let referenceIndex = 0; + /** @type {Array} */ + const references = []; + while (++referenceIndex <= counts[id]) { + references.push('↩' + (referenceIndex > 1 ? '' + referenceIndex + '' : '') + ''); + } + const reference = references.join(' '); + let injected = false; + this.lineEndingIfNeeded(); + this.tag('
  1. '); + this.lineEndingIfNeeded(); + this.tag(definitions[id].replace(/<\/p>(?:\r?\n|\r)?$/, function ($0) { + injected = true; + return ' ' + reference + $0; + })); + if (!injected) { + this.lineEndingIfNeeded(); + this.tag(reference); + } + this.lineEndingIfNeeded(); + this.tag('
  2. '); + } + if (calls.length > 0) { + this.lineEndingIfNeeded(); + this.tag('
'); + this.lineEndingIfNeeded(); + this.tag('
'); + } + } + } + }; +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-footnote/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-footnote/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..b0daa354cd943bd9eec26282f6e7e0ad2b79bca6 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/lib/syntax.d.ts @@ -0,0 +1,9 @@ +/** + * Create an extension for `micromark` to enable GFM footnote syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to + * enable GFM footnote syntax. + */ +export function gfmFootnote(): Extension; +import type { Extension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-footnote/lib/syntax.js b/node_modules/micromark-extension-gfm-footnote/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..5a8b1af5ea41c63aa4185d5b0afe143a894c938b --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/lib/syntax.js @@ -0,0 +1,485 @@ +/** + * @import {Event, Exiter, Extension, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +import { blankLine } from 'micromark-core-commonmark'; +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEndingOrSpace } from 'micromark-util-character'; +import { normalizeIdentifier } from 'micromark-util-normalize-identifier'; +const indent = { + tokenize: tokenizeIndent, + partial: true +}; + +// To do: micromark should support a `_hiddenGfmFootnoteSupport`, which only +// affects label start (image). +// That will let us drop `tokenizePotentialGfmFootnote*`. +// It currently has a `_hiddenFootnoteSupport`, which affects that and more. +// That can be removed when `micromark-extension-footnote` is archived. + +/** + * Create an extension for `micromark` to enable GFM footnote syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to + * enable GFM footnote syntax. + */ +export function gfmFootnote() { + /** @type {Extension} */ + return { + document: { + [91]: { + name: 'gfmFootnoteDefinition', + tokenize: tokenizeDefinitionStart, + continuation: { + tokenize: tokenizeDefinitionContinuation + }, + exit: gfmFootnoteDefinitionEnd + } + }, + text: { + [91]: { + name: 'gfmFootnoteCall', + tokenize: tokenizeGfmFootnoteCall + }, + [93]: { + name: 'gfmPotentialFootnoteCall', + add: 'after', + tokenize: tokenizePotentialGfmFootnoteCall, + resolveTo: resolveToPotentialGfmFootnoteCall + } + } + }; +} + +// To do: remove after micromark update. +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizePotentialGfmFootnoteCall(effects, ok, nok) { + const self = this; + let index = self.events.length; + const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []); + /** @type {Token} */ + let labelStart; + + // Find an opening. + while (index--) { + const token = self.events[index][1]; + if (token.type === "labelImage") { + labelStart = token; + break; + } + + // Exit if we’ve walked far enough. + if (token.type === 'gfmFootnoteCall' || token.type === "labelLink" || token.type === "label" || token.type === "image" || token.type === "link") { + break; + } + } + return start; + + /** + * @type {State} + */ + function start(code) { + if (!labelStart || !labelStart._balanced) { + return nok(code); + } + const id = normalizeIdentifier(self.sliceSerialize({ + start: labelStart.end, + end: self.now() + })); + if (id.codePointAt(0) !== 94 || !defined.includes(id.slice(1))) { + return nok(code); + } + effects.enter('gfmFootnoteCallLabelMarker'); + effects.consume(code); + effects.exit('gfmFootnoteCallLabelMarker'); + return ok(code); + } +} + +// To do: remove after micromark update. +/** @type {Resolver} */ +function resolveToPotentialGfmFootnoteCall(events, context) { + let index = events.length; + /** @type {Token | undefined} */ + let labelStart; + + // Find an opening. + while (index--) { + if (events[index][1].type === "labelImage" && events[index][0] === 'enter') { + labelStart = events[index][1]; + break; + } + } + // Change the `labelImageMarker` to a `data`. + events[index + 1][1].type = "data"; + events[index + 3][1].type = 'gfmFootnoteCallLabelMarker'; + + // The whole (without `!`): + /** @type {Token} */ + const call = { + type: 'gfmFootnoteCall', + start: Object.assign({}, events[index + 3][1].start), + end: Object.assign({}, events[events.length - 1][1].end) + }; + // The `^` marker + /** @type {Token} */ + const marker = { + type: 'gfmFootnoteCallMarker', + start: Object.assign({}, events[index + 3][1].end), + end: Object.assign({}, events[index + 3][1].end) + }; + // Increment the end 1 character. + marker.end.column++; + marker.end.offset++; + marker.end._bufferIndex++; + /** @type {Token} */ + const string = { + type: 'gfmFootnoteCallString', + start: Object.assign({}, marker.end), + end: Object.assign({}, events[events.length - 1][1].start) + }; + /** @type {Token} */ + const chunk = { + type: "chunkString", + contentType: 'string', + start: Object.assign({}, string.start), + end: Object.assign({}, string.end) + }; + + /** @type {Array} */ + const replacement = [ + // Take the `labelImageMarker` (now `data`, the `!`) + events[index + 1], events[index + 2], ['enter', call, context], + // The `[` + events[index + 3], events[index + 4], + // The `^`. + ['enter', marker, context], ['exit', marker, context], + // Everything in between. + ['enter', string, context], ['enter', chunk, context], ['exit', chunk, context], ['exit', string, context], + // The ending (`]`, properly parsed and labelled). + events[events.length - 2], events[events.length - 1], ['exit', call, context]]; + events.splice(index, events.length - index + 1, ...replacement); + return events; +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeGfmFootnoteCall(effects, ok, nok) { + const self = this; + const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []); + let size = 0; + /** @type {boolean} */ + let data; + + // Note: the implementation of `markdown-rs` is different, because it houses + // core *and* extensions in one project. + // Therefore, it can include footnote logic inside `label-end`. + // We can’t do that, but luckily, we can parse footnotes in a simpler way than + // needed for labels. + return start; + + /** + * Start of footnote label. + * + * ```markdown + * > | a [^b] c + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter('gfmFootnoteCall'); + effects.enter('gfmFootnoteCallLabelMarker'); + effects.consume(code); + effects.exit('gfmFootnoteCallLabelMarker'); + return callStart; + } + + /** + * After `[`, at `^`. + * + * ```markdown + * > | a [^b] c + * ^ + * ``` + * + * @type {State} + */ + function callStart(code) { + if (code !== 94) return nok(code); + effects.enter('gfmFootnoteCallMarker'); + effects.consume(code); + effects.exit('gfmFootnoteCallMarker'); + effects.enter('gfmFootnoteCallString'); + effects.enter('chunkString').contentType = 'string'; + return callData; + } + + /** + * In label. + * + * ```markdown + * > | a [^b] c + * ^ + * ``` + * + * @type {State} + */ + function callData(code) { + if ( + // Too long. + size > 999 || + // Closing brace with nothing. + code === 93 && !data || + // Space or tab is not supported by GFM for some reason. + // `\n` and `[` not being supported makes sense. + code === null || code === 91 || markdownLineEndingOrSpace(code)) { + return nok(code); + } + if (code === 93) { + effects.exit('chunkString'); + const token = effects.exit('gfmFootnoteCallString'); + if (!defined.includes(normalizeIdentifier(self.sliceSerialize(token)))) { + return nok(code); + } + effects.enter('gfmFootnoteCallLabelMarker'); + effects.consume(code); + effects.exit('gfmFootnoteCallLabelMarker'); + effects.exit('gfmFootnoteCall'); + return ok; + } + if (!markdownLineEndingOrSpace(code)) { + data = true; + } + size++; + effects.consume(code); + return code === 92 ? callEscape : callData; + } + + /** + * On character after escape. + * + * ```markdown + * > | a [^b\c] d + * ^ + * ``` + * + * @type {State} + */ + function callEscape(code) { + if (code === 91 || code === 92 || code === 93) { + effects.consume(code); + size++; + return callData; + } + return callData(code); + } +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeDefinitionStart(effects, ok, nok) { + const self = this; + const defined = self.parser.gfmFootnotes || (self.parser.gfmFootnotes = []); + /** @type {string} */ + let identifier; + let size = 0; + /** @type {boolean | undefined} */ + let data; + return start; + + /** + * Start of GFM footnote definition. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter('gfmFootnoteDefinition')._container = true; + effects.enter('gfmFootnoteDefinitionLabel'); + effects.enter('gfmFootnoteDefinitionLabelMarker'); + effects.consume(code); + effects.exit('gfmFootnoteDefinitionLabelMarker'); + return labelAtMarker; + } + + /** + * In label, at caret. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function labelAtMarker(code) { + if (code === 94) { + effects.enter('gfmFootnoteDefinitionMarker'); + effects.consume(code); + effects.exit('gfmFootnoteDefinitionMarker'); + effects.enter('gfmFootnoteDefinitionLabelString'); + effects.enter('chunkString').contentType = 'string'; + return labelInside; + } + return nok(code); + } + + /** + * In label. + * + * > 👉 **Note**: `cmark-gfm` prevents whitespace from occurring in footnote + * > definition labels. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function labelInside(code) { + if ( + // Too long. + size > 999 || + // Closing brace with nothing. + code === 93 && !data || + // Space or tab is not supported by GFM for some reason. + // `\n` and `[` not being supported makes sense. + code === null || code === 91 || markdownLineEndingOrSpace(code)) { + return nok(code); + } + if (code === 93) { + effects.exit('chunkString'); + const token = effects.exit('gfmFootnoteDefinitionLabelString'); + identifier = normalizeIdentifier(self.sliceSerialize(token)); + effects.enter('gfmFootnoteDefinitionLabelMarker'); + effects.consume(code); + effects.exit('gfmFootnoteDefinitionLabelMarker'); + effects.exit('gfmFootnoteDefinitionLabel'); + return labelAfter; + } + if (!markdownLineEndingOrSpace(code)) { + data = true; + } + size++; + effects.consume(code); + return code === 92 ? labelEscape : labelInside; + } + + /** + * After `\`, at a special character. + * + * > 👉 **Note**: `cmark-gfm` currently does not support escaped brackets: + * > + * + * ```markdown + * > | [^a\*b]: c + * ^ + * ``` + * + * @type {State} + */ + function labelEscape(code) { + if (code === 91 || code === 92 || code === 93) { + effects.consume(code); + size++; + return labelInside; + } + return labelInside(code); + } + + /** + * After definition label. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function labelAfter(code) { + if (code === 58) { + effects.enter('definitionMarker'); + effects.consume(code); + effects.exit('definitionMarker'); + if (!defined.includes(identifier)) { + defined.push(identifier); + } + + // Any whitespace after the marker is eaten, forming indented code + // is not possible. + // No space is also fine, just like a block quote marker. + return factorySpace(effects, whitespaceAfter, 'gfmFootnoteDefinitionWhitespace'); + } + return nok(code); + } + + /** + * After definition prefix. + * + * ```markdown + * > | [^a]: b + * ^ + * ``` + * + * @type {State} + */ + function whitespaceAfter(code) { + // `markdown-rs` has a wrapping token for the prefix that is closed here. + return ok(code); + } +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeDefinitionContinuation(effects, ok, nok) { + /// Start of footnote definition continuation. + /// + /// ```markdown + /// | [^a]: b + /// > | c + /// ^ + /// ``` + // + // Either a blank line, which is okay, or an indented thing. + return effects.check(blankLine, ok, effects.attempt(indent, ok, nok)); +} + +/** @type {Exiter} */ +function gfmFootnoteDefinitionEnd(effects) { + effects.exit('gfmFootnoteDefinition'); +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeIndent(effects, ok, nok) { + const self = this; + return factorySpace(effects, afterPrefix, 'gfmFootnoteDefinitionIndent', 4 + 1); + + /** + * @type {State} + */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1]; + return tail && tail[1].type === 'gfmFootnoteDefinitionIndent' && tail[2].sliceSerialize(tail[1], true).length === 4 ? ok(code) : nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-footnote/license b/node_modules/micromark-extension-gfm-footnote/license new file mode 100644 index 0000000000000000000000000000000000000000..f4fb31fe44ababc8c433e7d44eca5f8169e27e00 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2021 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark-extension-gfm-footnote/package.json b/node_modules/micromark-extension-gfm-footnote/package.json new file mode 100644 index 0000000000000000000000000000000000000000..bcbf3e6c464b6b80e1af89338b5a0dfc43970eff --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/package.json @@ -0,0 +1,132 @@ +{ + "name": "micromark-extension-gfm-footnote", + "version": "2.1.0", + "description": "micromark extension to support GFM footnotes", + "license": "MIT", + "keywords": [ + "micromark", + "micromark-extension", + "gfm", + "footnote", + "note", + "definition", + "markdown", + "unified" + ], + "repository": "micromark/micromark-extension-gfm-footnote", + "bugs": "https://github.com/micromark/micromark-extension-gfm-footnote/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "files": [ + "dev/", + "lib/", + "index.d.ts", + "index.js" + ], + "exports": { + "development": "./dev/index.js", + "default": "./index.js" + }, + "dependencies": { + "devlop": "^1.0.0", + "micromark-core-commonmark": "^2.0.0", + "micromark-factory-space": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-normalize-identifier": "^2.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^10.0.0", + "create-gfm-fixtures": "^1.0.0", + "micromark": "^4.0.0", + "micromark-build": "^2.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.58.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage && micromark-build", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api-prod": "node --conditions production test/index.js", + "test-api-dev": "node --conditions development test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "prettier": true, + "rules": { + "logical-assignment-operators": "off", + "unicorn/no-this-assignment": "off", + "unicorn/prefer-at": "off", + "unicorn/prefer-string-replace-all": "off" + }, + "overrides": [ + { + "files": [ + "**/*.d.ts" + ], + "rules": { + "@typescript-eslint/array-type": [ + "error", + { + "default": "generic" + } + ], + "@typescript-eslint/ban-types": [ + "error", + { + "extendDefaults": true + } + ], + "@typescript-eslint/consistent-type-definitions": [ + "error", + "interface" + ] + } + }, + { + "files": [ + "test/**/*.js" + ], + "rules": { + "no-await-in-loop": 0 + } + } + ] + } +} diff --git a/node_modules/micromark-extension-gfm-footnote/readme.md b/node_modules/micromark-extension-gfm-footnote/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..4c446ae20baab5e2775948fadb6bcf3347443ac2 --- /dev/null +++ b/node_modules/micromark-extension-gfm-footnote/readme.md @@ -0,0 +1,656 @@ +# micromark-extension-gfm-footnote + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[micromark][] extensions to support GFM [footnotes][post]. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`defaultBackLabel(referenceIndex, rereferenceIndex)`](#defaultbacklabelreferenceindex-rereferenceindex) + * [`gfmFootnote()`](#gfmfootnote) + * [`gfmFootnoteHtml(options?)`](#gfmfootnotehtmloptions) + * [`BackLabelTemplate`](#backlabeltemplate) + * [`HtmlOptions`](#htmloptions) +* [Bugs](#bugs) +* [Authoring](#authoring) +* [HTML](#html) +* [CSS](#css) +* [Syntax](#syntax) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains extensions that add support for footnotes as enabled by +GFM to [`micromark`][micromark]. + +GitHub announced footnotes [on September 30, 2021][post] but did not specify +them in their GFM spec. +As they are implemented in their parser and supported in all places where +other GFM features work, they can be considered part of GFM. +GitHub employs several other features (such as mentions or frontmatter) that +are either not in their parser, or not in all places where GFM features work, +which should not be considered GFM. + +The implementation of footnotes on github.com is currently buggy. +The bugs have been reported on [`cmark-gfm`][cmark-gfm]. +This micromark extension matches github.com except for its bugs. + +## When to use this + +This project is useful when you want to support footnotes in markdown. + +You can use these extensions when you are working with [`micromark`][micromark]. +To support all GFM features, use +[`micromark-extension-gfm`][micromark-extension-gfm] instead. + +When you need a syntax tree, combine this package with +[`mdast-util-gfm-footnote`][mdast-util-gfm-footnote]. + +All these packages are used in [`remark-gfm`][remark-gfm], which focusses on +making it easier to transform content by abstracting these internals away. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install micromark-extension-gfm-footnote +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmFootnote, gfmFootnoteHtml} from 'https://esm.sh/micromark-extension-gfm-footnote@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.md` contains: + +````markdown +Using footnotes is fun![^1] They let you reference relevant information without disrupting the flow of what you’re trying to say.[^bignote] + +[^1]: This is the first footnote. +[^bignote]: Here’s one with multiple paragraphs and code. + + Indent paragraphs to include them in the footnote. + + ``` + my code + ``` + + Add as many paragraphs as you like. + +Text here and here and here. +[Learn more about markdown and footnotes in markdown](https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#footnotes) +```` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {micromark} from 'micromark' +import {gfmFootnote, gfmFootnoteHtml} from 'micromark-extension-gfm-footnote' + +const output = micromark(await fs.readFile('example.md'), { + extensions: [gfmFootnote()], + htmlExtensions: [gfmFootnoteHtml()] +}) + +console.log(output) +``` + +…now running `node example.js` yields: + +```html +

Using footnotes is fun!1 They let you reference relevant information without disrupting the flow of what you’re trying to say.2

+

Text here and here and here. +Learn more about markdown and footnotes in markdown

+

Footnotes

+
    +
  1. +

    This is the first footnote. ↩

    +
  2. +
  3. +

    Here’s one with multiple paragraphs and code.

    +

    Indent paragraphs to include them in the footnote.

    +
    my code
    +
    +

    Add as many paragraphs as you like. ↩

    +
  4. +
+
+``` + +## API + +This package exports the identifiers +[`defaultBackLabel`][api-default-back-label], +[`gfmFootnote`][api-gfm-footnote], and +[`gfmFootnoteHtml`][api-gfm-footnote-html]. +There is no default export. + +The export map supports the [`development` condition][development]. +Run `node --conditions development module.js` to get instrumented dev code. +Without this condition, production code is loaded. + +### `defaultBackLabel(referenceIndex, rereferenceIndex)` + +Generate the default label that GitHub uses on backreferences +([`BackLabelTemplate`][api-back-label-template]). + +### `gfmFootnote()` + +Create an extension for `micromark` to enable GFM footnote syntax. + +###### Returns + +Extension for `micromark` that can be passed in `extensions` to enable GFM +footnote syntax ([`Extension`][micromark-extension]). + +### `gfmFootnoteHtml(options?)` + +Create an extension for `micromark` to support GFM footnotes when serializing +to HTML. + +###### Parameters + +* `options` ([`HtmlOptions`][api-html-options], optional) + — configuration + +###### Returns + +Extension for `micromark` that can be passed in `htmlExtensions` to support GFM +footnotes when serializing to HTML +([`HtmlExtension`][micromark-html-extension]). + +### `BackLabelTemplate` + +Generate a back label dynamically (TypeScript type). + +For the following markdown: + +```markdown +Alpha[^micromark], bravo[^micromark], and charlie[^remark]. + +[^remark]: things about remark +[^micromark]: things about micromark +``` + +This function will be called with: + +* `0` and `0` for the backreference from `things about micromark` to + `alpha`, as it is the first used definition, and the first call to it +* `0` and `1` for the backreference from `things about micromark` to + `bravo`, as it is the first used definition, and the second call to it +* `1` and `0` for the backreference from `things about remark` to + `charlie`, as it is the second used definition + +###### Parameters + +* `referenceIndex` (`number`) + — index of the definition in the order that they are first referenced, + 0-indexed +* `rereferenceIndex` (`number`) + — index of calls to the same definition, 0-indexed + +###### Returns + +Back label to use when linking back from definitions to their reference +(`string`). + +### `HtmlOptions` + +Configuration (TypeScript type). + +##### Fields + +###### `clobberPrefix` + +Prefix to use before the `id` attribute on footnotes to prevent them from +*clobbering* (`string`, default: `'user-content-'`). + +Pass `''` for trusted markdown and when you are careful with polyfilling. +You could pass a different prefix. + +DOM clobbering is this: + +```html +

+ +``` + +The above example shows that elements are made available by browsers, by their +ID, on the `window` object. +This is a security risk because you might be expecting some other variable at +that place. +It can also break polyfills. +Using a prefix solves these problems. + +###### `label` + +Textual label to use for the footnotes section (`string`, default: +`'Footnotes'`). + +Change it when the markdown is not in English. + +This label is typically hidden visually (assuming a `sr-only` CSS class +is defined that does that) and so affects screen readers only. + +###### `labelAttributes` + +Attributes to use on the footnote label (`string`, default: +`'class="sr-only"'`). + +Change it to show the label and add other attributes. + +This label is typically hidden visually (assuming an `sr-only` CSS class +is defined that does that) and so affects screen readers only. +If you do have such a class, but want to show this section to everyone, +pass an empty string. +You can also add different attributes. + +> 👉 **Note**: `id="footnote-label"` is always added, because footnote +> calls use it with `aria-describedby` to provide an accessible label. + +###### `labelTagName` + +HTML tag name to use for the footnote label element (`string`, default: +`'h2'`). + +Change it to match your document structure. + +This label is typically hidden visually (assuming a `sr-only` CSS class +is defined that does that) and so affects screen readers only. + +###### `backLabel` + +Textual label to describe the backreference back to footnote calls +([`BackLabelTemplate`][api-back-label-template] or `string`, +default: [`defaultBackLabel`][api-default-back-label]). + +Change it when the markdown is not in English. + +This label is used in the [`aria-label`][aria-label] attribute on each +backreference (the `↩` links). +It affects users of assistive technology. + +## Bugs + +GitHub’s own algorithm to parse footnote definitions contains several bugs. +These are not present in this project. +The issues relating to footnote definitions are: + +* [Footnote reference call identifiers are trimmed, but definition + identifiers aren’t](https://github.com/github/cmark-gfm/issues/237)\ + — initial and final whitespace in labels causes them not to match +* [Footnotes are matched case-insensitive, but links keep their casing, + breaking them](https://github.com/github/cmark-gfm/issues/239)\ + — using uppercase (or any character that will be percent encoded) in + identifiers breaks links +* [Colons in footnotes generate links w/o + `href`](https://github.com/github/cmark-gfm/issues/250)\ + — colons in identifiers generate broken links +* [Character escape of `]` does not work in footnote + identifiers](https://github.com/github/cmark-gfm/issues/240)\ + — some character escapes don’t work +* [Footnotes in links are + broken](https://github.com/github/cmark-gfm/issues/249)\ + — while `CommonMark` prevents links in links, GitHub does not prevent + footnotes (which turn into links) in links +* [Footnote-like brackets around image, break that + image](https://github.com/github/cmark-gfm/issues/275)\ + — images can’t be used in what looks like a footnote call +* [GFM footnotes: line ending in footnote definition label causes text to + disappear](https://github.com/github/cmark-gfm/issues/282)\ + — line endings in footnote definitions cause text to disappear + +## Authoring + +When authoring markdown with footnotes it’s recommended to use words instead +of numbers (or letters or anything with an order) as identifiers. +That makes it easier to reuse and reorder footnotes. + +It’s recommended to place footnotes definitions at the bottom of the document. + +## HTML + +GFM footnotes do not, on their own, relate to anything in HTML. +When a footnote reference matches with a definition, they each relate to several +elements in HTML. + +The reference relates to `` and `` elements in HTML: + +```html +1

+``` + +…where `x` is the identifier used in the markdown source and `1` the number of +corresponding, listed, definition. + +See [*§ 4.5.19 The `sub` and `sup` elements*][html-sup], +[*§ 4.5.1 The `a` element*][html-a], and +[*§ 3.2.6.6 Embedding custom non-visible data with the `data-*` +attributes*][html-data] +in the HTML spec, and +[*§ 6.8 `aria-describedby` property*][aria-describedby] +in WAI-ARIA, for more info. + +When one or more definitions are referenced, a footnote section is generated at +the end of the document, using `
`, `

`, and `
    ` elements: + +```html +

    Footnotes

    +
      …
    +
    +``` + +Each definition is generated as a `
  1. ` in the `
      ` in the order they were +first referenced: + +```html +
    1. …
    2. +``` + +Backreferences are injected at the end of the first paragraph, or, when there +is no paragraph, at the end of the definition. +When a definition is referenced multiple times, multiple backreferences are +generated. +Further backreferences use an extra counter in the `href` attribute and +visually in a `` after `↩`. + +```html +↩ ↩2 +``` + +See +[*§ 4.5.1 The `a` element*][html-a], +[*§ 4.3.6 The `h1`, `h2`, `h3`, `h4`, `h5`, and `h6` elements*][html-h], +[*§ 4.4.8 The `li` element*][html-li], +[*§ 4.4.5 The `ol` element*][html-ol], +[*§ 4.4.1 The `p` element*][html-p], +[*§ 4.3.3 The `section` element*][html-section], and +[*§ 4.5.19 The `sub` and `sup` elements*][html-sup] +in the HTML spec, and +[*§ 6.8 `aria-label` property*][aria-label] +in WAI-ARIA, for more info. + +## CSS + +The following CSS is needed to make footnotes look a bit like GitHub (and fixes +a bug). +For the complete actual CSS see +[`sindresorhus/github-markdown-css`](https://github.com/sindresorhus/github-markdown-css). + +```css +/* Style the footnotes section. */ +.footnotes { + font-size: smaller; + color: #8b949e; + border-top: 1px solid #30363d; +} + +/* Hide the section label for visual users. */ +.sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + overflow: hidden; + clip: rect(0, 0, 0, 0); + word-wrap: normal; + border: 0; +} + +/* Place `[` and `]` around footnote references. */ +[data-footnote-ref]::before { + content: '['; +} + +[data-footnote-ref]::after { + content: ']'; +} +``` + +## Syntax + +Footnotes form with, roughly, the following BNF: + +```bnf +gfm_footnote_reference ::= gfm_footnote_label + +gfm_footnote_definition_start ::= gfm_footnote_label ':' *space_or_tab +; Restriction: blank line allowed. +gfm_footnote_definition_cont ::= 4(space_or_tab) + +; Restriction: maximum `999` codes between `^` and `]`. +gfm_footnote_label ::= '[' '^' 1*(gfm_footnote_label_byte | gfm_footnote_label_escape) ']' +gfm_footnote_label_byte ::= text - '[' - '\\' - ']' +gfm_footnote_label_escape ::= '\\' ['[' | '\\' | ']'] + +; Any byte (u8) +byte ::= 0x00..=0xFFFF +space_or_tab ::= '\t' | ' ' +eol ::= '\n' | '\r' | '\r\n' +line ::= byte - eol +text ::= line - space_or_tab +``` + +Further lines after `gfm_footnote_definition_start` that are not prefixed with +`gfm_footnote_definition_cont` cause the footnote definition to be exited, +except when those lines are lazy continuation or blank. +Like so many things in markdown, footnote definition too are complex. +See [*§ Phase 1: block structure* in `CommonMark`][commonmark-block] for more +on parsing details. + +The identifiers in the `label` parts are interpreted as the +[string][micromark-content-types] content type. +That means that character escapes and character references are allowed. + +Definitions match to references through identifiers. +To match, both labels must be equal after normalizing with +[`normalizeIdentifier`][micromark-normalize-identifier]. +One definition can match to multiple calls. +Multiple definitions with the same, normalized, identifier are ignored: the +first definition is preferred. +To illustrate, the definition with the content of `x` wins: + +```markdown +[^a]: x +[^a]: y + +[^a] +``` + +Importantly, while labels *can* include [string][micromark-content-types] +content (character escapes and character references), these are not considered +when matching. +To illustrate, neither definition matches the reference: + +```markdown +[^a&b]: x +[^a\&b]: y + +[^a&b] +``` + +Because footnote definitions are containers (like block quotes and list items), +they can contain more footnote definitions. +They can even include references to themselves. + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional types [`BackLabelTemplate`][api-back-label-template] +and [`HtmlOptions`][api-html-options]. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`micromark-extension-gfm-footnote@^2`, compatible with Node.js 16. + +This package works with `micromark` version `3` and later. + +## Security + +This package is safe. +Setting `clobberPrefix = ''` is dangerous, it opens you up to DOM clobbering. +The `labelTagName` and `labelAttributes` options are unsafe when used with user +content, they allow defining arbitrary HTML. + +## Related + +* [`micromark-extension-gfm`][micromark-extension-gfm] + — support all of GFM +* [`mdast-util-gfm-footnote`][mdast-util-gfm-footnote] + — support all of GFM in mdast +* [`mdast-util-gfm`][mdast-util-gfm] + — support all of GFM in mdast +* [`remark-gfm`][remark-gfm] + — support all of GFM in remark + +## Contribute + +See [`contributing.md` in `micromark/.github`][contributing] for ways to get +started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/micromark/micromark-extension-gfm-footnote/workflows/main/badge.svg + +[build]: https://github.com/micromark/micromark-extension-gfm-footnote/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm-footnote.svg + +[coverage]: https://codecov.io/github/micromark/micromark-extension-gfm-footnote + +[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm-footnote.svg + +[downloads]: https://www.npmjs.com/package/micromark-extension-gfm-footnote + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-gfm-footnote + +[size]: https://bundlejs.com/?q=micromark-extension-gfm-footnote + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/micromark/micromark/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esmsh]: https://esm.sh + +[license]: license + +[author]: https://wooorm.com + +[contributing]: https://github.com/micromark/.github/blob/main/contributing.md + +[support]: https://github.com/micromark/.github/blob/main/support.md + +[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[typescript]: https://www.typescriptlang.org + +[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions + +[micromark]: https://github.com/micromark/micromark + +[micromark-content-types]: https://github.com/micromark/micromark#content-types + +[micromark-extension]: https://github.com/micromark/micromark#syntaxextension + +[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension + +[micromark-normalize-identifier]: https://github.com/micromark/micromark/tree/main/packages/micromark-util-normalize-identifier + +[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm + +[mdast-util-gfm-footnote]: https://github.com/syntax-tree/mdast-util-gfm-footnote + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[post]: https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/ + +[cmark-gfm]: https://github.com/github/cmark-gfm + +[commonmark-block]: https://spec.commonmark.org/0.30/#phase-1-block-structure + +[html-a]: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-a-element + +[html-data]: https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes + +[html-h]: https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements + +[html-li]: https://html.spec.whatwg.org/multipage/grouping-content.html#the-li-element + +[html-ol]: https://html.spec.whatwg.org/multipage/grouping-content.html#the-ol-element + +[html-p]: https://html.spec.whatwg.org/multipage/grouping-content.html#the-p-element + +[html-section]: https://html.spec.whatwg.org/multipage/sections.html#the-section-element + +[html-sup]: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-sub-and-sup-elements + +[aria-describedby]: https://w3c.github.io/aria/#aria-describedby + +[aria-label]: https://w3c.github.io/aria/#aria-label + +[api-gfm-footnote]: #gfmfootnote + +[api-gfm-footnote-html]: #gfmfootnotehtmloptions + +[api-html-options]: #htmloptions + +[api-default-back-label]: #defaultbacklabelreferenceindex-rereferenceindex + +[api-back-label-template]: #backlabeltemplate diff --git a/node_modules/micromark-extension-gfm-strikethrough/dev/index.d.ts b/node_modules/micromark-extension-gfm-strikethrough/dev/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..037dac3cae287508c6865d427f7b30353b727842 --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/dev/index.d.ts @@ -0,0 +1,30 @@ +export {gfmStrikethroughHtml} from './lib/html.js' +export {gfmStrikethrough} from './lib/syntax.js' + +/** + * Configuration (optional). + */ +export interface Options { + /** + * Whether to support strikethrough with a single tilde (default: `true`). + * + * Single tildes work on github.com, but are technically prohibited by the + * GFM spec. + */ + singleTilde?: boolean | null | undefined +} + +/** + * Augment. + */ +declare module 'micromark-util-types' { + /** + * Token types. + */ + interface TokenTypeMap { + strikethroughSequence: 'strikethroughSequence' + strikethroughSequenceTemporary: 'strikethroughSequenceTemporary' + strikethrough: 'strikethrough' + strikethroughText: 'strikethroughText' + } +} diff --git a/node_modules/micromark-extension-gfm-strikethrough/dev/index.js b/node_modules/micromark-extension-gfm-strikethrough/dev/index.js new file mode 100644 index 0000000000000000000000000000000000000000..127b78300b9b44edfab9fa7b9003f6ee9b6ba4e4 --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/dev/index.js @@ -0,0 +1,3 @@ +// Note: more types exposed from `index.d.ts`. +export {gfmStrikethroughHtml} from './lib/html.js' +export {gfmStrikethrough} from './lib/syntax.js' diff --git a/node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.d.ts b/node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..aa15edf69ac437816bfed0f4a5b7be931a957255 --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.d.ts @@ -0,0 +1,13 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ +/** + * Create an HTML extension for `micromark` to support GFM strikethrough when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions`, to + * support GFM strikethrough when serializing to HTML. + */ +export function gfmStrikethroughHtml(): HtmlExtension; +import type { HtmlExtension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.js b/node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..bfbf44da9bb5982ec21b8690b0cc91cdee44cb3c --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/dev/lib/html.js @@ -0,0 +1,26 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ + +/** + * Create an HTML extension for `micromark` to support GFM strikethrough when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions`, to + * support GFM strikethrough when serializing to HTML. + */ +export function gfmStrikethroughHtml() { + return { + enter: { + strikethrough() { + this.tag('') + } + }, + exit: { + strikethrough() { + this.tag('') + } + } + } +} diff --git a/node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8bfb44bad312272ce86d7c8bd06a58dac1f60d8f --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.d.ts @@ -0,0 +1,12 @@ +/** + * Create an extension for `micromark` to enable GFM strikethrough syntax. + * + * @param {Options | null | undefined} [options={}] + * Configuration. + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions`, to + * enable GFM strikethrough syntax. + */ +export function gfmStrikethrough(options?: Options | null | undefined): Extension; +import type { Options } from 'micromark-extension-gfm-strikethrough'; +import type { Extension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.js b/node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..dc4c18723c7beb47e819280f698c6718fdaaa15e --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/dev/lib/syntax.js @@ -0,0 +1,183 @@ +/** + * @import {Options} from 'micromark-extension-gfm-strikethrough' + * @import {Event, Extension, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {splice} from 'micromark-util-chunked' +import {classifyCharacter} from 'micromark-util-classify-character' +import {resolveAll} from 'micromark-util-resolve-all' +import {codes, constants, types} from 'micromark-util-symbol' + +/** + * Create an extension for `micromark` to enable GFM strikethrough syntax. + * + * @param {Options | null | undefined} [options={}] + * Configuration. + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions`, to + * enable GFM strikethrough syntax. + */ +export function gfmStrikethrough(options) { + const options_ = options || {} + let single = options_.singleTilde + const tokenizer = { + name: 'strikethrough', + tokenize: tokenizeStrikethrough, + resolveAll: resolveAllStrikethrough + } + + if (single === null || single === undefined) { + single = true + } + + return { + text: {[codes.tilde]: tokenizer}, + insideSpan: {null: [tokenizer]}, + attentionMarkers: {null: [codes.tilde]} + } + + /** + * Take events and resolve strikethrough. + * + * @type {Resolver} + */ + function resolveAllStrikethrough(events, context) { + let index = -1 + + // Walk through all events. + while (++index < events.length) { + // Find a token that can close. + if ( + events[index][0] === 'enter' && + events[index][1].type === 'strikethroughSequenceTemporary' && + events[index][1]._close + ) { + let open = index + + // Now walk back to find an opener. + while (open--) { + // Find a token that can open the closer. + if ( + events[open][0] === 'exit' && + events[open][1].type === 'strikethroughSequenceTemporary' && + events[open][1]._open && + // If the sizes are the same: + events[index][1].end.offset - events[index][1].start.offset === + events[open][1].end.offset - events[open][1].start.offset + ) { + events[index][1].type = 'strikethroughSequence' + events[open][1].type = 'strikethroughSequence' + + /** @type {Token} */ + const strikethrough = { + type: 'strikethrough', + start: Object.assign({}, events[open][1].start), + end: Object.assign({}, events[index][1].end) + } + + /** @type {Token} */ + const text = { + type: 'strikethroughText', + start: Object.assign({}, events[open][1].end), + end: Object.assign({}, events[index][1].start) + } + + // Opening. + /** @type {Array} */ + const nextEvents = [ + ['enter', strikethrough, context], + ['enter', events[open][1], context], + ['exit', events[open][1], context], + ['enter', text, context] + ] + + const insideSpan = context.parser.constructs.insideSpan.null + + if (insideSpan) { + // Between. + splice( + nextEvents, + nextEvents.length, + 0, + resolveAll(insideSpan, events.slice(open + 1, index), context) + ) + } + + // Closing. + splice(nextEvents, nextEvents.length, 0, [ + ['exit', text, context], + ['enter', events[index][1], context], + ['exit', events[index][1], context], + ['exit', strikethrough, context] + ]) + + splice(events, open - 1, index - open + 3, nextEvents) + + index = open + nextEvents.length - 2 + break + } + } + } + } + + index = -1 + + while (++index < events.length) { + if (events[index][1].type === 'strikethroughSequenceTemporary') { + events[index][1].type = types.data + } + } + + return events + } + + /** + * @this {TokenizeContext} + * @type {Tokenizer} + */ + function tokenizeStrikethrough(effects, ok, nok) { + const previous = this.previous + const events = this.events + let size = 0 + + return start + + /** @type {State} */ + function start(code) { + assert(code === codes.tilde, 'expected `~`') + + if ( + previous === codes.tilde && + events[events.length - 1][1].type !== types.characterEscape + ) { + return nok(code) + } + + effects.enter('strikethroughSequenceTemporary') + return more(code) + } + + /** @type {State} */ + function more(code) { + const before = classifyCharacter(previous) + + if (code === codes.tilde) { + // If this is the third marker, exit. + if (size > 1) return nok(code) + effects.consume(code) + size++ + return more + } + + if (size < 2 && !single) return nok(code) + const token = effects.exit('strikethroughSequenceTemporary') + const after = classifyCharacter(code) + token._open = + !after || (after === constants.attentionSideAfter && Boolean(before)) + token._close = + !before || (before === constants.attentionSideAfter && Boolean(after)) + return ok(code) + } + } +} diff --git a/node_modules/micromark-extension-gfm-strikethrough/index.d.ts b/node_modules/micromark-extension-gfm-strikethrough/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..50a0b7e5f6ef27ed02a887f86832aa1d66021621 --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/index.d.ts @@ -0,0 +1,24 @@ +export {gfmStrikethroughHtml} from './lib/html.js' +export {gfmStrikethrough} from './lib/syntax.js' + +/** + * Configuration (optional). + */ +export interface Options { + /** + * Whether to support strikethrough with a single tilde (default: `true`). + * + * Single tildes work on github.com, but are technically prohibited by the + * GFM spec. + */ + singleTilde?: boolean | null | undefined +} + +declare module 'micromark-util-types' { + interface TokenTypeMap { + strikethroughSequence: 'strikethroughSequence' + strikethroughSequenceTemporary: 'strikethroughSequenceTemporary' + strikethrough: 'strikethrough' + strikethroughText: 'strikethroughText' + } +} diff --git a/node_modules/micromark-extension-gfm-strikethrough/index.js b/node_modules/micromark-extension-gfm-strikethrough/index.js new file mode 100644 index 0000000000000000000000000000000000000000..da7cbe225887ca47dff43aea11519132d2f1acd2 --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/index.js @@ -0,0 +1,3 @@ +// Note: more types exposed from `index.d.ts`. +export { gfmStrikethroughHtml } from './lib/html.js'; +export { gfmStrikethrough } from './lib/syntax.js'; \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-strikethrough/lib/html.d.ts b/node_modules/micromark-extension-gfm-strikethrough/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..aa15edf69ac437816bfed0f4a5b7be931a957255 --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/lib/html.d.ts @@ -0,0 +1,13 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ +/** + * Create an HTML extension for `micromark` to support GFM strikethrough when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions`, to + * support GFM strikethrough when serializing to HTML. + */ +export function gfmStrikethroughHtml(): HtmlExtension; +import type { HtmlExtension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-strikethrough/lib/html.js b/node_modules/micromark-extension-gfm-strikethrough/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..fa8ef76c207f3e7544d16e6cbdcbcfa988feaf3e --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/lib/html.js @@ -0,0 +1,26 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ + +/** + * Create an HTML extension for `micromark` to support GFM strikethrough when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions`, to + * support GFM strikethrough when serializing to HTML. + */ +export function gfmStrikethroughHtml() { + return { + enter: { + strikethrough() { + this.tag(''); + } + }, + exit: { + strikethrough() { + this.tag(''); + } + } + }; +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8bfb44bad312272ce86d7c8bd06a58dac1f60d8f --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.d.ts @@ -0,0 +1,12 @@ +/** + * Create an extension for `micromark` to enable GFM strikethrough syntax. + * + * @param {Options | null | undefined} [options={}] + * Configuration. + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions`, to + * enable GFM strikethrough syntax. + */ +export function gfmStrikethrough(options?: Options | null | undefined): Extension; +import type { Options } from 'micromark-extension-gfm-strikethrough'; +import type { Extension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js b/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..715d5ba4cc0af432ddf7b7ad006398668cdce9ba --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/lib/syntax.js @@ -0,0 +1,142 @@ +/** + * @import {Options} from 'micromark-extension-gfm-strikethrough' + * @import {Event, Extension, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +import { splice } from 'micromark-util-chunked'; +import { classifyCharacter } from 'micromark-util-classify-character'; +import { resolveAll } from 'micromark-util-resolve-all'; +/** + * Create an extension for `micromark` to enable GFM strikethrough syntax. + * + * @param {Options | null | undefined} [options={}] + * Configuration. + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions`, to + * enable GFM strikethrough syntax. + */ +export function gfmStrikethrough(options) { + const options_ = options || {}; + let single = options_.singleTilde; + const tokenizer = { + name: 'strikethrough', + tokenize: tokenizeStrikethrough, + resolveAll: resolveAllStrikethrough + }; + if (single === null || single === undefined) { + single = true; + } + return { + text: { + [126]: tokenizer + }, + insideSpan: { + null: [tokenizer] + }, + attentionMarkers: { + null: [126] + } + }; + + /** + * Take events and resolve strikethrough. + * + * @type {Resolver} + */ + function resolveAllStrikethrough(events, context) { + let index = -1; + + // Walk through all events. + while (++index < events.length) { + // Find a token that can close. + if (events[index][0] === 'enter' && events[index][1].type === 'strikethroughSequenceTemporary' && events[index][1]._close) { + let open = index; + + // Now walk back to find an opener. + while (open--) { + // Find a token that can open the closer. + if (events[open][0] === 'exit' && events[open][1].type === 'strikethroughSequenceTemporary' && events[open][1]._open && + // If the sizes are the same: + events[index][1].end.offset - events[index][1].start.offset === events[open][1].end.offset - events[open][1].start.offset) { + events[index][1].type = 'strikethroughSequence'; + events[open][1].type = 'strikethroughSequence'; + + /** @type {Token} */ + const strikethrough = { + type: 'strikethrough', + start: Object.assign({}, events[open][1].start), + end: Object.assign({}, events[index][1].end) + }; + + /** @type {Token} */ + const text = { + type: 'strikethroughText', + start: Object.assign({}, events[open][1].end), + end: Object.assign({}, events[index][1].start) + }; + + // Opening. + /** @type {Array} */ + const nextEvents = [['enter', strikethrough, context], ['enter', events[open][1], context], ['exit', events[open][1], context], ['enter', text, context]]; + const insideSpan = context.parser.constructs.insideSpan.null; + if (insideSpan) { + // Between. + splice(nextEvents, nextEvents.length, 0, resolveAll(insideSpan, events.slice(open + 1, index), context)); + } + + // Closing. + splice(nextEvents, nextEvents.length, 0, [['exit', text, context], ['enter', events[index][1], context], ['exit', events[index][1], context], ['exit', strikethrough, context]]); + splice(events, open - 1, index - open + 3, nextEvents); + index = open + nextEvents.length - 2; + break; + } + } + } + } + index = -1; + while (++index < events.length) { + if (events[index][1].type === 'strikethroughSequenceTemporary') { + events[index][1].type = "data"; + } + } + return events; + } + + /** + * @this {TokenizeContext} + * @type {Tokenizer} + */ + function tokenizeStrikethrough(effects, ok, nok) { + const previous = this.previous; + const events = this.events; + let size = 0; + return start; + + /** @type {State} */ + function start(code) { + if (previous === 126 && events[events.length - 1][1].type !== "characterEscape") { + return nok(code); + } + effects.enter('strikethroughSequenceTemporary'); + return more(code); + } + + /** @type {State} */ + function more(code) { + const before = classifyCharacter(previous); + if (code === 126) { + // If this is the third marker, exit. + if (size > 1) return nok(code); + effects.consume(code); + size++; + return more; + } + if (size < 2 && !single) return nok(code); + const token = effects.exit('strikethroughSequenceTemporary'); + const after = classifyCharacter(code); + token._open = !after || after === 2 && Boolean(before); + token._close = !before || before === 2 && Boolean(after); + return ok(code); + } + } +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-strikethrough/license b/node_modules/micromark-extension-gfm-strikethrough/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark-extension-gfm-strikethrough/package.json b/node_modules/micromark-extension-gfm-strikethrough/package.json new file mode 100644 index 0000000000000000000000000000000000000000..31b7cd8392d60add7df4ed8afa15d61071798573 --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/package.json @@ -0,0 +1,129 @@ +{ + "name": "micromark-extension-gfm-strikethrough", + "version": "2.1.0", + "description": "micromark extension to support GFM strikethrough", + "license": "MIT", + "keywords": [ + "micromark", + "micromark-extension", + "strikethrough", + "strike", + "through", + "del", + "delete", + "deletion", + "gfm", + "markdown", + "unified" + ], + "repository": "micromark/micromark-extension-gfm-strikethrough", + "bugs": "https://github.com/micromark/micromark-extension-gfm-strikethrough/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "files": [ + "dev/", + "lib/", + "index.d.ts", + "index.js" + ], + "exports": { + "development": "./dev/index.js", + "default": "./index.js" + }, + "dependencies": { + "devlop": "^1.0.0", + "micromark-util-chunked": "^2.0.0", + "micromark-util-classify-character": "^2.0.0", + "micromark-util-resolve-all": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^10.0.0", + "create-gfm-fixtures": "^1.0.0", + "micromark": "^4.0.0", + "micromark-build": "^2.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "tape": "^5.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.58.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage && micromark-build", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", + "test-api-prod": "node --conditions production test/index.js", + "test-api-dev": "node --conditions development test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "prettier": true, + "rules": { + "logical-assignment-operators": "off", + "max-depth": "off", + "unicorn/prefer-at": "off" + }, + "overrides": [ + { + "files": "**/*.ts", + "rules": { + "@typescript-eslint/array-type": [ + "error", + { + "default": "generic" + } + ], + "@typescript-eslint/ban-types": [ + "error", + { + "extendDefaults": true + } + ], + "@typescript-eslint/consistent-type-definitions": [ + "error", + "interface" + ] + } + }, + { + "files": "test/**/*.js", + "rules": { + "no-await-in-loop": 0 + } + } + ] + } +} diff --git a/node_modules/micromark-extension-gfm-strikethrough/readme.md b/node_modules/micromark-extension-gfm-strikethrough/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..e2c18d38c97a0603d27687be228cd07bfb6aeaa0 --- /dev/null +++ b/node_modules/micromark-extension-gfm-strikethrough/readme.md @@ -0,0 +1,304 @@ +# micromark-extension-gfm-strikethrough + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[micromark][] extensions to support GFM [strikethrough][]. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmStrikethrough(options?)`](#gfmstrikethroughoptions) + * [`gfmStrikethroughHtml()`](#gfmstrikethroughhtml) + * [`Options`](#options) +* [Authoring](#authoring) +* [HTML](#html) +* [CSS](#css) +* [Syntax](#syntax) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains extensions that add support for strikethrough as enabled +by GFM to [`micromark`][micromark]. + +## When to use this + +This project is useful when you want to support strikethrough in markdown. + +You can use these extensions when you are working with [`micromark`][micromark]. +To support all GFM features, use +[`micromark-extension-gfm`][micromark-extension-gfm]. + +When you need a syntax tree, you can combine this package with +[`mdast-util-gfm-strikethrough`][mdast-util-gfm-strikethrough]. + +All these packages are used [`remark-gfm`][remark-gfm], which focusses on making +it easier to transform content by abstracting these internals away. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install micromark-extension-gfm-strikethrough +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmStrikethrough, gfmStrikethroughHtml} from 'https://esm.sh/micromark-extension-gfm-strikethrough@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +```js +import {micromark} from 'micromark' +import { + gfmStrikethrough, + gfmStrikethroughHtml +} from 'micromark-extension-gfm-strikethrough' + +const output = micromark('Some ~strikethrough~.', { + extensions: [gfmStrikethrough()], + htmlExtensions: [gfmStrikethroughHtml()] +}) + +console.log(output) +``` + +Yields: + +```html +

      Some strikethrough

      . +``` + +## API + +This package exports the identifiers +[`gfmStrikethrough`][api-gfm-strikethrough] and +[`gfmStrikethroughHtml`][api-gfm-strikethrough-html]. +There is no default export. + +The export map supports the [`development` condition][development]. +Run `node --conditions development module.js` to get instrumented dev code. +Without this condition, production code is loaded. + +### `gfmStrikethrough(options?)` + +Create an extension for `micromark` to enable GFM strikethrough syntax. + +###### Parameters + +* `options` ([`Options`][api-options], optional) + — configuration + +###### Returns + +Extension for `micromark` that can be passed in `extensions`, to +enable GFM strikethrough syntax ([`Extension`][micromark-extension]). + +### `gfmStrikethroughHtml()` + +Create an HTML extension for `micromark` to support GFM strikethrough when +serializing to HTML. + +###### Returns + +Extension for `micromark` that can be passed in `htmlExtensions`, to support +GFM strikethrough when serializing to HTML +([`HtmlExtension`][micromark-html-extension]). + +### `Options` + +Configuration (TypeScript type). + +###### Fields + +* `singleTilde` (`boolean`, default: `true`) + — whether to support strikethrough with a single tilde. + Single tildes work on github.com, but are technically prohibited by the GFM + spec + +## Authoring + +When authoring markdown with strikethrough, it is recommended to use two +markers. +While `github.com` allows single tildes too, it technically prohibits it in +their spec. + +## HTML + +When tilde sequences match, they together relate to the `` element in +HTML. +See [*§ 4.7.2 The `del` element*][html-del] in the HTML spec for more info. + +## CSS + +GitHub itself does not apply interesting CSS to `del` elements. +It currently (July 2022) does change `code` in `del`. + +```css +del code { + text-decoration: inherit; +} +``` + +For the complete actual CSS see +[`sindresorhus/github-markdown-css`][github-markdown-css]. + +## Syntax + +Strikethrough sequences form with the following BNF: + +```bnf +gfm_attention_sequence ::= 1*'~' +``` + +Sequences are matched together to form strikethrough based on which character +they contain, how long they are, and what character occurs before and after +each sequence. +Otherwise they are turned into data. + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional type [`Options`][api-options]. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`micromark-extension-gfm-strikethrough@^2`, compatible with Node.js 16. + +This package works with `micromark` version `3` and later. + +## Security + +This package is safe. + +## Related + +* [`micromark-extension-gfm`][micromark-extension-gfm] + — support all of GFM +* [`mdast-util-gfm-strikethrough`][mdast-util-gfm-strikethrough] + — support all of GFM in mdast +* [`mdast-util-gfm`][mdast-util-gfm] + — support all of GFM in mdast +* [`remark-gfm`][remark-gfm] + — support all of GFM in remark + +## Contribute + +See [`contributing.md` in `micromark/.github`][contributing] for ways to get +started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/micromark/micromark-extension-gfm-strikethrough/workflows/main/badge.svg + +[build]: https://github.com/micromark/micromark-extension-gfm-strikethrough/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm-strikethrough.svg + +[coverage]: https://codecov.io/github/micromark/micromark-extension-gfm-strikethrough + +[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm-strikethrough.svg + +[downloads]: https://www.npmjs.com/package/micromark-extension-gfm-strikethrough + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-gfm-strikethrough + +[size]: https://bundlejs.com/?q=micromark-extension-gfm-strikethrough + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/micromark/micromark/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esmsh]: https://esm.sh + +[license]: license + +[author]: https://wooorm.com + +[contributing]: https://github.com/micromark/.github/blob/main/contributing.md + +[support]: https://github.com/micromark/.github/blob/main/support.md + +[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[typescript]: https://www.typescriptlang.org + +[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions + +[micromark]: https://github.com/micromark/micromark + +[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension + +[micromark-extension]: https://github.com/micromark/micromark#syntaxextension + +[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm + +[mdast-util-gfm-strikethrough]: https://github.com/syntax-tree/mdast-util-gfm-strikethrough + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[strikethrough]: https://github.github.com/gfm/#strikethrough-extension- + +[github-markdown-css]: https://github.com/sindresorhus/github-markdown-css + +[html-del]: https://html.spec.whatwg.org/multipage/edits.html#the-del-element + +[api-gfm-strikethrough]: #gfmstrikethroughoptions + +[api-gfm-strikethrough-html]: #gfmstrikethroughhtml + +[api-options]: #options diff --git a/node_modules/micromark-extension-gfm-table/dev/index.d.ts b/node_modules/micromark-extension-gfm-table/dev/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..be1a117c5c3383d1f194c56950bf7bcc32ad0652 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/index.d.ts @@ -0,0 +1,55 @@ +import type {Align} from './lib/infer.js' + +export {gfmTableHtml} from './lib/html.js' +export {gfmTable} from './lib/syntax.js' + +/** + * Augment types. + */ +declare module 'micromark-util-types' { + /** + * State tracked to compile events as HTML, + * extended by `micromark-extension-gfm-table`. + */ + interface CompileData { + /** + * Alignment of current table. + */ + tableAlign?: Array | undefined + /** + * Current table column. + */ + tableColumn?: number | undefined + } + + /** + * Augment token; + * `align` is patched on `table` tokens by + * `micromark-extension-gfm-table`. + */ + interface Token { + /** + * Alignment of current table. + */ + _align?: Array | undefined + } + + /** + * Map of allowed token types, + * extended by `micromark-extension-gfm-table`. + */ + interface TokenTypeMap { + tableBody: 'tableBody' + tableCellDivider: 'tableCellDivider' + tableContent: 'tableContent' + tableData: 'tableData' + tableDelimiterFiller: 'tableDelimiterFiller' + tableDelimiterMarker: 'tableDelimiterMarker' + tableDelimiterRow: 'tableDelimiterRow' + tableDelimiter: 'tableDelimiter' + tableHeader: 'tableHeader' + tableHead: 'tableHead' + tableRow: 'tableRow' + table: 'table' + } +} diff --git a/node_modules/micromark-extension-gfm-table/dev/index.js b/node_modules/micromark-extension-gfm-table/dev/index.js new file mode 100644 index 0000000000000000000000000000000000000000..dcb556083f1c3ae04f1c6612ca99f96138230d24 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/index.js @@ -0,0 +1,2 @@ +export {gfmTableHtml} from './lib/html.js' +export {gfmTable} from './lib/syntax.js' diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.d.ts b/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..02da6f3ec111888fc55dc5e4e6ac71878d3cf44d --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.d.ts @@ -0,0 +1,38 @@ +/** + * @import {Event} from 'micromark-util-types' + */ +/** + * @typedef {[number, number, Array]} Change + * @typedef {[number, number, number]} Jump + */ +/** + * Tracks a bunch of edits. + */ +export class EditMap { + /** + * Record of changes. + * + * @type {Array} + */ + map: Array; + /** + * Create an edit: a remove and/or add at a certain place. + * + * @param {number} index + * @param {number} remove + * @param {Array} add + * @returns {undefined} + */ + add(index: number, remove: number, add: Array): undefined; + /** + * Done, change the events. + * + * @param {Array} events + * @returns {undefined} + */ + consume(events: Array): undefined; +} +export type Change = [number, number, Array]; +export type Jump = [number, number, number]; +import type { Event } from 'micromark-util-types'; +//# sourceMappingURL=edit-map.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.d.ts.map b/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b522a04952b1d63ebc817b1fa37639ae76619536 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"edit-map.d.ts","sourceRoot":"","sources":["edit-map.js"],"names":[],"mappings":"AAAA;;GAEG;AAeH;;;GAGG;AAEH;;GAEG;AACH;IAKI;;;;OAIG;IACH,KAFU,KAAK,CAAC,MAAM,CAAC,CAEV;IAGf;;;;;;;OAOG;IACH,WALW,MAAM,UACN,MAAM,OACN,KAAK,CAAC,KAAK,CAAC,GACV,SAAS,CAIrB;IAeD;;;;;OAKG;IACH,gBAHW,KAAK,CAAC,KAAK,CAAC,GACV,SAAS,CA2DrB;CACF;qBA7GY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;mBAC9B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;2BAlBb,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.js b/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.js new file mode 100644 index 0000000000000000000000000000000000000000..983d0556e2713dc92982faa6a09b1093ef4d02db --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/edit-map.js @@ -0,0 +1,212 @@ +/** + * @import {Event} from 'micromark-util-types' + */ + +// Port of `edit_map.rs` from `markdown-rs`. +// This should move to `markdown-js` later. + +// Deal with several changes in events, batching them together. +// +// Preferably, changes should be kept to a minimum. +// Sometimes, it’s needed to change the list of events, because parsing can be +// messy, and it helps to expose a cleaner interface of events to the compiler +// and other users. +// It can also help to merge many adjacent similar events. +// And, in other cases, it’s needed to parse subcontent: pass some events +// through another tokenizer and inject the result. + +/** + * @typedef {[number, number, Array]} Change + * @typedef {[number, number, number]} Jump + */ + +/** + * Tracks a bunch of edits. + */ +export class EditMap { + /** + * Create a new edit map. + */ + constructor() { + /** + * Record of changes. + * + * @type {Array} + */ + this.map = [] + } + + /** + * Create an edit: a remove and/or add at a certain place. + * + * @param {number} index + * @param {number} remove + * @param {Array} add + * @returns {undefined} + */ + add(index, remove, add) { + addImplementation(this, index, remove, add) + } + + // To do: add this when moving to `micromark`. + // /** + // * Create an edit: but insert `add` before existing additions. + // * + // * @param {number} index + // * @param {number} remove + // * @param {Array} add + // * @returns {undefined} + // */ + // addBefore(index, remove, add) { + // addImplementation(this, index, remove, add, true) + // } + + /** + * Done, change the events. + * + * @param {Array} events + * @returns {undefined} + */ + consume(events) { + this.map.sort(function (a, b) { + return a[0] - b[0] + }) + + /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */ + if (this.map.length === 0) { + return + } + + // To do: if links are added in events, like they are in `markdown-rs`, + // this is needed. + // // Calculate jumps: where items in the current list move to. + // /** @type {Array} */ + // const jumps = [] + // let index = 0 + // let addAcc = 0 + // let removeAcc = 0 + // while (index < this.map.length) { + // const [at, remove, add] = this.map[index] + // removeAcc += remove + // addAcc += add.length + // jumps.push([at, removeAcc, addAcc]) + // index += 1 + // } + // + // . shiftLinks(events, jumps) + + let index = this.map.length + /** @type {Array>} */ + const vecs = [] + while (index > 0) { + index -= 1 + vecs.push( + events.slice(this.map[index][0] + this.map[index][1]), + this.map[index][2] + ) + + // Truncate rest. + events.length = this.map[index][0] + } + + vecs.push(events.slice()) + events.length = 0 + + let slice = vecs.pop() + + while (slice) { + for (const element of slice) { + events.push(element) + } + + slice = vecs.pop() + } + + // Truncate everything. + this.map.length = 0 + } +} + +/** + * Create an edit. + * + * @param {EditMap} editMap + * @param {number} at + * @param {number} remove + * @param {Array} add + * @returns {undefined} + */ +function addImplementation(editMap, at, remove, add) { + let index = 0 + + /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */ + if (remove === 0 && add.length === 0) { + return + } + + while (index < editMap.map.length) { + if (editMap.map[index][0] === at) { + editMap.map[index][1] += remove + + // To do: before not used by tables, use when moving to micromark. + // if (before) { + // add.push(...editMap.map[index][2]) + // editMap.map[index][2] = add + // } else { + editMap.map[index][2].push(...add) + // } + + return + } + + index += 1 + } + + editMap.map.push([at, remove, add]) +} + +// /** +// * Shift `previous` and `next` links according to `jumps`. +// * +// * This fixes links in case there are events removed or added between them. +// * +// * @param {Array} events +// * @param {Array} jumps +// */ +// function shiftLinks(events, jumps) { +// let jumpIndex = 0 +// let index = 0 +// let add = 0 +// let rm = 0 + +// while (index < events.length) { +// const rmCurr = rm + +// while (jumpIndex < jumps.length && jumps[jumpIndex][0] <= index) { +// add = jumps[jumpIndex][2] +// rm = jumps[jumpIndex][1] +// jumpIndex += 1 +// } + +// // Ignore items that will be removed. +// if (rm > rmCurr) { +// index += rm - rmCurr +// } else { +// // ? +// // if let Some(link) = &events[index].link { +// // if let Some(next) = link.next { +// // events[next].link.as_mut().unwrap().previous = Some(index + add - rm); +// // while jumpIndex < jumps.len() && jumps[jumpIndex].0 <= next { +// // add = jumps[jumpIndex].2; +// // rm = jumps[jumpIndex].1; +// // jumpIndex += 1; +// // } +// // events[index].link.as_mut().unwrap().next = Some(next + add - rm); +// // index = next; +// // continue; +// // } +// // } +// index += 1 +// } +// } +// } diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/html.d.ts b/node_modules/micromark-extension-gfm-table/dev/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8e4d6696020cd66e121e9cd87f2811e44146da75 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/html.d.ts @@ -0,0 +1,11 @@ +/** + * Create an HTML extension for `micromark` to support GitHub tables when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GitHub tables when serializing to HTML. + */ +export function gfmTableHtml(): HtmlExtension; +import type { HtmlExtension } from 'micromark-util-types'; +//# sourceMappingURL=html.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/html.d.ts.map b/node_modules/micromark-extension-gfm-table/dev/lib/html.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..102bdf290ca0c6151bc963fdd563675da9c72df9 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/html.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["html.js"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,gCAJa,aAAa,CAsHzB;mCAxI+B,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/html.js b/node_modules/micromark-extension-gfm-table/dev/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..8397d72ffa37e5e9ee8f94204446d43ae111a478 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/html.js @@ -0,0 +1,148 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' + +const alignment = { + none: '', + left: ' align="left"', + right: ' align="right"', + center: ' align="center"' +} + +// To do: micromark@5: use `infer` here, when all events are exposed. + +/** + * Create an HTML extension for `micromark` to support GitHub tables when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GitHub tables when serializing to HTML. + */ +export function gfmTableHtml() { + return { + enter: { + table(token) { + const tableAlign = token._align + assert(tableAlign, 'expected `_align`') + this.lineEndingIfNeeded() + this.tag('') + this.setData('tableAlign', tableAlign) + }, + tableBody() { + this.tag('') + }, + tableData() { + const tableAlign = this.getData('tableAlign') + const tableColumn = this.getData('tableColumn') + assert(tableAlign, 'expected `tableAlign`') + assert(typeof tableColumn === 'number', 'expected `tableColumn`') + const align = alignment[tableAlign[tableColumn]] + + if (align === undefined) { + // Capture results to ignore them. + this.buffer() + } else { + this.lineEndingIfNeeded() + this.tag('') + } + }, + tableHead() { + this.lineEndingIfNeeded() + this.tag('') + }, + tableHeader() { + const tableAlign = this.getData('tableAlign') + const tableColumn = this.getData('tableColumn') + assert(tableAlign, 'expected `tableAlign`') + assert(typeof tableColumn === 'number', 'expected `tableColumn`') + const align = alignment[tableAlign[tableColumn]] + this.lineEndingIfNeeded() + this.tag('') + }, + tableRow() { + this.setData('tableColumn', 0) + this.lineEndingIfNeeded() + this.tag('') + } + }, + exit: { + // Overwrite the default code text data handler to unescape escaped pipes when + // they are in tables. + codeTextData(token) { + let value = this.sliceSerialize(token) + + if (this.getData('tableAlign')) { + value = value.replace(/\\([\\|])/g, replace) + } + + this.raw(this.encode(value)) + }, + table() { + this.setData('tableAlign') + // Note: we don’t set `slurpAllLineEndings` anymore, in delimiter rows, + // but we do need to reset it to match a funky newline GH generates for + // list items combined with tables. + this.setData('slurpAllLineEndings') + this.lineEndingIfNeeded() + this.tag('
      ') + }, + tableBody() { + this.lineEndingIfNeeded() + this.tag('') + }, + tableData() { + const tableAlign = this.getData('tableAlign') + const tableColumn = this.getData('tableColumn') + assert(tableAlign, 'expected `tableAlign`') + assert(typeof tableColumn === 'number', 'expected `tableColumn`') + + if (tableColumn in tableAlign) { + this.tag('') + this.setData('tableColumn', tableColumn + 1) + } else { + // Stop capturing. + this.resume() + } + }, + tableHead() { + this.lineEndingIfNeeded() + this.tag('') + }, + tableHeader() { + const tableColumn = this.getData('tableColumn') + assert(typeof tableColumn === 'number', 'expected `tableColumn`') + this.tag('') + this.setData('tableColumn', tableColumn + 1) + }, + tableRow() { + const tableAlign = this.getData('tableAlign') + let tableColumn = this.getData('tableColumn') + assert(tableAlign, 'expected `tableAlign`') + assert(typeof tableColumn === 'number', 'expected `tableColumn`') + + while (tableColumn < tableAlign.length) { + this.lineEndingIfNeeded() + this.tag('') + tableColumn++ + } + + this.setData('tableColumn', tableColumn) + this.lineEndingIfNeeded() + this.tag('') + } + } + } +} + +/** + * @param {string} $0 + * @param {string} $1 + * @returns {string} + */ +function replace($0, $1) { + // Pipes work, backslashes don’t (but can’t escape pipes). + return $1 === '|' ? $1 : $0 +} diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/infer.d.ts b/node_modules/micromark-extension-gfm-table/dev/lib/infer.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e55881efdde461efa55bea7c47ad9893dc864b20 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/infer.d.ts @@ -0,0 +1,14 @@ +/** + * Figure out the alignment of a GFM table. + * + * @param {Readonly>} events + * List of events. + * @param {number} index + * Table enter event. + * @returns {Array} + * List of aligns. + */ +export function gfmTableAlign(events: Readonly>, index: number): Array; +export type Align = "center" | "left" | "none" | "right"; +import type { Event } from 'micromark-util-types'; +//# sourceMappingURL=infer.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/infer.d.ts.map b/node_modules/micromark-extension-gfm-table/dev/lib/infer.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..c5b12c1ade8d3a0cbb44389f567a3002068b19dc --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/infer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"infer.d.ts","sourceRoot":"","sources":["infer.js"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,sCAPW,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,SAEtB,MAAM,GAEJ,KAAK,CAAC,KAAK,CAAC,CA8CxB;oBA1DY,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;2BAJzB,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/infer.js b/node_modules/micromark-extension-gfm-table/dev/lib/infer.js new file mode 100644 index 0000000000000000000000000000000000000000..9a6ecf02ca4e006915ef1a2087e75576e5e9ba2e --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/infer.js @@ -0,0 +1,64 @@ +/** + * @import {Event} from 'micromark-util-types' + */ + +/** + * @typedef {'center' | 'left' | 'none' | 'right'} Align + */ + +import {ok as assert} from 'devlop' + +/** + * Figure out the alignment of a GFM table. + * + * @param {Readonly>} events + * List of events. + * @param {number} index + * Table enter event. + * @returns {Array} + * List of aligns. + */ +export function gfmTableAlign(events, index) { + assert(events[index][1].type === 'table', 'expected table') + let inDelimiterRow = false + /** @type {Array} */ + const align = [] + + while (index < events.length) { + const event = events[index] + + if (inDelimiterRow) { + if (event[0] === 'enter') { + // Start of alignment value: set a new column. + // To do: `markdown-rs` uses `tableDelimiterCellValue`. + if (event[1].type === 'tableContent') { + align.push( + events[index + 1][1].type === 'tableDelimiterMarker' + ? 'left' + : 'none' + ) + } + } + // Exits: + // End of alignment value: change the column. + // To do: `markdown-rs` uses `tableDelimiterCellValue`. + else if (event[1].type === 'tableContent') { + if (events[index - 1][1].type === 'tableDelimiterMarker') { + const alignIndex = align.length - 1 + + align[alignIndex] = align[alignIndex] === 'left' ? 'center' : 'right' + } + } + // Done! + else if (event[1].type === 'tableDelimiterRow') { + break + } + } else if (event[0] === 'enter' && event[1].type === 'tableDelimiterRow') { + inDelimiterRow = true + } + + index += 1 + } + + return align +} diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-table/dev/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ecac018a28abeb8490d4e9df56c659b2aa93fcec --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/syntax.d.ts @@ -0,0 +1,18 @@ +/** + * Create an HTML extension for `micromark` to support GitHub tables syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * table syntax. + */ +export function gfmTable(): Extension; +/** + * Cell info. + */ +export type Range = [number, number, number, number]; +/** + * Where we are: `1` for head row, `2` for delimiter row, `3` for body row. + */ +export type RowKind = 0 | 1 | 2 | 3; +import type { Extension } from 'micromark-util-types'; +//# sourceMappingURL=syntax.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/syntax.d.ts.map b/node_modules/micromark-extension-gfm-table/dev/lib/syntax.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..01eedacae562189b56aa95f1925da210f999cfa9 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/syntax.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["syntax.js"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,4BAJa,SAAS,CAUrB;;;;oBA/BY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;;;;sBAGhC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;+BAPoE,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/dev/lib/syntax.js b/node_modules/micromark-extension-gfm-table/dev/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..71693081622ef30d536e339eb11147488b067fdd --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/dev/lib/syntax.js @@ -0,0 +1,941 @@ +/** + * @import {Event, Extension, Point, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +/** + * @typedef {[number, number, number, number]} Range + * Cell info. + * + * @typedef {0 | 1 | 2 | 3} RowKind + * Where we are: `1` for head row, `2` for delimiter row, `3` for body row. + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import { + markdownLineEnding, + markdownLineEndingOrSpace, + markdownSpace +} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' +import {EditMap} from './edit-map.js' +import {gfmTableAlign} from './infer.js' + +/** + * Create an HTML extension for `micromark` to support GitHub tables syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * table syntax. + */ +export function gfmTable() { + return { + flow: { + null: {name: 'table', tokenize: tokenizeTable, resolveAll: resolveTable} + } + } +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeTable(effects, ok, nok) { + const self = this + let size = 0 + let sizeB = 0 + /** @type {boolean | undefined} */ + let seen + + return start + + /** + * Start of a GFM table. + * + * If there is a valid table row or table head before, then we try to parse + * another row. + * Otherwise, we try to parse a head. + * + * ```markdown + * > | | a | + * ^ + * | | - | + * > | | b | + * ^ + * ``` + * @type {State} + */ + function start(code) { + let index = self.events.length - 1 + + while (index > -1) { + const type = self.events[index][1].type + if ( + type === types.lineEnding || + // Note: markdown-rs uses `whitespace` instead of `linePrefix` + type === types.linePrefix + ) + index-- + else break + } + + const tail = index > -1 ? self.events[index][1].type : null + + const next = + tail === 'tableHead' || tail === 'tableRow' ? bodyRowStart : headRowBefore + + // Don’t allow lazy body rows. + if (next === bodyRowStart && self.parser.lazy[self.now().line]) { + return nok(code) + } + + return next(code) + } + + /** + * Before table head row. + * + * ```markdown + * > | | a | + * ^ + * | | - | + * | | b | + * ``` + * + * @type {State} + */ + function headRowBefore(code) { + effects.enter('tableHead') + effects.enter('tableRow') + return headRowStart(code) + } + + /** + * Before table head row, after whitespace. + * + * ```markdown + * > | | a | + * ^ + * | | - | + * | | b | + * ``` + * + * @type {State} + */ + function headRowStart(code) { + if (code === codes.verticalBar) { + return headRowBreak(code) + } + + // To do: micromark-js should let us parse our own whitespace in extensions, + // like `markdown-rs`: + // + // ```js + // // 4+ spaces. + // if (markdownSpace(code)) { + // return nok(code) + // } + // ``` + + seen = true + // Count the first character, that isn’t a pipe, double. + sizeB += 1 + return headRowBreak(code) + } + + /** + * At break in table head row. + * + * ```markdown + * > | | a | + * ^ + * ^ + * ^ + * | | - | + * | | b | + * ``` + * + * @type {State} + */ + function headRowBreak(code) { + if (code === codes.eof) { + // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t. + return nok(code) + } + + if (markdownLineEnding(code)) { + // If anything other than one pipe (ignoring whitespace) was used, it’s fine. + if (sizeB > 1) { + sizeB = 0 + // To do: check if this works. + // Feel free to interrupt: + self.interrupt = true + effects.exit('tableRow') + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return headDelimiterStart + } + + // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t. + return nok(code) + } + + if (markdownSpace(code)) { + // To do: check if this is fine. + // effects.attempt(State::Next(StateName::GfmTableHeadRowBreak), State::Nok) + // State::Retry(space_or_tab(tokenizer)) + return factorySpace(effects, headRowBreak, types.whitespace)(code) + } + + sizeB += 1 + + if (seen) { + seen = false + // Header cell count. + size += 1 + } + + if (code === codes.verticalBar) { + effects.enter('tableCellDivider') + effects.consume(code) + effects.exit('tableCellDivider') + // Whether a delimiter was seen. + seen = true + return headRowBreak + } + + // Anything else is cell data. + effects.enter(types.data) + return headRowData(code) + } + + /** + * In table head row data. + * + * ```markdown + * > | | a | + * ^ + * | | - | + * | | b | + * ``` + * + * @type {State} + */ + function headRowData(code) { + if ( + code === codes.eof || + code === codes.verticalBar || + markdownLineEndingOrSpace(code) + ) { + effects.exit(types.data) + return headRowBreak(code) + } + + effects.consume(code) + return code === codes.backslash ? headRowEscape : headRowData + } + + /** + * In table head row escape. + * + * ```markdown + * > | | a\-b | + * ^ + * | | ---- | + * | | c | + * ``` + * + * @type {State} + */ + function headRowEscape(code) { + if (code === codes.backslash || code === codes.verticalBar) { + effects.consume(code) + return headRowData + } + + return headRowData(code) + } + + /** + * Before delimiter row. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * | | b | + * ``` + * + * @type {State} + */ + function headDelimiterStart(code) { + // Reset `interrupt`. + self.interrupt = false + + // Note: in `markdown-rs`, we need to handle piercing here too. + if (self.parser.lazy[self.now().line]) { + return nok(code) + } + + effects.enter('tableDelimiterRow') + // Track if we’ve seen a `:` or `|`. + seen = false + + if (markdownSpace(code)) { + assert(self.parser.constructs.disable.null, 'expected `disabled.null`') + return factorySpace( + effects, + headDelimiterBefore, + types.linePrefix, + self.parser.constructs.disable.null.includes('codeIndented') + ? undefined + : constants.tabSize + )(code) + } + + return headDelimiterBefore(code) + } + + /** + * Before delimiter row, after optional whitespace. + * + * Reused when a `|` is found later, to parse another cell. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * | | b | + * ``` + * + * @type {State} + */ + function headDelimiterBefore(code) { + if (code === codes.dash || code === codes.colon) { + return headDelimiterValueBefore(code) + } + + if (code === codes.verticalBar) { + seen = true + // If we start with a pipe, we open a cell marker. + effects.enter('tableCellDivider') + effects.consume(code) + effects.exit('tableCellDivider') + return headDelimiterCellBefore + } + + // More whitespace / empty row not allowed at start. + return headDelimiterNok(code) + } + + /** + * After `|`, before delimiter cell. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterCellBefore(code) { + if (markdownSpace(code)) { + return factorySpace( + effects, + headDelimiterValueBefore, + types.whitespace + )(code) + } + + return headDelimiterValueBefore(code) + } + + /** + * Before delimiter cell value. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterValueBefore(code) { + // Align: left. + if (code === codes.colon) { + sizeB += 1 + seen = true + + effects.enter('tableDelimiterMarker') + effects.consume(code) + effects.exit('tableDelimiterMarker') + return headDelimiterLeftAlignmentAfter + } + + // Align: none. + if (code === codes.dash) { + sizeB += 1 + // To do: seems weird that this *isn’t* left aligned, but that state is used? + return headDelimiterLeftAlignmentAfter(code) + } + + if (code === codes.eof || markdownLineEnding(code)) { + return headDelimiterCellAfter(code) + } + + return headDelimiterNok(code) + } + + /** + * After delimiter cell left alignment marker. + * + * ```markdown + * | | a | + * > | | :- | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterLeftAlignmentAfter(code) { + if (code === codes.dash) { + effects.enter('tableDelimiterFiller') + return headDelimiterFiller(code) + } + + // Anything else is not ok after the left-align colon. + return headDelimiterNok(code) + } + + /** + * In delimiter cell filler. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterFiller(code) { + if (code === codes.dash) { + effects.consume(code) + return headDelimiterFiller + } + + // Align is `center` if it was `left`, `right` otherwise. + if (code === codes.colon) { + seen = true + effects.exit('tableDelimiterFiller') + effects.enter('tableDelimiterMarker') + effects.consume(code) + effects.exit('tableDelimiterMarker') + return headDelimiterRightAlignmentAfter + } + + effects.exit('tableDelimiterFiller') + return headDelimiterRightAlignmentAfter(code) + } + + /** + * After delimiter cell right alignment marker. + * + * ```markdown + * | | a | + * > | | -: | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterRightAlignmentAfter(code) { + if (markdownSpace(code)) { + return factorySpace( + effects, + headDelimiterCellAfter, + types.whitespace + )(code) + } + + return headDelimiterCellAfter(code) + } + + /** + * After delimiter cell. + * + * ```markdown + * | | a | + * > | | -: | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterCellAfter(code) { + if (code === codes.verticalBar) { + return headDelimiterBefore(code) + } + + if (code === codes.eof || markdownLineEnding(code)) { + // Exit when: + // * there was no `:` or `|` at all (it’s a thematic break or setext + // underline instead) + // * the header cell count is not the delimiter cell count + if (!seen || size !== sizeB) { + return headDelimiterNok(code) + } + + // Note: in markdown-rs`, a reset is needed here. + effects.exit('tableDelimiterRow') + effects.exit('tableHead') + // To do: in `markdown-rs`, resolvers need to be registered manually. + // effects.register_resolver(ResolveName::GfmTable) + return ok(code) + } + + return headDelimiterNok(code) + } + + /** + * In delimiter row, at a disallowed byte. + * + * ```markdown + * | | a | + * > | | x | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterNok(code) { + // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t. + return nok(code) + } + + /** + * Before table body row. + * + * ```markdown + * | | a | + * | | - | + * > | | b | + * ^ + * ``` + * + * @type {State} + */ + function bodyRowStart(code) { + // Note: in `markdown-rs` we need to manually take care of a prefix, + // but in `micromark-js` that is done for us, so if we’re here, we’re + // never at whitespace. + effects.enter('tableRow') + return bodyRowBreak(code) + } + + /** + * At break in table body row. + * + * ```markdown + * | | a | + * | | - | + * > | | b | + * ^ + * ^ + * ^ + * ``` + * + * @type {State} + */ + function bodyRowBreak(code) { + if (code === codes.verticalBar) { + effects.enter('tableCellDivider') + effects.consume(code) + effects.exit('tableCellDivider') + return bodyRowBreak + } + + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit('tableRow') + return ok(code) + } + + if (markdownSpace(code)) { + return factorySpace(effects, bodyRowBreak, types.whitespace)(code) + } + + // Anything else is cell content. + effects.enter(types.data) + return bodyRowData(code) + } + + /** + * In table body row data. + * + * ```markdown + * | | a | + * | | - | + * > | | b | + * ^ + * ``` + * + * @type {State} + */ + function bodyRowData(code) { + if ( + code === codes.eof || + code === codes.verticalBar || + markdownLineEndingOrSpace(code) + ) { + effects.exit(types.data) + return bodyRowBreak(code) + } + + effects.consume(code) + return code === codes.backslash ? bodyRowEscape : bodyRowData + } + + /** + * In table body row escape. + * + * ```markdown + * | | a | + * | | ---- | + * > | | b\-c | + * ^ + * ``` + * + * @type {State} + */ + function bodyRowEscape(code) { + if (code === codes.backslash || code === codes.verticalBar) { + effects.consume(code) + return bodyRowData + } + + return bodyRowData(code) + } +} + +/** @type {Resolver} */ + +function resolveTable(events, context) { + let index = -1 + let inFirstCellAwaitingPipe = true + /** @type {RowKind} */ + let rowKind = 0 + /** @type {Range} */ + let lastCell = [0, 0, 0, 0] + /** @type {Range} */ + let cell = [0, 0, 0, 0] + let afterHeadAwaitingFirstBodyRow = false + let lastTableEnd = 0 + /** @type {Token | undefined} */ + let currentTable + /** @type {Token | undefined} */ + let currentBody + /** @type {Token | undefined} */ + let currentCell + + const map = new EditMap() + + while (++index < events.length) { + const event = events[index] + const token = event[1] + + if (event[0] === 'enter') { + // Start of head. + if (token.type === 'tableHead') { + afterHeadAwaitingFirstBodyRow = false + + // Inject previous (body end and) table end. + if (lastTableEnd !== 0) { + assert(currentTable, 'there should be a table opening') + flushTableEnd(map, context, lastTableEnd, currentTable, currentBody) + currentBody = undefined + lastTableEnd = 0 + } + + // Inject table start. + currentTable = { + type: 'table', + start: Object.assign({}, token.start), + // Note: correct end is set later. + end: Object.assign({}, token.end) + } + map.add(index, 0, [['enter', currentTable, context]]) + } else if ( + token.type === 'tableRow' || + token.type === 'tableDelimiterRow' + ) { + inFirstCellAwaitingPipe = true + currentCell = undefined + lastCell = [0, 0, 0, 0] + cell = [0, index + 1, 0, 0] + + // Inject table body start. + if (afterHeadAwaitingFirstBodyRow) { + afterHeadAwaitingFirstBodyRow = false + currentBody = { + type: 'tableBody', + start: Object.assign({}, token.start), + // Note: correct end is set later. + end: Object.assign({}, token.end) + } + map.add(index, 0, [['enter', currentBody, context]]) + } + + rowKind = token.type === 'tableDelimiterRow' ? 2 : currentBody ? 3 : 1 + } + // Cell data. + else if ( + rowKind && + (token.type === types.data || + token.type === 'tableDelimiterMarker' || + token.type === 'tableDelimiterFiller') + ) { + inFirstCellAwaitingPipe = false + + // First value in cell. + if (cell[2] === 0) { + if (lastCell[1] !== 0) { + cell[0] = cell[1] + currentCell = flushCell( + map, + context, + lastCell, + rowKind, + undefined, + currentCell + ) + lastCell = [0, 0, 0, 0] + } + + cell[2] = index + } + } else if (token.type === 'tableCellDivider') { + if (inFirstCellAwaitingPipe) { + inFirstCellAwaitingPipe = false + } else { + if (lastCell[1] !== 0) { + cell[0] = cell[1] + currentCell = flushCell( + map, + context, + lastCell, + rowKind, + undefined, + currentCell + ) + } + + lastCell = cell + cell = [lastCell[1], index, 0, 0] + } + } + } + // Exit events. + else if (token.type === 'tableHead') { + afterHeadAwaitingFirstBodyRow = true + lastTableEnd = index + } else if ( + token.type === 'tableRow' || + token.type === 'tableDelimiterRow' + ) { + lastTableEnd = index + + if (lastCell[1] !== 0) { + cell[0] = cell[1] + currentCell = flushCell( + map, + context, + lastCell, + rowKind, + index, + currentCell + ) + } else if (cell[1] !== 0) { + currentCell = flushCell(map, context, cell, rowKind, index, currentCell) + } + + rowKind = 0 + } else if ( + rowKind && + (token.type === types.data || + token.type === 'tableDelimiterMarker' || + token.type === 'tableDelimiterFiller') + ) { + cell[3] = index + } + } + + if (lastTableEnd !== 0) { + assert(currentTable, 'expected table opening') + flushTableEnd(map, context, lastTableEnd, currentTable, currentBody) + } + + map.consume(context.events) + + // To do: move this into `html`, when events are exposed there. + // That’s what `markdown-rs` does. + // That needs updates to `mdast-util-gfm-table`. + index = -1 + while (++index < context.events.length) { + const event = context.events[index] + if (event[0] === 'enter' && event[1].type === 'table') { + event[1]._align = gfmTableAlign(context.events, index) + } + } + + return events +} + +/** + * Generate a cell. + * + * @param {EditMap} map + * @param {Readonly} context + * @param {Readonly} range + * @param {RowKind} rowKind + * @param {number | undefined} rowEnd + * @param {Token | undefined} previousCell + * @returns {Token | undefined} + */ +// eslint-disable-next-line max-params +function flushCell(map, context, range, rowKind, rowEnd, previousCell) { + // `markdown-rs` uses: + // rowKind === 2 ? 'tableDelimiterCell' : 'tableCell' + const groupName = + rowKind === 1 + ? 'tableHeader' + : rowKind === 2 + ? 'tableDelimiter' + : 'tableData' + // `markdown-rs` uses: + // rowKind === 2 ? 'tableDelimiterCellValue' : 'tableCellText' + const valueName = 'tableContent' + + // Insert an exit for the previous cell, if there is one. + // + // ```markdown + // > | | aa | bb | cc | + // ^-- exit + // ^^^^-- this cell + // ``` + if (range[0] !== 0) { + assert(previousCell, 'expected previous cell enter') + previousCell.end = Object.assign({}, getPoint(context.events, range[0])) + map.add(range[0], 0, [['exit', previousCell, context]]) + } + + // Insert enter of this cell. + // + // ```markdown + // > | | aa | bb | cc | + // ^-- enter + // ^^^^-- this cell + // ``` + const now = getPoint(context.events, range[1]) + previousCell = { + type: groupName, + start: Object.assign({}, now), + // Note: correct end is set later. + end: Object.assign({}, now) + } + map.add(range[1], 0, [['enter', previousCell, context]]) + + // Insert text start at first data start and end at last data end, and + // remove events between. + // + // ```markdown + // > | | aa | bb | cc | + // ^-- enter + // ^-- exit + // ^^^^-- this cell + // ``` + if (range[2] !== 0) { + const relatedStart = getPoint(context.events, range[2]) + const relatedEnd = getPoint(context.events, range[3]) + /** @type {Token} */ + const valueToken = { + type: valueName, + start: Object.assign({}, relatedStart), + end: Object.assign({}, relatedEnd) + } + map.add(range[2], 0, [['enter', valueToken, context]]) + assert(range[3] !== 0) + + if (rowKind !== 2) { + // Fix positional info on remaining events + const start = context.events[range[2]] + const end = context.events[range[3]] + start[1].end = Object.assign({}, end[1].end) + start[1].type = types.chunkText + start[1].contentType = constants.contentTypeText + + // Remove if needed. + if (range[3] > range[2] + 1) { + const a = range[2] + 1 + const b = range[3] - range[2] - 1 + map.add(a, b, []) + } + } + + map.add(range[3] + 1, 0, [['exit', valueToken, context]]) + } + + // Insert an exit for the last cell, if at the row end. + // + // ```markdown + // > | | aa | bb | cc | + // ^-- exit + // ^^^^^^-- this cell (the last one contains two “between” parts) + // ``` + if (rowEnd !== undefined) { + previousCell.end = Object.assign({}, getPoint(context.events, rowEnd)) + map.add(rowEnd, 0, [['exit', previousCell, context]]) + previousCell = undefined + } + + return previousCell +} + +/** + * Generate table end (and table body end). + * + * @param {Readonly} map + * @param {Readonly} context + * @param {number} index + * @param {Token} table + * @param {Token | undefined} tableBody + */ +// eslint-disable-next-line max-params +function flushTableEnd(map, context, index, table, tableBody) { + /** @type {Array} */ + const exits = [] + const related = getPoint(context.events, index) + + if (tableBody) { + tableBody.end = Object.assign({}, related) + exits.push(['exit', tableBody, context]) + } + + table.end = Object.assign({}, related) + exits.push(['exit', table, context]) + + map.add(index + 1, 0, exits) +} + +/** + * @param {Readonly>} events + * @param {number} index + * @returns {Readonly} + */ +function getPoint(events, index) { + const event = events[index] + const side = event[0] === 'enter' ? 'start' : 'end' + return event[1][side] +} diff --git a/node_modules/micromark-extension-gfm-table/index.d.ts b/node_modules/micromark-extension-gfm-table/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..be1a117c5c3383d1f194c56950bf7bcc32ad0652 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/index.d.ts @@ -0,0 +1,55 @@ +import type {Align} from './lib/infer.js' + +export {gfmTableHtml} from './lib/html.js' +export {gfmTable} from './lib/syntax.js' + +/** + * Augment types. + */ +declare module 'micromark-util-types' { + /** + * State tracked to compile events as HTML, + * extended by `micromark-extension-gfm-table`. + */ + interface CompileData { + /** + * Alignment of current table. + */ + tableAlign?: Array | undefined + /** + * Current table column. + */ + tableColumn?: number | undefined + } + + /** + * Augment token; + * `align` is patched on `table` tokens by + * `micromark-extension-gfm-table`. + */ + interface Token { + /** + * Alignment of current table. + */ + _align?: Array | undefined + } + + /** + * Map of allowed token types, + * extended by `micromark-extension-gfm-table`. + */ + interface TokenTypeMap { + tableBody: 'tableBody' + tableCellDivider: 'tableCellDivider' + tableContent: 'tableContent' + tableData: 'tableData' + tableDelimiterFiller: 'tableDelimiterFiller' + tableDelimiterMarker: 'tableDelimiterMarker' + tableDelimiterRow: 'tableDelimiterRow' + tableDelimiter: 'tableDelimiter' + tableHeader: 'tableHeader' + tableHead: 'tableHead' + tableRow: 'tableRow' + table: 'table' + } +} diff --git a/node_modules/micromark-extension-gfm-table/index.js b/node_modules/micromark-extension-gfm-table/index.js new file mode 100644 index 0000000000000000000000000000000000000000..8f9afc67d3937d2bd808e29721f1209ae1ae0885 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/index.js @@ -0,0 +1,2 @@ +export { gfmTableHtml } from './lib/html.js'; +export { gfmTable } from './lib/syntax.js'; \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/edit-map.d.ts b/node_modules/micromark-extension-gfm-table/lib/edit-map.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..02da6f3ec111888fc55dc5e4e6ac71878d3cf44d --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/edit-map.d.ts @@ -0,0 +1,38 @@ +/** + * @import {Event} from 'micromark-util-types' + */ +/** + * @typedef {[number, number, Array]} Change + * @typedef {[number, number, number]} Jump + */ +/** + * Tracks a bunch of edits. + */ +export class EditMap { + /** + * Record of changes. + * + * @type {Array} + */ + map: Array; + /** + * Create an edit: a remove and/or add at a certain place. + * + * @param {number} index + * @param {number} remove + * @param {Array} add + * @returns {undefined} + */ + add(index: number, remove: number, add: Array): undefined; + /** + * Done, change the events. + * + * @param {Array} events + * @returns {undefined} + */ + consume(events: Array): undefined; +} +export type Change = [number, number, Array]; +export type Jump = [number, number, number]; +import type { Event } from 'micromark-util-types'; +//# sourceMappingURL=edit-map.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/edit-map.d.ts.map b/node_modules/micromark-extension-gfm-table/lib/edit-map.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b522a04952b1d63ebc817b1fa37639ae76619536 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/edit-map.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"edit-map.d.ts","sourceRoot":"","sources":["edit-map.js"],"names":[],"mappings":"AAAA;;GAEG;AAeH;;;GAGG;AAEH;;GAEG;AACH;IAKI;;;;OAIG;IACH,KAFU,KAAK,CAAC,MAAM,CAAC,CAEV;IAGf;;;;;;;OAOG;IACH,WALW,MAAM,UACN,MAAM,OACN,KAAK,CAAC,KAAK,CAAC,GACV,SAAS,CAIrB;IAeD;;;;;OAKG;IACH,gBAHW,KAAK,CAAC,KAAK,CAAC,GACV,SAAS,CA2DrB;CACF;qBA7GY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;mBAC9B,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;2BAlBb,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/edit-map.js b/node_modules/micromark-extension-gfm-table/lib/edit-map.js new file mode 100644 index 0000000000000000000000000000000000000000..ecc8bce784d29a48e0869be1c4a2dd5ccf1d3d01 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/edit-map.js @@ -0,0 +1,202 @@ +/** + * @import {Event} from 'micromark-util-types' + */ + +// Port of `edit_map.rs` from `markdown-rs`. +// This should move to `markdown-js` later. + +// Deal with several changes in events, batching them together. +// +// Preferably, changes should be kept to a minimum. +// Sometimes, it’s needed to change the list of events, because parsing can be +// messy, and it helps to expose a cleaner interface of events to the compiler +// and other users. +// It can also help to merge many adjacent similar events. +// And, in other cases, it’s needed to parse subcontent: pass some events +// through another tokenizer and inject the result. + +/** + * @typedef {[number, number, Array]} Change + * @typedef {[number, number, number]} Jump + */ + +/** + * Tracks a bunch of edits. + */ +export class EditMap { + /** + * Create a new edit map. + */ + constructor() { + /** + * Record of changes. + * + * @type {Array} + */ + this.map = []; + } + + /** + * Create an edit: a remove and/or add at a certain place. + * + * @param {number} index + * @param {number} remove + * @param {Array} add + * @returns {undefined} + */ + add(index, remove, add) { + addImplementation(this, index, remove, add); + } + + // To do: add this when moving to `micromark`. + // /** + // * Create an edit: but insert `add` before existing additions. + // * + // * @param {number} index + // * @param {number} remove + // * @param {Array} add + // * @returns {undefined} + // */ + // addBefore(index, remove, add) { + // addImplementation(this, index, remove, add, true) + // } + + /** + * Done, change the events. + * + * @param {Array} events + * @returns {undefined} + */ + consume(events) { + this.map.sort(function (a, b) { + return a[0] - b[0]; + }); + + /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */ + if (this.map.length === 0) { + return; + } + + // To do: if links are added in events, like they are in `markdown-rs`, + // this is needed. + // // Calculate jumps: where items in the current list move to. + // /** @type {Array} */ + // const jumps = [] + // let index = 0 + // let addAcc = 0 + // let removeAcc = 0 + // while (index < this.map.length) { + // const [at, remove, add] = this.map[index] + // removeAcc += remove + // addAcc += add.length + // jumps.push([at, removeAcc, addAcc]) + // index += 1 + // } + // + // . shiftLinks(events, jumps) + + let index = this.map.length; + /** @type {Array>} */ + const vecs = []; + while (index > 0) { + index -= 1; + vecs.push(events.slice(this.map[index][0] + this.map[index][1]), this.map[index][2]); + + // Truncate rest. + events.length = this.map[index][0]; + } + vecs.push(events.slice()); + events.length = 0; + let slice = vecs.pop(); + while (slice) { + for (const element of slice) { + events.push(element); + } + slice = vecs.pop(); + } + + // Truncate everything. + this.map.length = 0; + } +} + +/** + * Create an edit. + * + * @param {EditMap} editMap + * @param {number} at + * @param {number} remove + * @param {Array} add + * @returns {undefined} + */ +function addImplementation(editMap, at, remove, add) { + let index = 0; + + /* c8 ignore next 3 -- `resolve` is never called without tables, so without edits. */ + if (remove === 0 && add.length === 0) { + return; + } + while (index < editMap.map.length) { + if (editMap.map[index][0] === at) { + editMap.map[index][1] += remove; + + // To do: before not used by tables, use when moving to micromark. + // if (before) { + // add.push(...editMap.map[index][2]) + // editMap.map[index][2] = add + // } else { + editMap.map[index][2].push(...add); + // } + + return; + } + index += 1; + } + editMap.map.push([at, remove, add]); +} + +// /** +// * Shift `previous` and `next` links according to `jumps`. +// * +// * This fixes links in case there are events removed or added between them. +// * +// * @param {Array} events +// * @param {Array} jumps +// */ +// function shiftLinks(events, jumps) { +// let jumpIndex = 0 +// let index = 0 +// let add = 0 +// let rm = 0 + +// while (index < events.length) { +// const rmCurr = rm + +// while (jumpIndex < jumps.length && jumps[jumpIndex][0] <= index) { +// add = jumps[jumpIndex][2] +// rm = jumps[jumpIndex][1] +// jumpIndex += 1 +// } + +// // Ignore items that will be removed. +// if (rm > rmCurr) { +// index += rm - rmCurr +// } else { +// // ? +// // if let Some(link) = &events[index].link { +// // if let Some(next) = link.next { +// // events[next].link.as_mut().unwrap().previous = Some(index + add - rm); +// // while jumpIndex < jumps.len() && jumps[jumpIndex].0 <= next { +// // add = jumps[jumpIndex].2; +// // rm = jumps[jumpIndex].1; +// // jumpIndex += 1; +// // } +// // events[index].link.as_mut().unwrap().next = Some(next + add - rm); +// // index = next; +// // continue; +// // } +// // } +// index += 1 +// } +// } +// } \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/html.d.ts b/node_modules/micromark-extension-gfm-table/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8e4d6696020cd66e121e9cd87f2811e44146da75 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/html.d.ts @@ -0,0 +1,11 @@ +/** + * Create an HTML extension for `micromark` to support GitHub tables when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GitHub tables when serializing to HTML. + */ +export function gfmTableHtml(): HtmlExtension; +import type { HtmlExtension } from 'micromark-util-types'; +//# sourceMappingURL=html.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/html.d.ts.map b/node_modules/micromark-extension-gfm-table/lib/html.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..102bdf290ca0c6151bc963fdd563675da9c72df9 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/html.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["html.js"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,gCAJa,aAAa,CAsHzB;mCAxI+B,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/html.js b/node_modules/micromark-extension-gfm-table/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..5c944a8f7bd7cc7de37d72469ed19f645c9bdbda --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/html.js @@ -0,0 +1,130 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ + +const alignment = { + none: '', + left: ' align="left"', + right: ' align="right"', + center: ' align="center"' +}; + +// To do: micromark@5: use `infer` here, when all events are exposed. + +/** + * Create an HTML extension for `micromark` to support GitHub tables when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GitHub tables when serializing to HTML. + */ +export function gfmTableHtml() { + return { + enter: { + table(token) { + const tableAlign = token._align; + this.lineEndingIfNeeded(); + this.tag(''); + this.setData('tableAlign', tableAlign); + }, + tableBody() { + this.tag(''); + }, + tableData() { + const tableAlign = this.getData('tableAlign'); + const tableColumn = this.getData('tableColumn'); + const align = alignment[tableAlign[tableColumn]]; + if (align === undefined) { + // Capture results to ignore them. + this.buffer(); + } else { + this.lineEndingIfNeeded(); + this.tag(''); + } + }, + tableHead() { + this.lineEndingIfNeeded(); + this.tag(''); + }, + tableHeader() { + const tableAlign = this.getData('tableAlign'); + const tableColumn = this.getData('tableColumn'); + const align = alignment[tableAlign[tableColumn]]; + this.lineEndingIfNeeded(); + this.tag(''); + }, + tableRow() { + this.setData('tableColumn', 0); + this.lineEndingIfNeeded(); + this.tag(''); + } + }, + exit: { + // Overwrite the default code text data handler to unescape escaped pipes when + // they are in tables. + codeTextData(token) { + let value = this.sliceSerialize(token); + if (this.getData('tableAlign')) { + value = value.replace(/\\([\\|])/g, replace); + } + this.raw(this.encode(value)); + }, + table() { + this.setData('tableAlign'); + // Note: we don’t set `slurpAllLineEndings` anymore, in delimiter rows, + // but we do need to reset it to match a funky newline GH generates for + // list items combined with tables. + this.setData('slurpAllLineEndings'); + this.lineEndingIfNeeded(); + this.tag('
      '); + }, + tableBody() { + this.lineEndingIfNeeded(); + this.tag(''); + }, + tableData() { + const tableAlign = this.getData('tableAlign'); + const tableColumn = this.getData('tableColumn'); + if (tableColumn in tableAlign) { + this.tag(''); + this.setData('tableColumn', tableColumn + 1); + } else { + // Stop capturing. + this.resume(); + } + }, + tableHead() { + this.lineEndingIfNeeded(); + this.tag(''); + }, + tableHeader() { + const tableColumn = this.getData('tableColumn'); + this.tag(''); + this.setData('tableColumn', tableColumn + 1); + }, + tableRow() { + const tableAlign = this.getData('tableAlign'); + let tableColumn = this.getData('tableColumn'); + while (tableColumn < tableAlign.length) { + this.lineEndingIfNeeded(); + this.tag(''); + tableColumn++; + } + this.setData('tableColumn', tableColumn); + this.lineEndingIfNeeded(); + this.tag(''); + } + } + }; +} + +/** + * @param {string} $0 + * @param {string} $1 + * @returns {string} + */ +function replace($0, $1) { + // Pipes work, backslashes don’t (but can’t escape pipes). + return $1 === '|' ? $1 : $0; +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/infer.d.ts b/node_modules/micromark-extension-gfm-table/lib/infer.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..e55881efdde461efa55bea7c47ad9893dc864b20 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/infer.d.ts @@ -0,0 +1,14 @@ +/** + * Figure out the alignment of a GFM table. + * + * @param {Readonly>} events + * List of events. + * @param {number} index + * Table enter event. + * @returns {Array} + * List of aligns. + */ +export function gfmTableAlign(events: Readonly>, index: number): Array; +export type Align = "center" | "left" | "none" | "right"; +import type { Event } from 'micromark-util-types'; +//# sourceMappingURL=infer.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/infer.d.ts.map b/node_modules/micromark-extension-gfm-table/lib/infer.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..c5b12c1ade8d3a0cbb44389f567a3002068b19dc --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/infer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"infer.d.ts","sourceRoot":"","sources":["infer.js"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,sCAPW,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,SAEtB,MAAM,GAEJ,KAAK,CAAC,KAAK,CAAC,CA8CxB;oBA1DY,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO;2BAJzB,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/infer.js b/node_modules/micromark-extension-gfm-table/lib/infer.js new file mode 100644 index 0000000000000000000000000000000000000000..750f2fde30fbeda52a03a400fc45c1ddc26db595 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/infer.js @@ -0,0 +1,52 @@ +/** + * @import {Event} from 'micromark-util-types' + */ + +/** + * @typedef {'center' | 'left' | 'none' | 'right'} Align + */ + +/** + * Figure out the alignment of a GFM table. + * + * @param {Readonly>} events + * List of events. + * @param {number} index + * Table enter event. + * @returns {Array} + * List of aligns. + */ +export function gfmTableAlign(events, index) { + let inDelimiterRow = false; + /** @type {Array} */ + const align = []; + while (index < events.length) { + const event = events[index]; + if (inDelimiterRow) { + if (event[0] === 'enter') { + // Start of alignment value: set a new column. + // To do: `markdown-rs` uses `tableDelimiterCellValue`. + if (event[1].type === 'tableContent') { + align.push(events[index + 1][1].type === 'tableDelimiterMarker' ? 'left' : 'none'); + } + } + // Exits: + // End of alignment value: change the column. + // To do: `markdown-rs` uses `tableDelimiterCellValue`. + else if (event[1].type === 'tableContent') { + if (events[index - 1][1].type === 'tableDelimiterMarker') { + const alignIndex = align.length - 1; + align[alignIndex] = align[alignIndex] === 'left' ? 'center' : 'right'; + } + } + // Done! + else if (event[1].type === 'tableDelimiterRow') { + break; + } + } else if (event[0] === 'enter' && event[1].type === 'tableDelimiterRow') { + inDelimiterRow = true; + } + index += 1; + } + return align; +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-table/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ecac018a28abeb8490d4e9df56c659b2aa93fcec --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/syntax.d.ts @@ -0,0 +1,18 @@ +/** + * Create an HTML extension for `micromark` to support GitHub tables syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * table syntax. + */ +export function gfmTable(): Extension; +/** + * Cell info. + */ +export type Range = [number, number, number, number]; +/** + * Where we are: `1` for head row, `2` for delimiter row, `3` for body row. + */ +export type RowKind = 0 | 1 | 2 | 3; +import type { Extension } from 'micromark-util-types'; +//# sourceMappingURL=syntax.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/syntax.d.ts.map b/node_modules/micromark-extension-gfm-table/lib/syntax.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..01eedacae562189b56aa95f1925da210f999cfa9 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/syntax.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["syntax.js"],"names":[],"mappings":"AAuBA;;;;;;GAMG;AACH,4BAJa,SAAS,CAUrB;;;;oBA/BY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;;;;sBAGhC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;+BAPoE,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/lib/syntax.js b/node_modules/micromark-extension-gfm-table/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..00b45b02adb80dd2daf12a4a5dbf78ee80e0e83a --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/lib/syntax.js @@ -0,0 +1,819 @@ +/** + * @import {Event, Extension, Point, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +/** + * @typedef {[number, number, number, number]} Range + * Cell info. + * + * @typedef {0 | 1 | 2 | 3} RowKind + * Where we are: `1` for head row, `2` for delimiter row, `3` for body row. + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding, markdownLineEndingOrSpace, markdownSpace } from 'micromark-util-character'; +import { EditMap } from './edit-map.js'; +import { gfmTableAlign } from './infer.js'; + +/** + * Create an HTML extension for `micromark` to support GitHub tables syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * table syntax. + */ +export function gfmTable() { + return { + flow: { + null: { + name: 'table', + tokenize: tokenizeTable, + resolveAll: resolveTable + } + } + }; +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeTable(effects, ok, nok) { + const self = this; + let size = 0; + let sizeB = 0; + /** @type {boolean | undefined} */ + let seen; + return start; + + /** + * Start of a GFM table. + * + * If there is a valid table row or table head before, then we try to parse + * another row. + * Otherwise, we try to parse a head. + * + * ```markdown + * > | | a | + * ^ + * | | - | + * > | | b | + * ^ + * ``` + * @type {State} + */ + function start(code) { + let index = self.events.length - 1; + while (index > -1) { + const type = self.events[index][1].type; + if (type === "lineEnding" || + // Note: markdown-rs uses `whitespace` instead of `linePrefix` + type === "linePrefix") index--;else break; + } + const tail = index > -1 ? self.events[index][1].type : null; + const next = tail === 'tableHead' || tail === 'tableRow' ? bodyRowStart : headRowBefore; + + // Don’t allow lazy body rows. + if (next === bodyRowStart && self.parser.lazy[self.now().line]) { + return nok(code); + } + return next(code); + } + + /** + * Before table head row. + * + * ```markdown + * > | | a | + * ^ + * | | - | + * | | b | + * ``` + * + * @type {State} + */ + function headRowBefore(code) { + effects.enter('tableHead'); + effects.enter('tableRow'); + return headRowStart(code); + } + + /** + * Before table head row, after whitespace. + * + * ```markdown + * > | | a | + * ^ + * | | - | + * | | b | + * ``` + * + * @type {State} + */ + function headRowStart(code) { + if (code === 124) { + return headRowBreak(code); + } + + // To do: micromark-js should let us parse our own whitespace in extensions, + // like `markdown-rs`: + // + // ```js + // // 4+ spaces. + // if (markdownSpace(code)) { + // return nok(code) + // } + // ``` + + seen = true; + // Count the first character, that isn’t a pipe, double. + sizeB += 1; + return headRowBreak(code); + } + + /** + * At break in table head row. + * + * ```markdown + * > | | a | + * ^ + * ^ + * ^ + * | | - | + * | | b | + * ``` + * + * @type {State} + */ + function headRowBreak(code) { + if (code === null) { + // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t. + return nok(code); + } + if (markdownLineEnding(code)) { + // If anything other than one pipe (ignoring whitespace) was used, it’s fine. + if (sizeB > 1) { + sizeB = 0; + // To do: check if this works. + // Feel free to interrupt: + self.interrupt = true; + effects.exit('tableRow'); + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return headDelimiterStart; + } + + // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t. + return nok(code); + } + if (markdownSpace(code)) { + // To do: check if this is fine. + // effects.attempt(State::Next(StateName::GfmTableHeadRowBreak), State::Nok) + // State::Retry(space_or_tab(tokenizer)) + return factorySpace(effects, headRowBreak, "whitespace")(code); + } + sizeB += 1; + if (seen) { + seen = false; + // Header cell count. + size += 1; + } + if (code === 124) { + effects.enter('tableCellDivider'); + effects.consume(code); + effects.exit('tableCellDivider'); + // Whether a delimiter was seen. + seen = true; + return headRowBreak; + } + + // Anything else is cell data. + effects.enter("data"); + return headRowData(code); + } + + /** + * In table head row data. + * + * ```markdown + * > | | a | + * ^ + * | | - | + * | | b | + * ``` + * + * @type {State} + */ + function headRowData(code) { + if (code === null || code === 124 || markdownLineEndingOrSpace(code)) { + effects.exit("data"); + return headRowBreak(code); + } + effects.consume(code); + return code === 92 ? headRowEscape : headRowData; + } + + /** + * In table head row escape. + * + * ```markdown + * > | | a\-b | + * ^ + * | | ---- | + * | | c | + * ``` + * + * @type {State} + */ + function headRowEscape(code) { + if (code === 92 || code === 124) { + effects.consume(code); + return headRowData; + } + return headRowData(code); + } + + /** + * Before delimiter row. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * | | b | + * ``` + * + * @type {State} + */ + function headDelimiterStart(code) { + // Reset `interrupt`. + self.interrupt = false; + + // Note: in `markdown-rs`, we need to handle piercing here too. + if (self.parser.lazy[self.now().line]) { + return nok(code); + } + effects.enter('tableDelimiterRow'); + // Track if we’ve seen a `:` or `|`. + seen = false; + if (markdownSpace(code)) { + return factorySpace(effects, headDelimiterBefore, "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4)(code); + } + return headDelimiterBefore(code); + } + + /** + * Before delimiter row, after optional whitespace. + * + * Reused when a `|` is found later, to parse another cell. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * | | b | + * ``` + * + * @type {State} + */ + function headDelimiterBefore(code) { + if (code === 45 || code === 58) { + return headDelimiterValueBefore(code); + } + if (code === 124) { + seen = true; + // If we start with a pipe, we open a cell marker. + effects.enter('tableCellDivider'); + effects.consume(code); + effects.exit('tableCellDivider'); + return headDelimiterCellBefore; + } + + // More whitespace / empty row not allowed at start. + return headDelimiterNok(code); + } + + /** + * After `|`, before delimiter cell. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterCellBefore(code) { + if (markdownSpace(code)) { + return factorySpace(effects, headDelimiterValueBefore, "whitespace")(code); + } + return headDelimiterValueBefore(code); + } + + /** + * Before delimiter cell value. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterValueBefore(code) { + // Align: left. + if (code === 58) { + sizeB += 1; + seen = true; + effects.enter('tableDelimiterMarker'); + effects.consume(code); + effects.exit('tableDelimiterMarker'); + return headDelimiterLeftAlignmentAfter; + } + + // Align: none. + if (code === 45) { + sizeB += 1; + // To do: seems weird that this *isn’t* left aligned, but that state is used? + return headDelimiterLeftAlignmentAfter(code); + } + if (code === null || markdownLineEnding(code)) { + return headDelimiterCellAfter(code); + } + return headDelimiterNok(code); + } + + /** + * After delimiter cell left alignment marker. + * + * ```markdown + * | | a | + * > | | :- | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterLeftAlignmentAfter(code) { + if (code === 45) { + effects.enter('tableDelimiterFiller'); + return headDelimiterFiller(code); + } + + // Anything else is not ok after the left-align colon. + return headDelimiterNok(code); + } + + /** + * In delimiter cell filler. + * + * ```markdown + * | | a | + * > | | - | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterFiller(code) { + if (code === 45) { + effects.consume(code); + return headDelimiterFiller; + } + + // Align is `center` if it was `left`, `right` otherwise. + if (code === 58) { + seen = true; + effects.exit('tableDelimiterFiller'); + effects.enter('tableDelimiterMarker'); + effects.consume(code); + effects.exit('tableDelimiterMarker'); + return headDelimiterRightAlignmentAfter; + } + effects.exit('tableDelimiterFiller'); + return headDelimiterRightAlignmentAfter(code); + } + + /** + * After delimiter cell right alignment marker. + * + * ```markdown + * | | a | + * > | | -: | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterRightAlignmentAfter(code) { + if (markdownSpace(code)) { + return factorySpace(effects, headDelimiterCellAfter, "whitespace")(code); + } + return headDelimiterCellAfter(code); + } + + /** + * After delimiter cell. + * + * ```markdown + * | | a | + * > | | -: | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterCellAfter(code) { + if (code === 124) { + return headDelimiterBefore(code); + } + if (code === null || markdownLineEnding(code)) { + // Exit when: + // * there was no `:` or `|` at all (it’s a thematic break or setext + // underline instead) + // * the header cell count is not the delimiter cell count + if (!seen || size !== sizeB) { + return headDelimiterNok(code); + } + + // Note: in markdown-rs`, a reset is needed here. + effects.exit('tableDelimiterRow'); + effects.exit('tableHead'); + // To do: in `markdown-rs`, resolvers need to be registered manually. + // effects.register_resolver(ResolveName::GfmTable) + return ok(code); + } + return headDelimiterNok(code); + } + + /** + * In delimiter row, at a disallowed byte. + * + * ```markdown + * | | a | + * > | | x | + * ^ + * ``` + * + * @type {State} + */ + function headDelimiterNok(code) { + // Note: in `markdown-rs`, we need to reset, in `micromark-js` we don‘t. + return nok(code); + } + + /** + * Before table body row. + * + * ```markdown + * | | a | + * | | - | + * > | | b | + * ^ + * ``` + * + * @type {State} + */ + function bodyRowStart(code) { + // Note: in `markdown-rs` we need to manually take care of a prefix, + // but in `micromark-js` that is done for us, so if we’re here, we’re + // never at whitespace. + effects.enter('tableRow'); + return bodyRowBreak(code); + } + + /** + * At break in table body row. + * + * ```markdown + * | | a | + * | | - | + * > | | b | + * ^ + * ^ + * ^ + * ``` + * + * @type {State} + */ + function bodyRowBreak(code) { + if (code === 124) { + effects.enter('tableCellDivider'); + effects.consume(code); + effects.exit('tableCellDivider'); + return bodyRowBreak; + } + if (code === null || markdownLineEnding(code)) { + effects.exit('tableRow'); + return ok(code); + } + if (markdownSpace(code)) { + return factorySpace(effects, bodyRowBreak, "whitespace")(code); + } + + // Anything else is cell content. + effects.enter("data"); + return bodyRowData(code); + } + + /** + * In table body row data. + * + * ```markdown + * | | a | + * | | - | + * > | | b | + * ^ + * ``` + * + * @type {State} + */ + function bodyRowData(code) { + if (code === null || code === 124 || markdownLineEndingOrSpace(code)) { + effects.exit("data"); + return bodyRowBreak(code); + } + effects.consume(code); + return code === 92 ? bodyRowEscape : bodyRowData; + } + + /** + * In table body row escape. + * + * ```markdown + * | | a | + * | | ---- | + * > | | b\-c | + * ^ + * ``` + * + * @type {State} + */ + function bodyRowEscape(code) { + if (code === 92 || code === 124) { + effects.consume(code); + return bodyRowData; + } + return bodyRowData(code); + } +} + +/** @type {Resolver} */ + +function resolveTable(events, context) { + let index = -1; + let inFirstCellAwaitingPipe = true; + /** @type {RowKind} */ + let rowKind = 0; + /** @type {Range} */ + let lastCell = [0, 0, 0, 0]; + /** @type {Range} */ + let cell = [0, 0, 0, 0]; + let afterHeadAwaitingFirstBodyRow = false; + let lastTableEnd = 0; + /** @type {Token | undefined} */ + let currentTable; + /** @type {Token | undefined} */ + let currentBody; + /** @type {Token | undefined} */ + let currentCell; + const map = new EditMap(); + while (++index < events.length) { + const event = events[index]; + const token = event[1]; + if (event[0] === 'enter') { + // Start of head. + if (token.type === 'tableHead') { + afterHeadAwaitingFirstBodyRow = false; + + // Inject previous (body end and) table end. + if (lastTableEnd !== 0) { + flushTableEnd(map, context, lastTableEnd, currentTable, currentBody); + currentBody = undefined; + lastTableEnd = 0; + } + + // Inject table start. + currentTable = { + type: 'table', + start: Object.assign({}, token.start), + // Note: correct end is set later. + end: Object.assign({}, token.end) + }; + map.add(index, 0, [['enter', currentTable, context]]); + } else if (token.type === 'tableRow' || token.type === 'tableDelimiterRow') { + inFirstCellAwaitingPipe = true; + currentCell = undefined; + lastCell = [0, 0, 0, 0]; + cell = [0, index + 1, 0, 0]; + + // Inject table body start. + if (afterHeadAwaitingFirstBodyRow) { + afterHeadAwaitingFirstBodyRow = false; + currentBody = { + type: 'tableBody', + start: Object.assign({}, token.start), + // Note: correct end is set later. + end: Object.assign({}, token.end) + }; + map.add(index, 0, [['enter', currentBody, context]]); + } + rowKind = token.type === 'tableDelimiterRow' ? 2 : currentBody ? 3 : 1; + } + // Cell data. + else if (rowKind && (token.type === "data" || token.type === 'tableDelimiterMarker' || token.type === 'tableDelimiterFiller')) { + inFirstCellAwaitingPipe = false; + + // First value in cell. + if (cell[2] === 0) { + if (lastCell[1] !== 0) { + cell[0] = cell[1]; + currentCell = flushCell(map, context, lastCell, rowKind, undefined, currentCell); + lastCell = [0, 0, 0, 0]; + } + cell[2] = index; + } + } else if (token.type === 'tableCellDivider') { + if (inFirstCellAwaitingPipe) { + inFirstCellAwaitingPipe = false; + } else { + if (lastCell[1] !== 0) { + cell[0] = cell[1]; + currentCell = flushCell(map, context, lastCell, rowKind, undefined, currentCell); + } + lastCell = cell; + cell = [lastCell[1], index, 0, 0]; + } + } + } + // Exit events. + else if (token.type === 'tableHead') { + afterHeadAwaitingFirstBodyRow = true; + lastTableEnd = index; + } else if (token.type === 'tableRow' || token.type === 'tableDelimiterRow') { + lastTableEnd = index; + if (lastCell[1] !== 0) { + cell[0] = cell[1]; + currentCell = flushCell(map, context, lastCell, rowKind, index, currentCell); + } else if (cell[1] !== 0) { + currentCell = flushCell(map, context, cell, rowKind, index, currentCell); + } + rowKind = 0; + } else if (rowKind && (token.type === "data" || token.type === 'tableDelimiterMarker' || token.type === 'tableDelimiterFiller')) { + cell[3] = index; + } + } + if (lastTableEnd !== 0) { + flushTableEnd(map, context, lastTableEnd, currentTable, currentBody); + } + map.consume(context.events); + + // To do: move this into `html`, when events are exposed there. + // That’s what `markdown-rs` does. + // That needs updates to `mdast-util-gfm-table`. + index = -1; + while (++index < context.events.length) { + const event = context.events[index]; + if (event[0] === 'enter' && event[1].type === 'table') { + event[1]._align = gfmTableAlign(context.events, index); + } + } + return events; +} + +/** + * Generate a cell. + * + * @param {EditMap} map + * @param {Readonly} context + * @param {Readonly} range + * @param {RowKind} rowKind + * @param {number | undefined} rowEnd + * @param {Token | undefined} previousCell + * @returns {Token | undefined} + */ +// eslint-disable-next-line max-params +function flushCell(map, context, range, rowKind, rowEnd, previousCell) { + // `markdown-rs` uses: + // rowKind === 2 ? 'tableDelimiterCell' : 'tableCell' + const groupName = rowKind === 1 ? 'tableHeader' : rowKind === 2 ? 'tableDelimiter' : 'tableData'; + // `markdown-rs` uses: + // rowKind === 2 ? 'tableDelimiterCellValue' : 'tableCellText' + const valueName = 'tableContent'; + + // Insert an exit for the previous cell, if there is one. + // + // ```markdown + // > | | aa | bb | cc | + // ^-- exit + // ^^^^-- this cell + // ``` + if (range[0] !== 0) { + previousCell.end = Object.assign({}, getPoint(context.events, range[0])); + map.add(range[0], 0, [['exit', previousCell, context]]); + } + + // Insert enter of this cell. + // + // ```markdown + // > | | aa | bb | cc | + // ^-- enter + // ^^^^-- this cell + // ``` + const now = getPoint(context.events, range[1]); + previousCell = { + type: groupName, + start: Object.assign({}, now), + // Note: correct end is set later. + end: Object.assign({}, now) + }; + map.add(range[1], 0, [['enter', previousCell, context]]); + + // Insert text start at first data start and end at last data end, and + // remove events between. + // + // ```markdown + // > | | aa | bb | cc | + // ^-- enter + // ^-- exit + // ^^^^-- this cell + // ``` + if (range[2] !== 0) { + const relatedStart = getPoint(context.events, range[2]); + const relatedEnd = getPoint(context.events, range[3]); + /** @type {Token} */ + const valueToken = { + type: valueName, + start: Object.assign({}, relatedStart), + end: Object.assign({}, relatedEnd) + }; + map.add(range[2], 0, [['enter', valueToken, context]]); + if (rowKind !== 2) { + // Fix positional info on remaining events + const start = context.events[range[2]]; + const end = context.events[range[3]]; + start[1].end = Object.assign({}, end[1].end); + start[1].type = "chunkText"; + start[1].contentType = "text"; + + // Remove if needed. + if (range[3] > range[2] + 1) { + const a = range[2] + 1; + const b = range[3] - range[2] - 1; + map.add(a, b, []); + } + } + map.add(range[3] + 1, 0, [['exit', valueToken, context]]); + } + + // Insert an exit for the last cell, if at the row end. + // + // ```markdown + // > | | aa | bb | cc | + // ^-- exit + // ^^^^^^-- this cell (the last one contains two “between” parts) + // ``` + if (rowEnd !== undefined) { + previousCell.end = Object.assign({}, getPoint(context.events, rowEnd)); + map.add(rowEnd, 0, [['exit', previousCell, context]]); + previousCell = undefined; + } + return previousCell; +} + +/** + * Generate table end (and table body end). + * + * @param {Readonly} map + * @param {Readonly} context + * @param {number} index + * @param {Token} table + * @param {Token | undefined} tableBody + */ +// eslint-disable-next-line max-params +function flushTableEnd(map, context, index, table, tableBody) { + /** @type {Array} */ + const exits = []; + const related = getPoint(context.events, index); + if (tableBody) { + tableBody.end = Object.assign({}, related); + exits.push(['exit', tableBody, context]); + } + table.end = Object.assign({}, related); + exits.push(['exit', table, context]); + map.add(index + 1, 0, exits); +} + +/** + * @param {Readonly>} events + * @param {number} index + * @returns {Readonly} + */ +function getPoint(events, index) { + const event = events[index]; + const side = event[0] === 'enter' ? 'start' : 'end'; + return event[1][side]; +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-table/license b/node_modules/micromark-extension-gfm-table/license new file mode 100644 index 0000000000000000000000000000000000000000..bc8f165a62768a19de38901d81ac662c51ff29db --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark-extension-gfm-table/package.json b/node_modules/micromark-extension-gfm-table/package.json new file mode 100644 index 0000000000000000000000000000000000000000..89261b93d743af1eaa786e230c84737398250989 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/package.json @@ -0,0 +1,128 @@ +{ + "author": "Titus Wormer (https://wooorm.com)", + "bugs": "https://github.com/micromark/micromark-extension-gfm-table/issues", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "dependencies": { + "devlop": "^1.0.0", + "micromark-factory-space": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + }, + "description": "micromark extension to support GFM tables", + "devDependencies": { + "@types/node": "^22.0.0", + "c8": "^10.0.0", + "create-gfm-fixtures": "^2.0.0", + "micromark": "^4.0.0", + "micromark-build": "^2.0.0", + "prettier": "^3.0.0", + "remark-cli": "^12.0.0", + "remark-preset-wooorm": "^10.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.60.0" + }, + "exports": { + "development": "./dev/index.js", + "default": "./index.js" + }, + "files": [ + "dev/", + "index.d.ts", + "index.js", + "lib/" + ], + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "keywords": [ + "cell", + "column", + "gfm", + "markdown", + "micromark-extension", + "micromark", + "row", + "table", + "tabular", + "unified" + ], + "license": "MIT", + "name": "micromark-extension-gfm-table", + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "repository": "micromark/micromark-extension-gfm-table", + "scripts": { + "build": "tsc --build --clean && tsc --build && type-coverage && micromark-build", + "format": "remark --frail --quiet --output -- . && prettier --log-level warn --write -- . && xo --fix", + "test-api-dev": "node --conditions development test/index.js", + "test-api-prod": "node --conditions production test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov -- npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "sideEffects": false, + "typeCoverage": { + "atLeast": 100, + "strict": true + }, + "type": "module", + "version": "2.1.1", + "xo": { + "overrides": [ + { + "files": [ + "**/*.d.ts" + ], + "rules": { + "@typescript-eslint/array-type": [ + "error", + { + "default": "generic" + } + ], + "@typescript-eslint/ban-types": [ + "error", + { + "extendDefaults": true + } + ], + "@typescript-eslint/consistent-type-definitions": [ + "error", + "interface" + ] + } + }, + { + "files": [ + "test/**/*.js" + ], + "rules": { + "no-await-in-loop": "off" + } + } + ], + "prettier": true, + "rules": { + "complexity": "off", + "max-depth": "off", + "unicorn/no-this-assignment": "off", + "unicorn/prefer-string-replace-all": "off" + } + } +} diff --git a/node_modules/micromark-extension-gfm-table/readme.md b/node_modules/micromark-extension-gfm-table/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..2f437ab54e9648f4a116c9f7d0e37e4452d2a6f3 --- /dev/null +++ b/node_modules/micromark-extension-gfm-table/readme.md @@ -0,0 +1,515 @@ +# micromark-extension-gfm-table + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[micromark][] extensions to support GFM [tables][]. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmTable()`](#gfmtable) + * [`gfmTableHtml()`](#gfmtablehtml) +* [Bugs](#bugs) +* [Authoring](#authoring) +* [HTML](#html) +* [CSS](#css) +* [Syntax](#syntax) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains extensions that add support for the table syntax enabled +by GFM to [`micromark`][micromark]. +These extensions match github.com. + +## When to use this + +This project is useful when you want to support tables in markdown. + +You can use these extensions when you are working with [`micromark`][micromark]. +To support all GFM features, use +[`micromark-extension-gfm`][micromark-extension-gfm] instead. + +When you need a syntax tree, combine this package with +[`mdast-util-gfm-table`][mdast-util-gfm-table]. + +All these packages are used in [`remark-gfm`][remark-gfm], which focusses on +making it easier to transform content by abstracting these internals away. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install micromark-extension-gfm-table +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmTable, gfmTableHtml} from 'https://esm.sh/micromark-extension-gfm-table@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +```js +import {micromark} from 'micromark' +import {gfmTable, gfmTableHtml} from 'micromark-extension-gfm-table' + +const output = micromark('| a |\n| - |', { + extensions: [gfmTable()], + htmlExtensions: [gfmTableHtml()] +}) + +console.log(output) +``` + +Yields: + +```html + + + + + + +
      a
      +``` + +## API + +This package exports the identifiers [`gfmTable`][api-gfm-table] and +[`gfmTableHtml`][api-gfm-table-html]. +There is no default export. + +The export map supports the [`development` condition][development]. +Run `node --conditions development module.js` to get instrumented dev code. +Without this condition, production code is loaded. + +### `gfmTable()` + +Create an HTML extension for `micromark` to support GitHub tables syntax. + +###### Returns + +Extension for `micromark` that can be passed in `extensions` to enable GFM +table syntax ([`Extension`][micromark-extension]). + +### `gfmTableHtml()` + +Create an HTML extension for `micromark` to support GitHub tables when +serializing to HTML. + +###### Returns + +Extension for `micromark` that can be passed in `htmlExtensions` to support +GFM tables when serializing to HTML +([`HtmlExtension`][micromark-html-extension]). + +## Bugs + +GitHub’s own algorithm to parse tables contains a bug. +This bug is not present in this project. +The issue relating to tables is: + +* [GFM tables: escaped escapes are incorrectly treated as + escapes](https://github.com/github/cmark-gfm/issues/277) + +## Authoring + +When authoring markdown with GFM tables, it’s recommended to *always* put +pipes around cells. +Without them, it can be hard to infer whether the table will work, how many +columns there are, and which column you are currently editing. + +It is recommended to not use many columns, as it results in very long lines, +making it hard to infer which column you are currently editing. + +For larger tables, particularly when cells vary in size, it is recommended +*not* to manually “pad” cell text. +While it can look better, it results in a lot of time spent realigning +everything when a new, longer cell is added or the longest cell removed, as +every row then must be changed. +Other than costing time, it also causes large diffs in Git. + +To illustrate, when authoring large tables, it is discouraged to pad cells +like this: + +```markdown +| Alpha bravo charlie | delta | +| ------------------- | -----------------: | +| Echo | Foxtrot golf hotel | +``` + +Instead, use single spaces (and single filler dashes): + +```markdown +| Alpha bravo charlie | delta | +| - | -: | +| Echo | Foxtrot golf hotel | +``` + +## HTML + +GFM tables relate to several HTML elements: ``, ``, ``, and ``. +See +[*§ 4.9.1 The `table` element*][html-table], +[*§ 4.9.5 The `tbody` element*][html-tbody], +[*§ 4.9.9 The `td` element*][html-td], +[*§ 4.9.10 The `th` element*][html-th], +[*§ 4.9.6 The `thead` element*][html-thead], and +[*§ 4.9.8 The `tr` element*][html-tr] +in the HTML spec for more info. + +If the alignment of a column is left, right, or center, a deprecated +`align` attribute is added to each `
      `, +``, `
      ` and `` element belonging to +that column. +That attribute is interpreted by browsers as if a CSS `text-align` property +was included, with its value set to that same keyword. + +## CSS + +The following CSS is needed to make tables look a bit like GitHub. +For the complete actual CSS see +[`sindresorhus/github-markdown-css`][github-markdown-css] + +```css +/* Light theme. */ +:root { + --color-canvas-default: #ffffff; + --color-canvas-subtle: #f6f8fa; + --color-border-default: #d0d7de; + --color-border-muted: hsla(210, 18%, 87%, 1); +} + +/* Dark theme. */ +@media (prefers-color-scheme: dark) { + :root { + --color-canvas-default: #0d1117; + --color-canvas-subtle: #161b22; + --color-border-default: #30363d; + --color-border-muted: #21262d; + } +} + +table { + border-spacing: 0; + border-collapse: collapse; + display: block; + margin-top: 0; + margin-bottom: 16px; + width: max-content; + max-width: 100%; + overflow: auto; +} + +tr { + background-color: var(--color-canvas-default); + border-top: 1px solid var(--color-border-muted); +} + +tr:nth-child(2n) { + background-color: var(--color-canvas-subtle); +} + +td, +th { + padding: 6px 13px; + border: 1px solid var(--color-border-default); +} + +th { + font-weight: 600; +} + +table img { + background-color: transparent; +} +``` + +## Syntax + +Tables form with the following BNF: + +```abnf +gfmTable ::= gfmTableHead 0*(eol gfmTableBodyRow) + +; Restriction: both rows must have the same number of cells. +gfmTableHead ::= gfmTableRow eol gfmTableDelimiterRow + +gfmTableRow ::= ["|"] gfmTableCell 0*("|" gfmTableCell) ["|"] *spaceOrTab +gfmTableCell ::= *spaceOrTab gfmTableText *spaceOrTab +gfmTableText ::= 0*(line - "\\" - "|" / "\\" ["\\" / "|"]) + +gfmTableDelimiterRow ::= ["|"] gfmTableDelimiterCell 0*("|" gfmTableDelimiterCell) ["|"] *spaceOrTab +gfmTableDelimiterCell ::= *spaceOrTab gfmTableDelimiterValue *spaceOrTab +gfmTableDelimiterValue ::= [":"] 1*"-" [":"] +``` + +As this construct occurs in flow, like all flow constructs, it must be +followed by an eol (line ending) or eof (end of file). + +The above grammar shows that basically anything can be a cell or a row. +The main thing that makes something a row, is that it occurs directly before +or after a delimiter row, or after another row. + +It is not required for a table to have a body: it can end right after the +delimiter row. + +Each column can be marked with an alignment. +The alignment marker is a colon (`:`) used before and/or after delimiter row +filler. +To illustrate: + +```markdown +| none | left | right | center | +| ---- | :--- | ----: | :----: | +``` + +The number of cells in the delimiter row, is the number of columns of the +table. +Only the head row is required to have the same number of cells. +Body rows are not required to have a certain number of cells. +For body rows that have less cells than the number of columns of the table, +empty cells are injected. +When a row has more cells than the number of columns of the table, the +superfluous cells are dropped. +To illustrate: + +```markdown +| a | b | +| - | - | +| c | +| d | e | f | +``` + +Yields: + +```html + + + + + + + + + + + + + + + + + +
      ab
      c
      de
      +``` + +Each cell’s text is interpreted as the [text][micromark-content-type] content +type. +That means that it can include constructs such as attention (emphasis, strong). + +The grammar for cells prohibits the use of `|` in them. +To use pipes in cells, encode them as a character reference or character +escape: `|` (or `|`, `|`, `|`, `|`) or +`\|`. + +Escapes will typically work, but they are not supported in +code (text) (and the math (text) extension). +To work around this, GitHub came up with a rather weird “trick”. +When inside a table cell *and* inside code, escaped pipes *are* decoded. +To illustrate: + +```markdown +| Name | Character | +| - | - | +| Left curly brace | `{` | +| Pipe | `\|` | +| Right curly brace | `}` | +``` + +Yields: + +```html + + + + + + + + + + + + + + + + + + + + + +
      NameCharacter
      Left curly brace{
      Pipe|
      Right curly brace}
      +``` + +> 👉 **Note**: no other character can be escaped like this. +> Escaping pipes in code does not work when not inside a table, either. + +## Types + +This package is fully typed with [TypeScript][]. +It exports no additional types. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`micromark-extension-gfm-table@^2`, compatible with Node.js 16. + +This package works with `micromark` version `3` and later. + +## Security + +This package is safe. + +## Related + +* [`micromark-extension-gfm`][micromark-extension-gfm] + — support all of GFM +* [`mdast-util-gfm-table`][mdast-util-gfm-table] + — support all of GFM in mdast +* [`mdast-util-gfm`][mdast-util-gfm] + — support all of GFM in mdast +* [`remark-gfm`][remark-gfm] + — support all of GFM in remark + +## Contribute + +See [`contributing.md` in `micromark/.github`][contributing] for ways to get +started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/micromark/micromark-extension-gfm-table/workflows/main/badge.svg + +[build]: https://github.com/micromark/micromark-extension-gfm-table/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm-table.svg + +[coverage]: https://codecov.io/github/micromark/micromark-extension-gfm-table + +[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm-table.svg + +[downloads]: https://www.npmjs.com/package/micromark-extension-gfm-table + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-gfm-table + +[size]: https://bundlejs.com/?q=micromark-extension-gfm-table + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/micromark/micromark/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esmsh]: https://esm.sh + +[license]: license + +[author]: https://wooorm.com + +[contributing]: https://github.com/micromark/.github/blob/main/contributing.md + +[support]: https://github.com/micromark/.github/blob/main/support.md + +[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[typescript]: https://www.typescriptlang.org + +[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions + +[micromark]: https://github.com/micromark/micromark + +[micromark-extension]: https://github.com/micromark/micromark#syntaxextension + +[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension + +[micromark-content-type]: https://github.com/micromark/micromark#content-types + +[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[mdast-util-gfm-table]: https://github.com/syntax-tree/mdast-util-gfm-table + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[tables]: https://github.github.com/gfm/#tables-extension- + +[html-table]: https://html.spec.whatwg.org/multipage/tables.html#the-table-element + +[html-tbody]: https://html.spec.whatwg.org/multipage/tables.html#the-tbody-element + +[html-thead]: https://html.spec.whatwg.org/multipage/tables.html#the-thead-element + +[html-tr]: https://html.spec.whatwg.org/multipage/tables.html#the-tr-element + +[html-td]: https://html.spec.whatwg.org/multipage/tables.html#the-td-element + +[html-th]: https://html.spec.whatwg.org/multipage/tables.html#the-th-element + +[github-markdown-css]: https://github.com/sindresorhus/github-markdown-css + +[api-gfm-table]: #gfmtable + +[api-gfm-table-html]: #gfmtablehtml diff --git a/node_modules/micromark-extension-gfm-tagfilter/index.d.ts b/node_modules/micromark-extension-gfm-tagfilter/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a00c9377f59ca9a2cb0130bcc5cf8e908f37454a --- /dev/null +++ b/node_modules/micromark-extension-gfm-tagfilter/index.d.ts @@ -0,0 +1 @@ +export {gfmTagfilterHtml} from './lib/index.js' diff --git a/node_modules/micromark-extension-gfm-tagfilter/index.js b/node_modules/micromark-extension-gfm-tagfilter/index.js new file mode 100644 index 0000000000000000000000000000000000000000..a00c9377f59ca9a2cb0130bcc5cf8e908f37454a --- /dev/null +++ b/node_modules/micromark-extension-gfm-tagfilter/index.js @@ -0,0 +1 @@ +export {gfmTagfilterHtml} from './lib/index.js' diff --git a/node_modules/micromark-extension-gfm-tagfilter/lib/index.d.ts b/node_modules/micromark-extension-gfm-tagfilter/lib/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..6839a41ba12919efea0c617d8c6a077c383b403e --- /dev/null +++ b/node_modules/micromark-extension-gfm-tagfilter/lib/index.d.ts @@ -0,0 +1,12 @@ +/** + * Create an HTML extension for `micromark` to support GitHubs weird and + * useless tagfilter when serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to support + * GitHubs weird and useless tagfilter when serializing to HTML. + */ +export function gfmTagfilterHtml(): HtmlExtension +export type CompileContext = import('micromark-util-types').CompileContext +export type HtmlExtension = import('micromark-util-types').HtmlExtension +export type Token = import('micromark-util-types').Token diff --git a/node_modules/micromark-extension-gfm-tagfilter/lib/index.js b/node_modules/micromark-extension-gfm-tagfilter/lib/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d14eb36cb678a71cdaba0f6ded5b44ae2af76b59 --- /dev/null +++ b/node_modules/micromark-extension-gfm-tagfilter/lib/index.js @@ -0,0 +1,51 @@ +/** + * @typedef {import('micromark-util-types').CompileContext} CompileContext + * @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension + * @typedef {import('micromark-util-types').Token} Token + */ + +// An opening or closing tag start, followed by a case-insensitive specific tag name, +// followed by HTML whitespace, a greater than, or a slash. +const reFlow = + /<(\/?)(iframe|noembed|noframes|plaintext|script|style|title|textarea|xmp)(?=[\t\n\f\r />])/gi + +// As HTML (text) parses tags separately (and very strictly), we don’t need to be +// global. +const reText = new RegExp('^' + reFlow.source, 'i') + +/** + * Create an HTML extension for `micromark` to support GitHubs weird and + * useless tagfilter when serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to support + * GitHubs weird and useless tagfilter when serializing to HTML. + */ +export function gfmTagfilterHtml() { + return { + exit: { + htmlFlowData(token) { + exitHtmlData.call(this, token, reFlow) + }, + htmlTextData(token) { + exitHtmlData.call(this, token, reText) + } + } + } +} + +/** + * @this {CompileContext} + * @param {Token} token + * @param {RegExp} filter + * @returns {undefined} + */ +function exitHtmlData(token, filter) { + let value = this.sliceSerialize(token) + + if (this.options.allowDangerousHtml) { + value = value.replace(filter, '<$1$2') + } + + this.raw(this.encode(value)) +} diff --git a/node_modules/micromark-extension-gfm-tagfilter/license b/node_modules/micromark-extension-gfm-tagfilter/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/micromark-extension-gfm-tagfilter/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark-extension-gfm-tagfilter/package.json b/node_modules/micromark-extension-gfm-tagfilter/package.json new file mode 100644 index 0000000000000000000000000000000000000000..179a10583fe8bd64bae8404745288cd33dfc5276 --- /dev/null +++ b/node_modules/micromark-extension-gfm-tagfilter/package.json @@ -0,0 +1,82 @@ +{ + "name": "micromark-extension-gfm-tagfilter", + "version": "2.0.0", + "description": "micromark extension to support GFM tagfilter", + "license": "MIT", + "keywords": [ + "micromark", + "micromark-extension", + "tagfilter", + "tag", + "filter", + "dangerous", + "html", + "gfm", + "markdown", + "unified" + ], + "repository": "micromark/micromark-extension-gfm-tagfilter", + "bugs": "https://github.com/micromark/micromark-extension-gfm-tagfilter/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "lib/", + "index.d.ts", + "index.js" + ], + "dependencies": { + "micromark-util-types": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "micromark": "^4.0.0", + "prettier": "^2.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "xo": "^0.54.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api-prod": "node --conditions production test/index.js", + "test-api-dev": "node --conditions development test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "prettier": true + } +} diff --git a/node_modules/micromark-extension-gfm-tagfilter/readme.md b/node_modules/micromark-extension-gfm-tagfilter/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..f97b2e733b84b80fb70fef8423fc25640946c3bd --- /dev/null +++ b/node_modules/micromark-extension-gfm-tagfilter/readme.md @@ -0,0 +1,237 @@ +# micromark-extension-gfm-tagfilter + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[micromark][] extension to support GFM [tag filter][]. + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfmTagfilterHtml()`](#gfmtagfilterhtml) +* [Authoring](#authoring) +* [HTML](#html) +* [CSS](#css) +* [Syntax](#syntax) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Related](#related) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains an extension that adds support for the tagfilter enabled +by GFM to [`micromark`][micromark]. +The tagfilter is kinda weird and kinda useless. +This package exists for completeness. +The tag filter is a naïve attempt at XSS protection. +You should use a proper HTML sanitizing algorithm. + +## When to use this + +This project is useful when you want to match how GitHub works. +You can use this extension when you are working with [`micromark`][micromark] +already. +When you do, you can instead use +[`micromark-extension-gfm`][micromark-extension-gfm], which includes this +extension, to support all GFM features. + +When you want to deal with syntax trees, you should instead use +[`hast-util-sanitize`][hast-util-sanitize]. + +When you use remark and rehype, you should use +[`rehype-sanitize`][rehype-sanitize]. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install micromark-extension-gfm-tagfilter +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfmTagfilterHtml} from 'https://esm.sh/micromark-extension-gfm-tagfilter@2' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +```js +import {micromark} from 'micromark' +import {gfmTagfilterHtml} from 'micromark-extension-gfm-tagfilter' + +const output = micromark('XSS! ', { + allowDangerousHtml: true, + htmlExtensions: [gfmTagfilterHtml()] +}) + +console.log(output) +``` + +Yields: + +```html +

      XSS! <script>alert(1)</script>

      +``` + +## API + +This package exports the identifier +[`gfmTagfilterHtml`][api-gfm-tagfilter-html]. +There is no default export. + +### `gfmTagfilterHtml()` + +Create an HTML extension for `micromark` to support GitHubs weird and +useless tagfilter when serializing to HTML. + +###### Returns + +Extension for `micromark` that can be passed in `htmlExtensions` to support +GitHubs weird and useless tagfilter when serializing to HTML +([`HtmlExtension`][micromark-html-extension]). + +## Authoring + +This package relates to malicious authors, not decent authors. + +## HTML + +GFM tagfilter removes certain dangerous HTML tags: `iframe`, `noembed`, +`noframes`, `plaintext`, `script`, `style`, `title`, `textarea`, and `xmp`. + +## CSS + +This package does not relate to CSS. + +## Syntax + +This package does not change how markdown is parsed. + +## Types + +This package is fully typed with [TypeScript][]. +It exports no additional types. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`micromark-extension-gfm-tagfilter@^2`, compatible with Node.js 16. + +This package works with `micromark` version `3` and later. + +## Security + +While micromark is safe by default, this extension only does something when +`allowDangerousHtml: true` is passed, which is an unsafe option. +This package is **not safe**. + +## Related + +* [`micromark-extension-gfm`][micromark-extension-gfm] + — support all of GFM +* [`hast-util-sanitize`][hast-util-sanitize] + — hast utility to make trees safe +* [`rehype-sanitize`][rehype-sanitize] + — rehype plugin to sanitize HTML + +## Contribute + +See [`contributing.md` in `micromark/.github`][contributing] for ways to get +started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + + + +[build-badge]: https://github.com/micromark/micromark-extension-gfm-tagfilter/workflows/main/badge.svg + +[build]: https://github.com/micromark/micromark-extension-gfm-tagfilter/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm-tagfilter.svg + +[coverage]: https://codecov.io/github/micromark/micromark-extension-gfm-tagfilter + +[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm-tagfilter.svg + +[downloads]: https://www.npmjs.com/package/micromark-extension-gfm-tagfilter + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-gfm-tagfilter + +[size]: https://bundlejs.com/?q=micromark-extension-gfm-tagfilter + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/micromark/micromark/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esmsh]: https://esm.sh + +[license]: license + +[author]: https://wooorm.com + +[contributing]: https://github.com/micromark/.github/blob/main/contributing.md + +[support]: https://github.com/micromark/.github/blob/main/support.md + +[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[typescript]: https://www.typescriptlang.org + +[micromark]: https://github.com/micromark/micromark + +[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension + +[micromark-extension-gfm]: https://github.com/micromark/micromark-extension-gfm + +[rehype-sanitize]: https://github.com/rehypejs/rehype-sanitize + +[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize + +[tag filter]: https://github.github.com/gfm/#disallowed-raw-html-extension- + +[api-gfm-tagfilter-html]: #gfmtagfilterhtml diff --git a/node_modules/micromark-extension-gfm-task-list-item/dev/index.d.ts b/node_modules/micromark-extension-gfm-task-list-item/dev/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c0d959e29771342952fdb91d23e9da173a98144 --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/dev/index.d.ts @@ -0,0 +1,17 @@ +export {gfmTaskListItemHtml} from './lib/html.js' +export {gfmTaskListItem} from './lib/syntax.js' + +/** + * Augment types. + */ +declare module 'micromark-util-types' { + /** + * Token types. + */ + interface TokenTypeMap { + taskListCheck: 'taskListCheck' + taskListCheckMarker: 'taskListCheckMarker' + taskListCheckValueChecked: 'taskListCheckValueChecked' + taskListCheckValueUnchecked: 'taskListCheckValueUnchecked' + } +} diff --git a/node_modules/micromark-extension-gfm-task-list-item/dev/index.js b/node_modules/micromark-extension-gfm-task-list-item/dev/index.js new file mode 100644 index 0000000000000000000000000000000000000000..2e18f6c1f8187df801c379d0911a6bd989878dfe --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/dev/index.js @@ -0,0 +1,2 @@ +export {gfmTaskListItemHtml} from './lib/html.js' +export {gfmTaskListItem} from './lib/syntax.js' diff --git a/node_modules/micromark-extension-gfm-task-list-item/dev/lib/html.d.ts b/node_modules/micromark-extension-gfm-task-list-item/dev/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..77a83bdaf606d940ec9151dcae16356f12027b21 --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/dev/lib/html.d.ts @@ -0,0 +1,13 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ +/** + * Create an HTML extension for `micromark` to support GFM task list items when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM task list items when serializing to HTML. + */ +export function gfmTaskListItemHtml(): HtmlExtension; +import type { HtmlExtension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-task-list-item/dev/lib/html.js b/node_modules/micromark-extension-gfm-task-list-item/dev/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..b4a14addeb51aacc192ad945bb6bd5539d9f2e9c --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/dev/lib/html.js @@ -0,0 +1,29 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ + +/** + * Create an HTML extension for `micromark` to support GFM task list items when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM task list items when serializing to HTML. + */ +export function gfmTaskListItemHtml() { + return { + enter: { + taskListCheck() { + this.tag('') + }, + taskListCheckValueChecked() { + this.tag('checked="" ') + } + } + } +} diff --git a/node_modules/micromark-extension-gfm-task-list-item/dev/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-task-list-item/dev/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3ffb821e47543ebe4a435cc20aac30e748027438 --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/dev/lib/syntax.d.ts @@ -0,0 +1,10 @@ +/** + * Create an HTML extension for `micromark` to support GFM task list items + * syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM task list items when serializing to HTML. + */ +export function gfmTaskListItem(): Extension; +import type { Extension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-task-list-item/dev/lib/syntax.js b/node_modules/micromark-extension-gfm-task-list-item/dev/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..4174cee274c7c0aa474308c01cd78841e284204d --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/dev/lib/syntax.js @@ -0,0 +1,166 @@ +/** + * @import {Extension, State, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import { + markdownLineEnding, + markdownLineEndingOrSpace, + markdownSpace +} from 'micromark-util-character' +import {codes, types} from 'micromark-util-symbol' + +const tasklistCheck = {name: 'tasklistCheck', tokenize: tokenizeTasklistCheck} + +/** + * Create an HTML extension for `micromark` to support GFM task list items + * syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM task list items when serializing to HTML. + */ +export function gfmTaskListItem() { + return { + text: {[codes.leftSquareBracket]: tasklistCheck} + } +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeTasklistCheck(effects, ok, nok) { + const self = this + + return open + + /** + * At start of task list item check. + * + * ```markdown + * > | * [x] y. + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + assert(code === codes.leftSquareBracket, 'expected `[`') + + if ( + // Exit if there’s stuff before. + self.previous !== codes.eof || + // Exit if not in the first content that is the first child of a list + // item. + !self._gfmTasklistFirstContentOfListItem + ) { + return nok(code) + } + + effects.enter('taskListCheck') + effects.enter('taskListCheckMarker') + effects.consume(code) + effects.exit('taskListCheckMarker') + return inside + } + + /** + * In task list item check. + * + * ```markdown + * > | * [x] y. + * ^ + * ``` + * + * @type {State} + */ + function inside(code) { + // Currently we match how GH works in files. + // To match how GH works in comments, use `markdownSpace` (`[\t ]`) instead + // of `markdownLineEndingOrSpace` (`[\t\n\r ]`). + if (markdownLineEndingOrSpace(code)) { + effects.enter('taskListCheckValueUnchecked') + effects.consume(code) + effects.exit('taskListCheckValueUnchecked') + return close + } + + if (code === codes.uppercaseX || code === codes.lowercaseX) { + effects.enter('taskListCheckValueChecked') + effects.consume(code) + effects.exit('taskListCheckValueChecked') + return close + } + + return nok(code) + } + + /** + * At close of task list item check. + * + * ```markdown + * > | * [x] y. + * ^ + * ``` + * + * @type {State} + */ + function close(code) { + if (code === codes.rightSquareBracket) { + effects.enter('taskListCheckMarker') + effects.consume(code) + effects.exit('taskListCheckMarker') + effects.exit('taskListCheck') + return after + } + + return nok(code) + } + + /** + * @type {State} + */ + function after(code) { + // EOL in paragraph means there must be something else after it. + if (markdownLineEnding(code)) { + return ok(code) + } + + // Space or tab? + // Check what comes after. + if (markdownSpace(code)) { + return effects.check({tokenize: spaceThenNonSpace}, ok, nok)(code) + } + + // EOF, or non-whitespace, both wrong. + return nok(code) + } +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function spaceThenNonSpace(effects, ok, nok) { + return factorySpace(effects, after, types.whitespace) + + /** + * After whitespace, after task list item check. + * + * ```markdown + * > | * [x] y. + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + // EOF means there was nothing, so bad. + // EOL means there’s content after it, so good. + // Impossible to have more spaces. + // Anything else is good. + return code === codes.eof ? nok(code) : ok(code) + } +} diff --git a/node_modules/micromark-extension-gfm-task-list-item/index.d.ts b/node_modules/micromark-extension-gfm-task-list-item/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c0d959e29771342952fdb91d23e9da173a98144 --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/index.d.ts @@ -0,0 +1,17 @@ +export {gfmTaskListItemHtml} from './lib/html.js' +export {gfmTaskListItem} from './lib/syntax.js' + +/** + * Augment types. + */ +declare module 'micromark-util-types' { + /** + * Token types. + */ + interface TokenTypeMap { + taskListCheck: 'taskListCheck' + taskListCheckMarker: 'taskListCheckMarker' + taskListCheckValueChecked: 'taskListCheckValueChecked' + taskListCheckValueUnchecked: 'taskListCheckValueUnchecked' + } +} diff --git a/node_modules/micromark-extension-gfm-task-list-item/index.js b/node_modules/micromark-extension-gfm-task-list-item/index.js new file mode 100644 index 0000000000000000000000000000000000000000..b7d19c142b4c76efae7a6142ddf47d9a4ed49bd7 --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/index.js @@ -0,0 +1,2 @@ +export { gfmTaskListItemHtml } from './lib/html.js'; +export { gfmTaskListItem } from './lib/syntax.js'; \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-task-list-item/lib/html.d.ts b/node_modules/micromark-extension-gfm-task-list-item/lib/html.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..77a83bdaf606d940ec9151dcae16356f12027b21 --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/lib/html.d.ts @@ -0,0 +1,13 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ +/** + * Create an HTML extension for `micromark` to support GFM task list items when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM task list items when serializing to HTML. + */ +export function gfmTaskListItemHtml(): HtmlExtension; +import type { HtmlExtension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-task-list-item/lib/html.js b/node_modules/micromark-extension-gfm-task-list-item/lib/html.js new file mode 100644 index 0000000000000000000000000000000000000000..a611f71bbe9f7cd59a2ffae85b8d546cf7b6055d --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/lib/html.js @@ -0,0 +1,29 @@ +/** + * @import {HtmlExtension} from 'micromark-util-types' + */ + +/** + * Create an HTML extension for `micromark` to support GFM task list items when + * serializing to HTML. + * + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM task list items when serializing to HTML. + */ +export function gfmTaskListItemHtml() { + return { + enter: { + taskListCheck() { + this.tag(''); + }, + taskListCheckValueChecked() { + this.tag('checked="" '); + } + } + }; +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-task-list-item/lib/syntax.d.ts b/node_modules/micromark-extension-gfm-task-list-item/lib/syntax.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3ffb821e47543ebe4a435cc20aac30e748027438 --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/lib/syntax.d.ts @@ -0,0 +1,10 @@ +/** + * Create an HTML extension for `micromark` to support GFM task list items + * syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM task list items when serializing to HTML. + */ +export function gfmTaskListItem(): Extension; +import type { Extension } from 'micromark-util-types'; diff --git a/node_modules/micromark-extension-gfm-task-list-item/lib/syntax.js b/node_modules/micromark-extension-gfm-task-list-item/lib/syntax.js new file mode 100644 index 0000000000000000000000000000000000000000..0e1eeaff8ea9df6393ca8f07c09cc89482b72a89 --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/lib/syntax.js @@ -0,0 +1,158 @@ +/** + * @import {Extension, State, TokenizeContext, Tokenizer} from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding, markdownLineEndingOrSpace, markdownSpace } from 'micromark-util-character'; +const tasklistCheck = { + name: 'tasklistCheck', + tokenize: tokenizeTasklistCheck +}; + +/** + * Create an HTML extension for `micromark` to support GFM task list items + * syntax. + * + * @returns {Extension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM task list items when serializing to HTML. + */ +export function gfmTaskListItem() { + return { + text: { + [91]: tasklistCheck + } + }; +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function tokenizeTasklistCheck(effects, ok, nok) { + const self = this; + return open; + + /** + * At start of task list item check. + * + * ```markdown + * > | * [x] y. + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if ( + // Exit if there’s stuff before. + self.previous !== null || + // Exit if not in the first content that is the first child of a list + // item. + !self._gfmTasklistFirstContentOfListItem) { + return nok(code); + } + effects.enter('taskListCheck'); + effects.enter('taskListCheckMarker'); + effects.consume(code); + effects.exit('taskListCheckMarker'); + return inside; + } + + /** + * In task list item check. + * + * ```markdown + * > | * [x] y. + * ^ + * ``` + * + * @type {State} + */ + function inside(code) { + // Currently we match how GH works in files. + // To match how GH works in comments, use `markdownSpace` (`[\t ]`) instead + // of `markdownLineEndingOrSpace` (`[\t\n\r ]`). + if (markdownLineEndingOrSpace(code)) { + effects.enter('taskListCheckValueUnchecked'); + effects.consume(code); + effects.exit('taskListCheckValueUnchecked'); + return close; + } + if (code === 88 || code === 120) { + effects.enter('taskListCheckValueChecked'); + effects.consume(code); + effects.exit('taskListCheckValueChecked'); + return close; + } + return nok(code); + } + + /** + * At close of task list item check. + * + * ```markdown + * > | * [x] y. + * ^ + * ``` + * + * @type {State} + */ + function close(code) { + if (code === 93) { + effects.enter('taskListCheckMarker'); + effects.consume(code); + effects.exit('taskListCheckMarker'); + effects.exit('taskListCheck'); + return after; + } + return nok(code); + } + + /** + * @type {State} + */ + function after(code) { + // EOL in paragraph means there must be something else after it. + if (markdownLineEnding(code)) { + return ok(code); + } + + // Space or tab? + // Check what comes after. + if (markdownSpace(code)) { + return effects.check({ + tokenize: spaceThenNonSpace + }, ok, nok)(code); + } + + // EOF, or non-whitespace, both wrong. + return nok(code); + } +} + +/** + * @this {TokenizeContext} + * @type {Tokenizer} + */ +function spaceThenNonSpace(effects, ok, nok) { + return factorySpace(effects, after, "whitespace"); + + /** + * After whitespace, after task list item check. + * + * ```markdown + * > | * [x] y. + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + // EOF means there was nothing, so bad. + // EOL means there’s content after it, so good. + // Impossible to have more spaces. + // Anything else is good. + return code === null ? nok(code) : ok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-extension-gfm-task-list-item/license b/node_modules/micromark-extension-gfm-task-list-item/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/micromark-extension-gfm-task-list-item/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark-extension-gfm/index.d.ts b/node_modules/micromark-extension-gfm/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8fdf19672fc8864d0bc7a917b25ecde1f41295cb --- /dev/null +++ b/node_modules/micromark-extension-gfm/index.d.ts @@ -0,0 +1,28 @@ +/** + * Create an extension for `micromark` to enable GFM syntax. + * + * @param {Options | null | undefined} [options] + * Configuration (optional). + * + * Passed to `micromark-extens-gfm-strikethrough`. + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * syntax. + */ +export function gfm(options?: Options | null | undefined): Extension +/** + * Create an extension for `micromark` to support GFM when serializing to HTML. + * + * @param {HtmlOptions | null | undefined} [options] + * Configuration (optional). + * + * Passed to `micromark-extens-gfm-footnote`. + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM when serializing to HTML. + */ +export function gfmHtml(options?: HtmlOptions | null | undefined): HtmlExtension +export type HtmlOptions = import('micromark-extension-gfm-footnote').HtmlOptions +export type Options = import('micromark-extension-gfm-strikethrough').Options +export type Extension = import('micromark-util-types').Extension +export type HtmlExtension = import('micromark-util-types').HtmlExtension diff --git a/node_modules/micromark-extension-gfm/index.js b/node_modules/micromark-extension-gfm/index.js new file mode 100644 index 0000000000000000000000000000000000000000..839e7358e65a80363c0b46ffa0a8899e91ff6b43 --- /dev/null +++ b/node_modules/micromark-extension-gfm/index.js @@ -0,0 +1,69 @@ +/** + * @typedef {import('micromark-extension-gfm-footnote').HtmlOptions} HtmlOptions + * @typedef {import('micromark-extension-gfm-strikethrough').Options} Options + * @typedef {import('micromark-util-types').Extension} Extension + * @typedef {import('micromark-util-types').HtmlExtension} HtmlExtension + */ + +import { + combineExtensions, + combineHtmlExtensions +} from 'micromark-util-combine-extensions' +import { + gfmAutolinkLiteral, + gfmAutolinkLiteralHtml +} from 'micromark-extension-gfm-autolink-literal' +import {gfmFootnote, gfmFootnoteHtml} from 'micromark-extension-gfm-footnote' +import { + gfmStrikethrough, + gfmStrikethroughHtml +} from 'micromark-extension-gfm-strikethrough' +import {gfmTable, gfmTableHtml} from 'micromark-extension-gfm-table' +import {gfmTagfilterHtml} from 'micromark-extension-gfm-tagfilter' +import { + gfmTaskListItem, + gfmTaskListItemHtml +} from 'micromark-extension-gfm-task-list-item' + +/** + * Create an extension for `micromark` to enable GFM syntax. + * + * @param {Options | null | undefined} [options] + * Configuration (optional). + * + * Passed to `micromark-extens-gfm-strikethrough`. + * @returns {Extension} + * Extension for `micromark` that can be passed in `extensions` to enable GFM + * syntax. + */ +export function gfm(options) { + return combineExtensions([ + gfmAutolinkLiteral(), + gfmFootnote(), + gfmStrikethrough(options), + gfmTable(), + gfmTaskListItem() + ]) +} + +/** + * Create an extension for `micromark` to support GFM when serializing to HTML. + * + * @param {HtmlOptions | null | undefined} [options] + * Configuration (optional). + * + * Passed to `micromark-extens-gfm-footnote`. + * @returns {HtmlExtension} + * Extension for `micromark` that can be passed in `htmlExtensions` to + * support GFM when serializing to HTML. + */ +export function gfmHtml(options) { + return combineHtmlExtensions([ + gfmAutolinkLiteralHtml(), + gfmFootnoteHtml(options), + gfmStrikethroughHtml(), + gfmTableHtml(), + gfmTagfilterHtml(), + gfmTaskListItemHtml() + ]) +} diff --git a/node_modules/micromark-extension-gfm/license b/node_modules/micromark-extension-gfm/license new file mode 100644 index 0000000000000000000000000000000000000000..39372356c47d0f6e070ff62d84c69f4f5e8c16eb --- /dev/null +++ b/node_modules/micromark-extension-gfm/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) 2020 Titus Wormer + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark-extension-gfm/package.json b/node_modules/micromark-extension-gfm/package.json new file mode 100644 index 0000000000000000000000000000000000000000..11c014f89e01863a30e830588cd2eb7e118f92f3 --- /dev/null +++ b/node_modules/micromark-extension-gfm/package.json @@ -0,0 +1,107 @@ +{ + "name": "micromark-extension-gfm", + "version": "3.0.0", + "description": "micromark extension to support GFM (GitHub Flavored Markdown)", + "license": "MIT", + "keywords": [ + "micromark", + "micromark-extension", + "table", + "strikethrough", + "tasklist", + "autolink", + "footnote", + "tagfilter", + "github", + "gfm", + "markdown", + "unified" + ], + "repository": "micromark/micromark-extension-gfm", + "bugs": "https://github.com/micromark/micromark-extension-gfm/issues", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/unified" + }, + "author": "Titus Wormer (https://wooorm.com)", + "contributors": [ + "Titus Wormer (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "exports": "./index.js", + "files": [ + "index.d.ts", + "index.js" + ], + "dependencies": { + "micromark-extension-gfm-autolink-literal": "^2.0.0", + "micromark-extension-gfm-footnote": "^2.0.0", + "micromark-extension-gfm-strikethrough": "^2.0.0", + "micromark-extension-gfm-table": "^2.0.0", + "micromark-extension-gfm-tagfilter": "^2.0.0", + "micromark-extension-gfm-task-list-item": "^2.0.0", + "micromark-util-combine-extensions": "^2.0.0", + "micromark-util-types": "^2.0.0" + }, + "devDependencies": { + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "create-gfm-fixtures": "^1.0.0", + "hast-util-from-html": "^1.0.0", + "hast-util-select": "^5.0.0", + "hast-util-to-text": "^3.0.0", + "micromark": "^4.0.0", + "prettier": "^2.0.0", + "rehype": "^12.0.0", + "rehype-sort-attributes": "^4.0.0", + "remark-cli": "^11.0.0", + "remark-preset-wooorm": "^9.0.0", + "type-coverage": "^2.0.0", + "typescript": "^5.0.0", + "undici": "^5.0.0", + "xo": "^0.54.0" + }, + "scripts": { + "prepack": "npm run build && npm run format", + "build": "tsc --build --clean && tsc --build && type-coverage", + "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "test-api-prod": "node --conditions production test/index.js", + "test-api-dev": "node --conditions development test/index.js", + "test-api": "npm run test-api-dev && npm run test-api-prod", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", + "test": "npm run build && npm run format && npm run test-coverage" + }, + "prettier": { + "bracketSpacing": false, + "semi": false, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false + }, + "remarkConfig": { + "plugins": [ + "remark-preset-wooorm" + ] + }, + "typeCoverage": { + "atLeast": 100, + "detail": true, + "ignoreCatch": true, + "strict": true + }, + "xo": { + "prettier": true, + "overrides": [ + { + "files": [ + "{test,script}/**/*.js" + ], + "rules": { + "no-await-in-loop": "off" + } + } + ] + } +} diff --git a/node_modules/micromark-extension-gfm/readme.md b/node_modules/micromark-extension-gfm/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..d569a19ac040dae70aab269e7ee1bbe5c631ea50 --- /dev/null +++ b/node_modules/micromark-extension-gfm/readme.md @@ -0,0 +1,433 @@ +# micromark-extension-gfm + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][size-badge]][size] +[![Sponsors][sponsors-badge]][collective] +[![Backers][backers-badge]][collective] +[![Chat][chat-badge]][chat] + +[micromark][] extensions to support [GitHub flavored markdown][gfm] (GFM). + +## Contents + +* [What is this?](#what-is-this) +* [When to use this](#when-to-use-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`gfm(options?)`](#gfmoptions) + * [`gfmHtml(options?)`](#gfmhtmloptions) + * [`Options`](#options) + * [`HtmlOptions`](#htmloptions) +* [Bugs](#bugs) +* [Authoring](#authoring) +* [HTML](#html) +* [CSS](#css) +* [Syntax](#syntax) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Contribute](#contribute) +* [License](#license) + +## What is this? + +This package contains extensions that add support for all features enabled by +GFM to [`micromark`][micromark]. +It supports autolink literals, footnotes, strikethrough, tables, tagfilter, and +tasklists. + +## When to use this + +This project is useful when you want to support GFM in markdown. + +You can use these extensions when you are working with [`micromark`][micromark]. +Alternatively, you can also use the underlying features separately: + +* [`micromark-extension-gfm-autolink-literal`][gfm-autolink-literal] + — support GFM [autolink literals][] +* [`micromark-extension-gfm-footnote`][gfm-footnote] + — support GFM [footnotes][] +* [`micromark-extension-gfm-strikethrough`][gfm-strikethrough] + — support GFM [strikethrough][] +* [`micromark-extension-gfm-table`][gfm-table] + — support GFM [tables][] +* [`micromark-extension-gfm-tagfilter`][gfm-tagfilter] + — support GFM [tagfilter][] +* [`micromark-extension-gfm-task-list-item`][gfm-task-list-item] + — support GFM [tasklists][] + +When you need a syntax tree, combine this package with +[`mdast-util-gfm`][mdast-util-gfm]. + +All these packages are used in [`remark-gfm`][remark-gfm], which focusses on +making it easier to transform content by abstracting these internals away. + +## Install + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install micromark-extension-gfm +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {gfm, gfmHtml} from 'https://esm.sh/micromark-extension-gfm@3' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html + +``` + +## Use + +Say our document `example.md` contains: + +```markdown +# GFM + +## Autolink literals + +www.example.com, https://example.com, and contact@example.com. + +## Footnote + +A note[^1] + +[^1]: Big note. + +## Strikethrough + +~one~ or ~~two~~ tildes. + +## Table + +| a | b | c | d | +| - | :- | -: | :-: | + +## Tag filter + + + +## Tasklist + +* [ ] to do +* [x] done +``` + +…and our module `example.js` looks as follows: + +```js +import fs from 'node:fs/promises' +import {micromark} from 'micromark' +import {gfm, gfmHtml} from 'micromark-extension-gfm' + +const output = micromark(await fs.readFile('example.md'), { + allowDangerousHtml: true, + extensions: [gfm()], + htmlExtensions: [gfmHtml()] +}) + +console.log(output) +``` + +…now running `node example.js` yields: + +```html +<h1>GFM</h1> +<h2>Autolink literals</h2> +<p><a href="http://www.example.com">www.example.com</a>, <a href="https://example.com">https://example.com</a>, and <a href="mailto:contact@example.com">contact@example.com</a>.</p> +<h2>Footnote</h2> +<p>A note<sup><a href="#user-content-fn-1" id="user-content-fnref-1" data-footnote-ref="" aria-describedby="footnote-label">1</a></sup></p> +<h2>Strikethrough</h2> +<p><del>one</del> or <del>two</del> tildes.</p> +<h2>Table</h2> +<table> +<thead> +<tr> +<th>a</th> +<th align="left">b</th> +<th align="right">c</th> +<th align="center">d</th> +</tr> +</thead> +</table> +<h2>Tag filter</h2> +&lt;plaintext> +<h2>Tasklist</h2> +<ul> +<li><input type="checkbox" disabled="" /> to do</li> +<li><input type="checkbox" disabled="" checked="" /> done</li> +</ul> +<section data-footnotes="" class="footnotes"><h2 id="footnote-label" class="sr-only">Footnotes</h2> +<ol> +<li id="user-content-fn-1"> +<p>Big note. <a href="#user-content-fnref-1" data-footnote-backref="" class="data-footnote-backref" aria-label="Back to content">↩</a></p> +</li> +</ol> +</section> +``` + +## API + +This package exports the identifiers [`gfm`][api-gfm] and +[`gfmHtml`][api-gfm-html]. +There is no default export. + +The separate extensions support the [`development` condition][development]. +Run `node --conditions development module.js` to get instrumented dev code. +Without this condition, production code is loaded. + +### `gfm(options?)` + +Create an extension for `micromark` to enable GFM syntax. + +###### Parameters + +* `options` ([`Options`][api-options], optional) + — configuration; passed to + [`micromark-extens-gfm-strikethrough`][gfm-strikethrough-options] + +###### Returns + +Extension for `micromark` that can be passed in `extensions` to enable GFM +syntax ([`Extension`][micromark-extension]). + +### `gfmHtml(options?)` + +Create an extension for `micromark` to support GFM when serializing to HTML. + +###### Parameters + +* `options` ([`HtmlOptions`][api-html-options], optional) + — configuration; passed to + [`micromark-extens-gfm-footnote`][gfm-footnote-html-options] + +###### Returns + +Extension for `micromark` that can be passed in `htmlExtensions` to support GFM +when serializing to HTML ([`HtmlExtension`][micromark-html-extension]). + +### `Options` + +Configuration for syntax (TypeScript type). + +###### Type + +```ts +export type {Options} from 'micromark-extension-gfm-strikethrough' +``` + +[See `Options`][gfm-strikethrough-options]. + +### `HtmlOptions` + +Configuration for HTML (TypeScript type). + +###### Type + +```ts +export type {HtmlOptions} from 'micromark-extension-gfm-footnote' +``` + +[See `HtmlOptions`][gfm-footnote-html-options]. + +## Bugs + +For bugs present in GFM but not here, or other peculiarities that are +supported, see each corresponding readme: + +* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#bugs) +* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#bugs) +* strikethrough: n/a +* [table](https://github.com/micromark/micromark-extension-gfm-table#bugs) +* tagfilter: n/a +* tasklists: n/a + +## Authoring + +For recommendations on how to author GFM, see each corresponding readme: + +* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#authoring) +* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#authoring) +* [strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough#authoring) +* [table](https://github.com/micromark/micromark-extension-gfm-table#authoring) +* tagfilter: n/a +* [tasklists](https://github.com/micromark/micromark-extension-gfm-task-list-item#authoring) + +## HTML + +For info on what HTML features GFM relates to, see each corresponding readme: + +* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#html) +* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#html) +* [strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough#html) +* [table](https://github.com/micromark/micromark-extension-gfm-table#html) +* [tagfilter](https://github.com/micromark/micromark-extension-gfm-tagfilter#html) +* [tasklists](https://github.com/micromark/micromark-extension-gfm-task-list-item#html) + +## CSS + +For info on how GitHub styles these features, see each corresponding readme: + +* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#css) +* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#css) +* [strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough#css) +* [table](https://github.com/micromark/micromark-extension-gfm-table#css) +* tagfilter: n/a +* [tasklists](https://github.com/micromark/micromark-extension-gfm-task-list-item#css) + +## Syntax + +For info on the syntax of these features, see each corresponding readme: + +* [autolink literal](https://github.com/micromark/micromark-extension-gfm-autolink-literal#syntax) +* [footnote](https://github.com/micromark/micromark-extension-gfm-footnote#syntax) +* [strikethrough](https://github.com/micromark/micromark-extension-gfm-strikethrough#syntax) +* [table](https://github.com/micromark/micromark-extension-gfm-table#syntax) +* tagfilter: n/a +* [tasklists](https://github.com/micromark/micromark-extension-gfm-task-list-item#syntax) + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional types [`HtmlOptions`][api-html-options] and +[`Options`][api-options]. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, +`micromark-extension-gfm@^3`, compatible with Node.js 16. + +This package works with `micromark` version `3` and later. + +## Security + +This package is safe. +Setting `clobberPrefix = ''` is dangerous, it opens you up to DOM clobbering. +The `labelTagName` and `labelAttributes` options are unsafe when used with user +content, they allow defining arbitrary HTML. + +## Contribute + +See [`contributing.md` in `micromark/.github`][contributing] for ways to get +started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organization, or community you agree to +abide by its terms. + +## License + +[MIT][license] © [Titus Wormer][author] + +<!-- Definitions --> + +[build-badge]: https://github.com/micromark/micromark-extension-gfm/workflows/main/badge.svg + +[build]: https://github.com/micromark/micromark-extension-gfm/actions + +[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark-extension-gfm.svg + +[coverage]: https://codecov.io/github/micromark/micromark-extension-gfm + +[downloads-badge]: https://img.shields.io/npm/dm/micromark-extension-gfm.svg + +[downloads]: https://www.npmjs.com/package/micromark-extension-gfm + +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark-extension-gfm + +[size]: https://bundlejs.com/?q=micromark-extension-gfm + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[collective]: https://opencollective.com/unified + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[chat]: https://github.com/micromark/micromark/discussions + +[npm]: https://docs.npmjs.com/cli/install + +[esmsh]: https://esm.sh + +[license]: license + +[author]: https://wooorm.com + +[contributing]: https://github.com/micromark/.github/blob/main/contributing.md + +[support]: https://github.com/micromark/.github/blob/main/support.md + +[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions + +[typescript]: https://www.typescriptlang.org + +[gfm]: https://github.github.com/gfm/ + +[strikethrough]: https://github.github.com/gfm/#strikethrough-extension- + +[tables]: https://github.github.com/gfm/#tables-extension- + +[tasklists]: https://github.github.com/gfm/#task-list-items-extension- + +[autolink literals]: https://github.github.com/gfm/#autolinks-extension- + +[tagfilter]: https://github.github.com/gfm/#disallowed-raw-html-extension- + +[footnotes]: https://github.blog/changelog/2021-09-30-footnotes-now-supported-in-markdown-fields/ + +[micromark]: https://github.com/micromark/micromark + +[micromark-extension]: https://github.com/micromark/micromark#syntaxextension + +[micromark-html-extension]: https://github.com/micromark/micromark#htmlextension + +[gfm-strikethrough]: https://github.com/micromark/micromark-extension-gfm-strikethrough + +[gfm-strikethrough-options]: https://github.com/micromark/micromark-extension-gfm-strikethrough#options + +[gfm-autolink-literal]: https://github.com/micromark/micromark-extension-gfm-autolink-literal + +[gfm-footnote]: https://github.com/micromark/micromark-extension-gfm-footnote + +[gfm-footnote-html-options]: https://github.com/micromark/micromark-extension-gfm-footnote#htmloptions + +[gfm-table]: https://github.com/micromark/micromark-extension-gfm-table + +[gfm-tagfilter]: https://github.com/micromark/micromark-extension-gfm-tagfilter + +[gfm-task-list-item]: https://github.com/micromark/micromark-extension-gfm-task-list-item + +[remark-gfm]: https://github.com/remarkjs/remark-gfm + +[mdast-util-gfm]: https://github.com/syntax-tree/mdast-util-gfm + +[api-gfm]: #gfmoptions + +[api-gfm-html]: #gfmhtmloptions + +[api-options]: #options + +[api-html-options]: #htmloptions diff --git a/node_modules/micromark/lib/preprocess.d.ts.map b/node_modules/micromark/lib/preprocess.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..a916e156f1b758f81de4570424117b7f70218886 --- /dev/null +++ b/node_modules/micromark/lib/preprocess.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"preprocess.d.ts","sourceRoot":"","sources":["preprocess.js"],"names":[],"mappings":"AAqBA;;;GAGG;AACH,8BAHa,YAAY,CAsHxB;;;;mCArIU,KAAK,aAEL,QAAQ,GAAG,IAAI,GAAG,SAAS,QAE3B,OAAO,GAAG,IAAI,GAAG,SAAS,KAExB,KAAK,CAAC,KAAK,CAAC;2BAZsB,sBAAsB;8BAAtB,sBAAsB;2BAAtB,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark/lib/preprocess.js b/node_modules/micromark/lib/preprocess.js new file mode 100644 index 0000000000000000000000000000000000000000..2cd2d442ca72df285276bc19d9f8ec7cf915fe4f --- /dev/null +++ b/node_modules/micromark/lib/preprocess.js @@ -0,0 +1,115 @@ +/** + * @import {Chunk, Code, Encoding, Value} from 'micromark-util-types' + */ + +/** + * @callback Preprocessor + * Preprocess a value. + * @param {Value} value + * Value. + * @param {Encoding | null | undefined} [encoding] + * Encoding when `value` is a typed array (optional). + * @param {boolean | null | undefined} [end=false] + * Whether this is the last chunk (default: `false`). + * @returns {Array<Chunk>} + * Chunks. + */ + +const search = /[\0\t\n\r]/g; + +/** + * @returns {Preprocessor} + * Preprocess a value. + */ +export function preprocess() { + let column = 1; + let buffer = ''; + /** @type {boolean | undefined} */ + let start = true; + /** @type {boolean | undefined} */ + let atCarriageReturn; + return preprocessor; + + /** @type {Preprocessor} */ + // eslint-disable-next-line complexity + function preprocessor(value, encoding, end) { + /** @type {Array<Chunk>} */ + const chunks = []; + /** @type {RegExpMatchArray | null} */ + let match; + /** @type {number} */ + let next; + /** @type {number} */ + let startPosition; + /** @type {number} */ + let endPosition; + /** @type {Code} */ + let code; + value = buffer + (typeof value === 'string' ? value.toString() : new TextDecoder(encoding || undefined).decode(value)); + startPosition = 0; + buffer = ''; + if (start) { + // To do: `markdown-rs` actually parses BOMs (byte order mark). + if (value.charCodeAt(0) === 65279) { + startPosition++; + } + start = undefined; + } + while (startPosition < value.length) { + search.lastIndex = startPosition; + match = search.exec(value); + endPosition = match && match.index !== undefined ? match.index : value.length; + code = value.charCodeAt(endPosition); + if (!match) { + buffer = value.slice(startPosition); + break; + } + if (code === 10 && startPosition === endPosition && atCarriageReturn) { + chunks.push(-3); + atCarriageReturn = undefined; + } else { + if (atCarriageReturn) { + chunks.push(-5); + atCarriageReturn = undefined; + } + if (startPosition < endPosition) { + chunks.push(value.slice(startPosition, endPosition)); + column += endPosition - startPosition; + } + switch (code) { + case 0: + { + chunks.push(65533); + column++; + break; + } + case 9: + { + next = Math.ceil(column / 4) * 4; + chunks.push(-2); + while (column++ < next) chunks.push(-1); + break; + } + case 10: + { + chunks.push(-4); + column = 1; + break; + } + default: + { + atCarriageReturn = true; + column = 1; + } + } + } + startPosition = endPosition + 1; + } + if (end) { + if (atCarriageReturn) chunks.push(-5); + if (buffer) chunks.push(buffer); + chunks.push(null); + } + return chunks; + } +} \ No newline at end of file diff --git a/node_modules/micromark/license b/node_modules/micromark/license new file mode 100644 index 0000000000000000000000000000000000000000..bc8f165a62768a19de38901d81ac662c51ff29db --- /dev/null +++ b/node_modules/micromark/license @@ -0,0 +1,22 @@ +(The MIT License) + +Copyright (c) Titus Wormer <tituswormer@gmail.com> + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +'Software'), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/micromark/package.json b/node_modules/micromark/package.json new file mode 100644 index 0000000000000000000000000000000000000000..c1c00e880137758d0ba9c2d000182354272366af --- /dev/null +++ b/node_modules/micromark/package.json @@ -0,0 +1,100 @@ +{ + "name": "micromark", + "version": "4.0.2", + "description": "small commonmark compliant markdown parser with positional info and concrete tokens", + "license": "MIT", + "keywords": [ + "commonmark", + "compiler", + "gfm", + "html", + "lexer", + "markdown", + "markup", + "md", + "unified", + "parse", + "parser", + "plugin", + "process", + "remark", + "render", + "renderer", + "token", + "tokenizer" + ], + "repository": "https://github.com/micromark/micromark/tree/main/packages/micromark", + "bugs": "https://github.com/micromark/micromark/issues", + "funding": [ + { + "type": "GitHub Sponsors", + "url": "https://github.com/sponsors/unifiedjs" + }, + { + "type": "OpenCollective", + "url": "https://opencollective.com/unified" + } + ], + "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)", + "contributors": [ + "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" + ], + "sideEffects": false, + "type": "module", + "files": [ + "dev/", + "lib/", + "index.d.ts.map", + "index.d.ts", + "index.js", + "stream.d.ts.map", + "stream.d.ts", + "stream.js" + ], + "exports": { + ".": { + "development": "./dev/index.js", + "default": "./index.js" + }, + "./stream": { + "development": "./dev/stream.js", + "default": "./stream.js" + } + }, + "dependencies": { + "@types/debug": "^4.0.0", + "debug": "^4.0.0", + "decode-named-character-reference": "^1.0.0", + "devlop": "^1.0.0", + "micromark-core-commonmark": "^2.0.0", + "micromark-factory-space": "^2.0.0", + "micromark-util-character": "^2.0.0", + "micromark-util-chunked": "^2.0.0", + "micromark-util-combine-extensions": "^2.0.0", + "micromark-util-decode-numeric-character-reference": "^2.0.0", + "micromark-util-encode": "^2.0.0", + "micromark-util-normalize-identifier": "^2.0.0", + "micromark-util-resolve-all": "^2.0.0", + "micromark-util-sanitize-uri": "^2.0.0", + "micromark-util-subtokenize": "^2.0.0", + "micromark-util-symbol": "^2.0.0", + "micromark-util-types": "^2.0.0" + }, + "scripts": { + "build": "micromark-build" + }, + "xo": { + "envs": [ + "shared-node-browser" + ], + "prettier": true, + "rules": { + "logical-assignment-operators": "off", + "max-depth": "off", + "unicorn/no-this-assignment": "off", + "unicorn/prefer-at": "off", + "unicorn/prefer-code-point": "off", + "unicorn/prefer-event-target": "off" + } + } +} diff --git a/node_modules/micromark/readme.md b/node_modules/micromark/readme.md new file mode 100644 index 0000000000000000000000000000000000000000..43ee49383006e71eccf4c482aa1bb31dcd85df8e --- /dev/null +++ b/node_modules/micromark/readme.md @@ -0,0 +1,488 @@ +# micromark + +[![Build][build-badge]][build] +[![Coverage][coverage-badge]][coverage] +[![Downloads][downloads-badge]][downloads] +[![Size][bundle-size-badge]][bundle-size] +[![Sponsors][sponsors-badge]][opencollective] +[![Backers][backers-badge]][opencollective] +[![Chat][chat-badge]][chat] + +Markdown parser. + +> **Note**: this is the `micromark` package from the micromark monorepo. +> See the [monorepo readme][micromark] for more on the project. +> See this readme for how to use it. + +## Feature highlights + +<!-- Note: this section has to be in sync with the monorepo readme. --> + +* [x] **[compliant][commonmark]** (100% to CommonMark) +* [x] **[extensions][]** (100% [GFM][], 100% [MDX.js][mdxjs], [directives][], + [frontmatter][], [math][]) +* [x] **[safe][security]** (by default) +* [x] **[robust][test]** (±2k tests, 100% coverage, fuzz testing) +* [x] **[small][size-debug]** (smallest CM parser at ±14kb) + +## Contents + +* [When should I use this?](#when-should-i-use-this) +* [What is this?](#what-is-this) +* [Install](#install) +* [Use](#use) +* [API](#api) + * [`micromark(value[, encoding][, options])`](#micromarkvalue-encoding-options) + * [`stream(options?)`](#streamoptions) + * [`Options`](#options) +* [Types](#types) +* [Compatibility](#compatibility) +* [Security](#security) +* [Contribute](#contribute) +* [Sponsor](#sponsor) +* [License](#license) + +## When should I use this? + +<!-- Note: this section has to be in sync with the monorepo readme. --> + +* If you *just* want to turn markdown into HTML (with maybe a few extensions) +* If you want to do *really complex things* with markdown + +See [§ Comparison][comparison] for more info + +## What is this? + +<!-- Note: this section has to be in sync with the monorepo readme. --> + +`micromark` is an open source markdown parser written in JavaScript. +It’s implemented as a state machine that emits concrete tokens, so that every +byte is accounted for, with positional info. +It then compiles those tokens directly to HTML, but other tools can take the +data and for example build an AST which is easier to work with +([`mdast-util-to-markdown`][mdast-util-to-markdown]). + +While most markdown parsers work towards compliancy with CommonMark (or GFM), +this project goes further by following how the reference parsers (`cmark`, +`cmark-gfm`) work, which is confirmed with thousands of extra tests. + +Other than CommonMark and GFM, micromark also supports common extensions to +markdown such as MDX, math, and frontmatter. + +These npm packages have a sibling project in Rust: +[`markdown-rs`][markdown-rs]. + +* to learn markdown, see this [cheatsheet and tutorial][cheat] +* for more about us, see [`unifiedjs.com`][site] +* for questions, see [Discussions][chat] +* to help, see [contribute][] and [sponsor][] below + +## Install + +<!-- Note: this section has to be in sync with the monorepo readme. --> + +This package is [ESM only][esm]. +In Node.js (version 16+), install with [npm][]: + +```sh +npm install micromark +``` + +In Deno with [`esm.sh`][esmsh]: + +```js +import {micromark} from 'https://esm.sh/micromark@3' +``` + +In browsers with [`esm.sh`][esmsh]: + +```html +<script type="module"> + import {micromark} from 'https://esm.sh/micromark@3?bundle' +</script> +``` + +## Use + +<!-- Note: this section has to be in sync with the `micromark` readme. --> + +Typical use (buffering): + +```js +import {micromark} from 'micromark' + +console.log(micromark('## Hello, *world*!')) +``` + +Yields: + +```html +<h2>Hello, <em>world</em>!</h2> +``` + +You can pass extensions (in this case [`micromark-extension-gfm`][gfm]): + +```js +import {micromark} from 'micromark' +import {gfmHtml, gfm} from 'micromark-extension-gfm' + +const value = '* [x] contact@example.com ~~strikethrough~~' + +const result = micromark(value, { + extensions: [gfm()], + htmlExtensions: [gfmHtml()] +}) + +console.log(result) +``` + +Yields: + +```html +<ul> +<li><input checked="" disabled="" type="checkbox"> <a href="mailto:contact@example.com">contact@example.com</a> <del>strikethrough</del></li> +</ul> +``` + +Streaming interface: + +```js +import {createReadStream} from 'node:fs' +import {stream} from 'micromark/stream' + +createReadStream('example.md') + .on('error', handleError) + .pipe(stream()) + .pipe(process.stdout) + +function handleError(error) { + // Handle your error here! + throw error +} +``` + +## API + +`micromark` core has two entries in its export map: `micromark` and +`micromark/stream`. + +`micromark` exports the identifier [`micromark`][api-micromark]. +`micromark/stream` exports the identifier [`stream`][api-stream]. +There are no default exports. + +The export map supports the [`development` condition][development]. +Run `node --conditions development module.js` to get instrumented dev code. +Without this condition, production code is loaded. +See [§ Size & debug][size-debug] for more info. + +### `micromark(value[, encoding][, options])` + +Compile markdown to HTML. + +> Note: which encodings are supported depends on the engine. +> For info on Node.js, see *[WHATWG supported encodings][encoding]*. + +###### Parameters + +* `value` (`string` or [`Uint8Array`][uint8-array]) + — markdown to parse +* `encoding` (`string`, default: `'utf8'`) + — [character encoding][encoding] to understand `value` as when it’s a + [`Uint8Array`][uint8-array] +* `options` ([`Options`][api-options], optional) + — configuration + +###### Returns + +Compiled HTML (`string`). + +### `stream(options?)` + +Create a duplex (readable and writable) stream. + +Some of the work to parse markdown can be done streaming, but in the +end buffering is required. + +micromark does not handle errors for you, so you must handle errors on whatever +streams you pipe into it. +As markdown does not know errors, `micromark` itself does not emit errors. + +###### Parameters + +* `options` ([`Options`][api-options], optional) + — configuration + +###### Returns + +Duplex stream. + +### `Options` + +Configuration (TypeScript type). + +##### Fields + +###### `allowDangerousHtml` + +Whether to allow (dangerous) HTML (`boolean`, default: `false`). + +The default is `false`, which still parses the HTML according to `CommonMark` +but shows the HTML as text instead of as elements. + +Pass `true` for trusted content to get actual HTML elements. +See [§ Security][security]. + +###### `allowDangerousProtocol` + +Whether to allow dangerous protocols in links and images (`boolean`, default: +`false`). + +The default is `false`, which drops URLs in links and images that use dangerous +protocols. + +Pass `true` for trusted content to support all protocols. + +URLs that have no protocol (which means it’s relative to the current page, such +as `./some/page.html`) and URLs that have a safe protocol (for images: `http`, +`https`; for links: `http`, `https`, `irc`, `ircs`, `mailto`, `xmpp`), are +safe. +All other URLs are dangerous and dropped. +See [§ Security][security]. + +###### `defaultLineEnding` + +Default line ending to use when compiling to HTML, for line endings not in +`value` (`'\r'`, `'\n'`, or `'\r\n'`; default: first line ending or `'\n'`). + +Generally, `micromark` copies line endings (`\r`, `\n`, `\r\n`) in the markdown +document over to the compiled HTML. +In some cases, such as `> a`, CommonMark requires that extra line endings are +added: `<blockquote>\n<p>a</p>\n</blockquote>`. + +To create that line ending, the document is checked for the first line ending +that is used. +If there is no line ending, `defaultLineEnding` is used. +If that isn’t configured, `\n` is used. + +###### `extensions` + +Array of syntax extensions (`Array<SyntaxExtension>`, default: `[]`). +See [§ Extensions][extensions]. + +###### `htmlExtensions` + +Array of syntax extensions (`Array<HtmlExtension>`, default: `[]`). +See [§ Extensions][extensions]. + +## Types + +This package is fully typed with [TypeScript][]. +It exports the additional type [`Options`][api-options]. + +## Compatibility + +Projects maintained by the unified collective are compatible with maintained +versions of Node.js. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `micromark@4`, compatible +with Node.js 16. + +## Security + +This package is safe. +See [`security.md`][securitymd] in [`micromark/.github`][health] for how to +submit a security report. + +## Contribute + +See [`contributing.md`][contributing] in [`micromark/.github`][health] for ways +to get started. +See [`support.md`][support] for ways to get help. + +This project has a [code of conduct][coc]. +By interacting with this repository, organisation, or community you agree to +abide by its terms. + +## Sponsor + +<!-- Note: this section has to be in sync with the monorepo readme. --> + +Support this effort and give back by sponsoring on [OpenCollective][]! + +<table> +<tr valign="middle"> +<td width="100%" align="center" colspan="10"> + <br> + <a href="https://www.salesforce.com">Salesforce</a> 🏅<br><br> + <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo/512.png" width="256"></a> +</td> +</tr> +<tr valign="middle"> +<td width="20%" align="center" rowspan="2" colspan="2"> + <a href="https://vercel.com">Vercel</a><br><br> + <a href="https://vercel.com"><img src="https://avatars1.githubusercontent.com/u/14985020?s=256&v=4" width="128"></a> +</td> +<td width="20%" align="center" rowspan="2" colspan="2"> + <a href="https://motif.land">Motif</a><br><br> + <a href="https://motif.land"><img src="https://avatars1.githubusercontent.com/u/74457950?s=256&v=4" width="128"></a> +</td> +<td width="20%" align="center" rowspan="2" colspan="2"> + <a href="https://www.hashicorp.com">HashiCorp</a><br><br> + <a href="https://www.hashicorp.com"><img src="https://avatars1.githubusercontent.com/u/761456?s=256&v=4" width="128"></a> +</td> +<td width="20%" align="center" rowspan="2" colspan="2"> + <a href="https://www.gitbook.com">GitBook</a><br><br> + <a href="https://www.gitbook.com"><img src="https://avatars1.githubusercontent.com/u/7111340?s=256&v=4" width="128"></a> +</td> +<td width="20%" align="center" rowspan="2" colspan="2"> + <a href="https://www.gatsbyjs.org">Gatsby</a><br><br> + <a href="https://www.gatsbyjs.org"><img src="https://avatars1.githubusercontent.com/u/12551863?s=256&v=4" width="128"></a> +</td> +</tr> +<tr valign="middle"> +</tr> +<tr valign="middle"> +<td width="20%" align="center" rowspan="2" colspan="2"> + <a href="https://www.netlify.com">Netlify</a><br><br> + <!--OC has a sharper image--> + <a href="https://www.netlify.com"><img src="https://images.opencollective.com/netlify/4087de2/logo/256.png" width="128"></a> +</td> +<td width="10%" align="center"> + <a href="https://www.coinbase.com">Coinbase</a><br><br> + <a href="https://www.coinbase.com"><img src="https://avatars1.githubusercontent.com/u/1885080?s=256&v=4" width="64"></a> +</td> +<td width="10%" align="center"> + <a href="https://themeisle.com">ThemeIsle</a><br><br> + <a href="https://themeisle.com"><img src="https://avatars1.githubusercontent.com/u/58979018?s=128&v=4" width="64"></a> +</td> +<td width="10%" align="center"> + <a href="https://expo.io">Expo</a><br><br> + <a href="https://expo.io"><img src="https://avatars1.githubusercontent.com/u/12504344?s=128&v=4" width="64"></a> +</td> +<td width="10%" align="center"> + <a href="https://boostnote.io">Boost Note</a><br><br> + <a href="https://boostnote.io"><img src="https://images.opencollective.com/boosthub/6318083/logo/128.png" width="64"></a> +</td> +<td width="10%" align="center"> + <a href="https://markdown.space">Markdown Space</a><br><br> + <a href="https://markdown.space"><img src="https://images.opencollective.com/markdown-space/e1038ed/logo/128.png" width="64"></a> +</td> +<td width="10%" align="center"> + <a href="https://www.holloway.com">Holloway</a><br><br> + <a href="https://www.holloway.com"><img src="https://avatars1.githubusercontent.com/u/35904294?s=128&v=4" width="64"></a> +</td> +<td width="10%"></td> +<td width="10%"></td> +</tr> +<tr valign="middle"> +<td width="100%" align="center" colspan="8"> + <br> + <a href="https://opencollective.com/unified"><strong>You?</strong></a> + <br><br> +</td> +</tr> +</table> + +## License + +[MIT][license] © [Titus Wormer][author] + +<!-- Definitions --> + +[api-micromark]: #micromarkvalue-encoding-options + +[api-options]: #options + +[api-stream]: #streamoptions + +[author]: https://wooorm.com + +[backers-badge]: https://opencollective.com/unified/backers/badge.svg + +[build]: https://github.com/micromark/micromark/actions + +[build-badge]: https://github.com/micromark/micromark/workflows/main/badge.svg + +[bundle-size]: https://bundlejs.com/?q=micromark + +[bundle-size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=micromark + +[chat]: https://github.com/micromark/micromark/discussions + +[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg + +[cheat]: https://commonmark.org/help/ + +[coc]: https://github.com/micromark/.github/blob/main/code-of-conduct.md + +[commonmark]: https://commonmark.org + +[comparison]: https://github.com/micromark/micromark#comparison + +[contribute]: #contribute + +[contributing]: https://github.com/micromark/.github/blob/main/contributing.md + +[coverage]: https://codecov.io/github/micromark/micromark + +[coverage-badge]: https://img.shields.io/codecov/c/github/micromark/micromark.svg + +[development]: https://nodejs.org/api/packages.html#packages_resolving_user_conditions + +[directives]: https://github.com/micromark/micromark-extension-directive + +[downloads]: https://www.npmjs.com/package/micromark + +[downloads-badge]: https://img.shields.io/npm/dm/micromark.svg + +[encoding]: https://nodejs.org/api/util.html#whatwg-supported-encodings + +[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c + +[esmsh]: https://esm.sh + +[extensions]: https://github.com/micromark/micromark#extensions + +[frontmatter]: https://github.com/micromark/micromark-extension-frontmatter + +[gfm]: https://github.com/micromark/micromark-extension-gfm + +[health]: https://github.com/micromark/.github + +[license]: https://github.com/micromark/micromark/blob/main/license + +[markdown-rs]: https://github.com/wooorm/markdown-rs + +[math]: https://github.com/micromark/micromark-extension-math + +[mdast-util-to-markdown]: https://github.com/syntax-tree/mdast-util-to-markdown + +[mdxjs]: https://github.com/micromark/micromark-extension-mdxjs + +[micromark]: https://github.com/micromark/micromark + +[npm]: https://docs.npmjs.com/cli/install + +[opencollective]: https://opencollective.com/unified + +[security]: #security + +[securitymd]: https://github.com/micromark/.github/blob/main/security.md + +[site]: https://unifiedjs.com + +[size-debug]: https://github.com/micromark/micromark#size--debug + +[sponsor]: #sponsor + +[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg + +[support]: https://github.com/micromark/.github/blob/main/support.md + +[test]: https://github.com/micromark/micromark#test + +[typescript]: https://www.typescriptlang.org + +[uint8-array]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array diff --git a/node_modules/micromark/stream.d.ts b/node_modules/micromark/stream.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..2b05447e816dab4efbeba084a9ad47c37f8d458a --- /dev/null +++ b/node_modules/micromark/stream.d.ts @@ -0,0 +1,35 @@ +/** + * Create a duplex (readable and writable) stream. + * + * Some of the work to parse markdown can be done streaming, but in the + * end buffering is required. + * + * micromark does not handle errors for you, so you must handle errors on whatever + * streams you pipe into it. + * As markdown does not know errors, `micromark` itself does not emit errors. + * + * @param {Options | null | undefined} [options] + * Configuration (optional). + * @returns {MinimalDuplex} + * Duplex stream. + */ +export function stream(options?: Options | null | undefined): MinimalDuplex; +export type Options = import("micromark-util-types").Options; +/** + * Function called when write was successful. + */ +export type Callback = () => undefined; +/** + * Configuration for piping. + */ +export type PipeOptions = { + /** + * Whether to end the destination stream when the source stream ends. + */ + end?: boolean | null | undefined; +}; +/** + * Duplex stream. + */ +export type MinimalDuplex = Omit<NodeJS.ReadableStream & NodeJS.WritableStream, "isPaused" | "pause" | "read" | "resume" | "setEncoding" | "unpipe" | "unshift" | "wrap">; +//# sourceMappingURL=stream.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark/stream.d.ts.map b/node_modules/micromark/stream.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..f89c748fa5fb2ff13da0b371e82ea395938d7d71 --- /dev/null +++ b/node_modules/micromark/stream.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["stream.js"],"names":[],"mappings":"AA6BA;;;;;;;;;;;;;;GAcG;AACH,iCALW,OAAO,GAAG,IAAI,GAAG,SAAS,GAExB,aAAa,CAoOzB;sBAxQY,OAAO,sBAAsB,EAAE,OAAO;;;;6BAMtC,SAAS;;;;;;;;UAKR,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;4BAG3B,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,MAAM,CAAC,cAAc,EAAE,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,aAAa,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC"} \ No newline at end of file diff --git a/node_modules/micromark/stream.js b/node_modules/micromark/stream.js new file mode 100644 index 0000000000000000000000000000000000000000..7561620013d6f32ca11669362233565ce9dea469 --- /dev/null +++ b/node_modules/micromark/stream.js @@ -0,0 +1,256 @@ +/** + * @import {Encoding, Value} from 'micromark-util-types' + */ + +/** + * @typedef {import('micromark-util-types').Options} Options + */ + +/** + * @callback Callback + * Function called when write was successful. + * @returns {undefined} + * Nothing. + * + * @typedef PipeOptions + * Configuration for piping. + * @property {boolean | null | undefined} [end] + * Whether to end the destination stream when the source stream ends. + * + * @typedef {Omit<NodeJS.ReadableStream & NodeJS.WritableStream, 'isPaused' | 'pause' | 'read' | 'resume' | 'setEncoding' | 'unpipe' | 'unshift' | 'wrap'>} MinimalDuplex + * Duplex stream. + */ + +import { EventEmitter } from 'node:events'; +import { compile } from './lib/compile.js'; +import { parse } from './lib/parse.js'; +import { postprocess } from './lib/postprocess.js'; +import { preprocess } from './lib/preprocess.js'; + +/** + * Create a duplex (readable and writable) stream. + * + * Some of the work to parse markdown can be done streaming, but in the + * end buffering is required. + * + * micromark does not handle errors for you, so you must handle errors on whatever + * streams you pipe into it. + * As markdown does not know errors, `micromark` itself does not emit errors. + * + * @param {Options | null | undefined} [options] + * Configuration (optional). + * @returns {MinimalDuplex} + * Duplex stream. + */ +export function stream(options) { + const prep = preprocess(); + const tokenize = parse(options).document().write; + const comp = compile(options); + /** @type {boolean} */ + let ended; + const emitter = /** @type {MinimalDuplex} */new EventEmitter(); + // @ts-expect-error: fine. + emitter.end = end; + emitter.pipe = pipe; + emitter.readable = true; + emitter.writable = true; + // @ts-expect-error: fine. + emitter.write = write; + return emitter; + + /** + * Write a chunk into memory. + * + * @overload + * @param {Value | null | undefined} [chunk] + * Slice of markdown to parse (`string` or `Uint8Array`). + * @param {Encoding | null | undefined} [encoding] + * Character encoding to understand `chunk` as when it’s a `Uint8Array` + * (`string`, default: `'utf8'`). + * @param {Callback | null | undefined} [callback] + * Function called when write was successful. + * @returns {boolean} + * Whether write was successful. + * + * @overload + * @param {Value | null | undefined} [chunk] + * Slice of markdown to parse (`string` or `Uint8Array`). + * @param {Callback | null | undefined} [callback] + * Function called when write was successful. + * @returns {boolean} + * Whether write was successful. + * + * @param {Value | null | undefined} [chunk] + * Slice of markdown to parse (`string` or `Uint8Array`). + * @param {Callback | Encoding | null | undefined} [encoding] + * Character encoding to understand `chunk` as when it’s a `Uint8Array` + * (`string`, default: `'utf8'`). + * @param {Callback | null | undefined} [callback] + * Function called when write was successful. + * @returns {boolean} + * Whether write was successful. + */ + function write(chunk, encoding, callback) { + if (typeof encoding === 'function') { + callback = encoding; + encoding = undefined; + } + if (ended) { + throw new Error('Did not expect `write` after `end`'); + } + tokenize(prep(chunk || '', encoding)); + if (callback) { + callback(); + } + + // Signal successful write. + return true; + } + + /** + * End the writing. + * + * Passes all arguments as a final `write`. + * + * @overload + * @param {Value | null | undefined} [chunk] + * Slice of markdown to parse (`string` or `Uint8Array`). + * @param {Encoding | null | undefined} [encoding] + * Character encoding to understand `chunk` as when it’s a `Uint8Array` + * (`string`, default: `'utf8'`). + * @param {Callback | null | undefined} [callback] + * Function called when write was successful. + * @returns {boolean} + * Whether write was successful. + * + * @overload + * @param {Value | null | undefined} [chunk] + * Slice of markdown to parse (`string` or `Uint8Array`). + * @param {Callback | null | undefined} [callback] + * Function called when write was successful. + * @returns {boolean} + * Whether write was successful. + * + * @overload + * @param {Callback | null | undefined} [callback] + * Function called when write was successful. + * @returns {boolean} + * Whether write was successful. + * + * @param {Callback | Value | null | undefined} [chunk] + * Slice of markdown to parse (`string` or `Uint8Array`). + * @param {Callback | Encoding | null | undefined} [encoding] + * Character encoding to understand `chunk` as when it’s a `Uint8Array` + * (`string`, default: `'utf8'`). + * @param {Callback | null | undefined} [callback] + * Function called when write was successful. + * @returns {boolean} + * Whether write was successful. + */ + function end(chunk, encoding, callback) { + if (typeof chunk === 'function') { + encoding = chunk; + chunk = undefined; + } + if (typeof encoding === 'function') { + callback = encoding; + encoding = undefined; + } + write(chunk, encoding, callback); + emitter.emit('data', comp(postprocess(tokenize(prep('', encoding, true))))); + emitter.emit('end'); + ended = true; + return true; + } + + /** + * Pipe the processor into a writable stream. + * + * Basically `Stream#pipe`, but inlined and simplified to keep the bundled + * size down. + * See: <https://github.com/nodejs/node/blob/43a5170/lib/internal/streams/legacy.js#L13>. + * + * @template {NodeJS.WritableStream} Stream + * Writable stream. + * @param {Stream} destination + * Stream to pipe into. + * @param {PipeOptions | null | undefined} [options] + * Configuration. + * @returns {Stream} + * Destination stream. + */ + function pipe(destination, options) { + emitter.on('data', ondata); + emitter.on('error', onerror); + emitter.on('end', cleanup); + emitter.on('close', cleanup); + + // If the `end` option is not supplied, `destination.end()` will be + // called when the `end` or `close` events are received. + // @ts-expect-error `_isStdio` is available on `std{err,out}` + if (!destination._isStdio && (!options || options.end !== false)) { + emitter.on('end', onend); + } + destination.on('error', onerror); + destination.on('close', cleanup); + destination.emit('pipe', emitter); + return destination; + + /** + * End destination stream. + * + * @returns {undefined} + * Nothing. + */ + function onend() { + if (destination.end) { + destination.end(); + } + } + + /** + * Handle data. + * + * @param {string} chunk + * Data. + * @returns {undefined} + * Nothing. + */ + function ondata(chunk) { + if (destination.writable) { + destination.write(chunk); + } + } + + /** + * Clean listeners. + * + * @returns {undefined} + * Nothing. + */ + function cleanup() { + emitter.removeListener('data', ondata); + emitter.removeListener('end', onend); + emitter.removeListener('error', onerror); + emitter.removeListener('end', cleanup); + emitter.removeListener('close', cleanup); + destination.removeListener('error', onerror); + destination.removeListener('close', cleanup); + } + + /** + * Close dangling pipes and handle unheard errors. + * + * @param {Error | null | undefined} [error] + * Error, if any. + * @returns {undefined} + * Nothing. + */ + function onerror(error) { + cleanup(); + if (!emitter.listenerCount('error')) { + throw error; // Unhandled stream error in pipe. + } + } + } +} \ No newline at end of file

!^a

+ *

!^a

+ * ``` + * + * @type {State} + */ + function after(code) { + // To do: use a new field to do this, this is still needed for + // `micromark-extension-gfm-footnote`, but the `label-start-link` + // behavior isn’t. + // Hidden footnotes hook. + /* c8 ignore next 3 */ + return code === codes.caret && + '_hiddenFootnoteSupport' in self.parser.constructs + ? nok(code) + : ok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-start-link.d.ts b/node_modules/micromark-core-commonmark/dev/lib/label-start-link.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..955c873ff3dcafb631cec59cf7b54512272d4aba --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-start-link.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const labelStartLink: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=label-start-link.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-start-link.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/label-start-link.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b242831ba15fac1a3725811dea1e9d32d39b02d7 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-start-link.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"label-start-link.d.ts","sourceRoot":"","sources":["label-start-link.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,6BADW,SAAS,CAKnB;+BAZS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/label-start-link.js b/node_modules/micromark-core-commonmark/dev/lib/label-start-link.js new file mode 100644 index 0000000000000000000000000000000000000000..91039bf029cfc535197fa731da60cc57d258b031 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/label-start-link.js @@ -0,0 +1,62 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {codes, types} from 'micromark-util-symbol' +import {labelEnd} from './label-end.js' + +/** @type {Construct} */ +export const labelStartLink = { + name: 'labelStartLink', + resolveAll: labelEnd.resolveAll, + tokenize: tokenizeLabelStartLink +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeLabelStartLink(effects, ok, nok) { + const self = this + + return start + + /** + * Start of label (link) start. + * + * ```markdown + * > | a [b] c + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + assert(code === codes.leftSquareBracket, 'expected `[`') + effects.enter(types.labelLink) + effects.enter(types.labelMarker) + effects.consume(code) + effects.exit(types.labelMarker) + effects.exit(types.labelLink) + return after + } + + /** @type {State} */ + function after(code) { + // To do: this isn’t needed in `micromark-extension-gfm-footnote`, + // remove. + // Hidden footnotes hook. + /* c8 ignore next 3 */ + return code === codes.caret && + '_hiddenFootnoteSupport' in self.parser.constructs + ? nok(code) + : ok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/line-ending.d.ts b/node_modules/micromark-core-commonmark/dev/lib/line-ending.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3eb4a88afb8ec44f64729914b561e9fc5eb38d02 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/line-ending.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const lineEnding: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=line-ending.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/line-ending.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/line-ending.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..22bb64a5bed6c25aded0771488c316b138f07c05 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/line-ending.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"line-ending.d.ts","sourceRoot":"","sources":["line-ending.js"],"names":[],"mappings":"AAcA,wBAAwB;AACxB,yBADW,SAAS,CACwD;+BATlE,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/line-ending.js b/node_modules/micromark-core-commonmark/dev/lib/line-ending.js new file mode 100644 index 0000000000000000000000000000000000000000..a58d9e330bca739035e41ef3c42e33bd4cdf48bd --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/line-ending.js @@ -0,0 +1,34 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import {markdownLineEnding} from 'micromark-util-character' +import {types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const lineEnding = {name: 'lineEnding', tokenize: tokenizeLineEnding} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeLineEnding(effects, ok) { + return start + + /** @type {State} */ + function start(code) { + assert(markdownLineEnding(code), 'expected eol') + effects.enter(types.lineEnding) + effects.consume(code) + effects.exit(types.lineEnding) + return factorySpace(effects, ok, types.linePrefix) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/list.d.ts b/node_modules/micromark-core-commonmark/dev/lib/list.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ebecfda629530ee4e2f129755d795c8111ee5879 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/list.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const list: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=list.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/list.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/list.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..8731fa642c91a3f999c2781be6c26ce41e253ba3 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/list.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["list.js"],"names":[],"mappings":"AAkBA,wBAAwB;AACxB,mBADW,SAAS,CAMnB;+BAhBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/list.js b/node_modules/micromark-core-commonmark/dev/lib/list.js new file mode 100644 index 0000000000000000000000000000000000000000..55671e12ec43194115cecf4e58c23bc4b2e5fcb5 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/list.js @@ -0,0 +1,306 @@ +/** + * @import { + * Code, + * Construct, + * Exiter, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import {asciiDigit, markdownSpace} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' +import {blankLine} from './blank-line.js' +import {thematicBreak} from './thematic-break.js' + +/** @type {Construct} */ +export const list = { + continuation: {tokenize: tokenizeListContinuation}, + exit: tokenizeListEnd, + name: 'list', + tokenize: tokenizeListStart +} + +/** @type {Construct} */ +const listItemPrefixWhitespaceConstruct = { + partial: true, + tokenize: tokenizeListItemPrefixWhitespace +} + +/** @type {Construct} */ +const indentConstruct = {partial: true, tokenize: tokenizeIndent} + +// To do: `markdown-rs` parses list items on their own and later stitches them +// together. + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeListStart(effects, ok, nok) { + const self = this + const tail = self.events[self.events.length - 1] + let initialSize = + tail && tail[1].type === types.linePrefix + ? tail[2].sliceSerialize(tail[1], true).length + : 0 + let size = 0 + + return start + + /** @type {State} */ + function start(code) { + assert(self.containerState, 'expected state') + const kind = + self.containerState.type || + (code === codes.asterisk || code === codes.plusSign || code === codes.dash + ? types.listUnordered + : types.listOrdered) + + if ( + kind === types.listUnordered + ? !self.containerState.marker || code === self.containerState.marker + : asciiDigit(code) + ) { + if (!self.containerState.type) { + self.containerState.type = kind + effects.enter(kind, {_container: true}) + } + + if (kind === types.listUnordered) { + effects.enter(types.listItemPrefix) + return code === codes.asterisk || code === codes.dash + ? effects.check(thematicBreak, nok, atMarker)(code) + : atMarker(code) + } + + if (!self.interrupt || code === codes.digit1) { + effects.enter(types.listItemPrefix) + effects.enter(types.listItemValue) + return inside(code) + } + } + + return nok(code) + } + + /** @type {State} */ + function inside(code) { + assert(self.containerState, 'expected state') + if (asciiDigit(code) && ++size < constants.listItemValueSizeMax) { + effects.consume(code) + return inside + } + + if ( + (!self.interrupt || size < 2) && + (self.containerState.marker + ? code === self.containerState.marker + : code === codes.rightParenthesis || code === codes.dot) + ) { + effects.exit(types.listItemValue) + return atMarker(code) + } + + return nok(code) + } + + /** + * @type {State} + **/ + function atMarker(code) { + assert(self.containerState, 'expected state') + assert(code !== codes.eof, 'eof (`null`) is not a marker') + effects.enter(types.listItemMarker) + effects.consume(code) + effects.exit(types.listItemMarker) + self.containerState.marker = self.containerState.marker || code + return effects.check( + blankLine, + // Can’t be empty when interrupting. + self.interrupt ? nok : onBlank, + effects.attempt( + listItemPrefixWhitespaceConstruct, + endOfPrefix, + otherPrefix + ) + ) + } + + /** @type {State} */ + function onBlank(code) { + assert(self.containerState, 'expected state') + self.containerState.initialBlankLine = true + initialSize++ + return endOfPrefix(code) + } + + /** @type {State} */ + function otherPrefix(code) { + if (markdownSpace(code)) { + effects.enter(types.listItemPrefixWhitespace) + effects.consume(code) + effects.exit(types.listItemPrefixWhitespace) + return endOfPrefix + } + + return nok(code) + } + + /** @type {State} */ + function endOfPrefix(code) { + assert(self.containerState, 'expected state') + self.containerState.size = + initialSize + + self.sliceSerialize(effects.exit(types.listItemPrefix), true).length + return ok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeListContinuation(effects, ok, nok) { + const self = this + + assert(self.containerState, 'expected state') + self.containerState._closeFlow = undefined + + return effects.check(blankLine, onBlank, notBlank) + + /** @type {State} */ + function onBlank(code) { + assert(self.containerState, 'expected state') + assert(typeof self.containerState.size === 'number', 'expected size') + self.containerState.furtherBlankLines = + self.containerState.furtherBlankLines || + self.containerState.initialBlankLine + + // We have a blank line. + // Still, try to consume at most the items size. + return factorySpace( + effects, + ok, + types.listItemIndent, + self.containerState.size + 1 + )(code) + } + + /** @type {State} */ + function notBlank(code) { + assert(self.containerState, 'expected state') + if (self.containerState.furtherBlankLines || !markdownSpace(code)) { + self.containerState.furtherBlankLines = undefined + self.containerState.initialBlankLine = undefined + return notInCurrentItem(code) + } + + self.containerState.furtherBlankLines = undefined + self.containerState.initialBlankLine = undefined + return effects.attempt(indentConstruct, ok, notInCurrentItem)(code) + } + + /** @type {State} */ + function notInCurrentItem(code) { + assert(self.containerState, 'expected state') + // While we do continue, we signal that the flow should be closed. + self.containerState._closeFlow = true + // As we’re closing flow, we’re no longer interrupting. + self.interrupt = undefined + // Always populated by defaults. + assert( + self.parser.constructs.disable.null, + 'expected `disable.null` to be populated' + ) + return factorySpace( + effects, + effects.attempt(list, ok, nok), + types.linePrefix, + self.parser.constructs.disable.null.includes('codeIndented') + ? undefined + : constants.tabSize + )(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeIndent(effects, ok, nok) { + const self = this + + assert(self.containerState, 'expected state') + assert(typeof self.containerState.size === 'number', 'expected size') + + return factorySpace( + effects, + afterPrefix, + types.listItemIndent, + self.containerState.size + 1 + ) + + /** @type {State} */ + function afterPrefix(code) { + assert(self.containerState, 'expected state') + const tail = self.events[self.events.length - 1] + return tail && + tail[1].type === types.listItemIndent && + tail[2].sliceSerialize(tail[1], true).length === self.containerState.size + ? ok(code) + : nok(code) + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Exiter} + */ +function tokenizeListEnd(effects) { + assert(this.containerState, 'expected state') + assert(typeof this.containerState.type === 'string', 'expected type') + effects.exit(this.containerState.type) +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeListItemPrefixWhitespace(effects, ok, nok) { + const self = this + + // Always populated by defaults. + assert( + self.parser.constructs.disable.null, + 'expected `disable.null` to be populated' + ) + + return factorySpace( + effects, + afterPrefix, + types.listItemPrefixWhitespace, + self.parser.constructs.disable.null.includes('codeIndented') + ? undefined + : constants.tabSize + 1 + ) + + /** @type {State} */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1] + + return !markdownSpace(code) && + tail && + tail[1].type === types.listItemPrefixWhitespace + ? ok(code) + : nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/setext-underline.d.ts b/node_modules/micromark-core-commonmark/dev/lib/setext-underline.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..d7ca340f4f659fa79d6438660bcdd3a0c8583a21 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/setext-underline.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const setextUnderline: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=setext-underline.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/setext-underline.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/setext-underline.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..296f7c681e31b0a670a4a5091c194be9a77d82ae --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/setext-underline.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"setext-underline.d.ts","sourceRoot":"","sources":["setext-underline.js"],"names":[],"mappings":"AAgBA,wBAAwB;AACxB,8BADW,SAAS,CAKnB;+BAbS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/setext-underline.js b/node_modules/micromark-core-commonmark/dev/lib/setext-underline.js new file mode 100644 index 0000000000000000000000000000000000000000..9379f906c4c0608167e2791372afebee290decea --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/setext-underline.js @@ -0,0 +1,210 @@ +/** + * @import { + * Code, + * Construct, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import {markdownLineEnding, markdownSpace} from 'micromark-util-character' +import {codes, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const setextUnderline = { + name: 'setextUnderline', + resolveTo: resolveToSetextUnderline, + tokenize: tokenizeSetextUnderline +} + +/** @type {Resolver} */ +function resolveToSetextUnderline(events, context) { + // To do: resolve like `markdown-rs`. + let index = events.length + /** @type {number | undefined} */ + let content + /** @type {number | undefined} */ + let text + /** @type {number | undefined} */ + let definition + + // Find the opening of the content. + // It’ll always exist: we don’t tokenize if it isn’t there. + while (index--) { + if (events[index][0] === 'enter') { + if (events[index][1].type === types.content) { + content = index + break + } + + if (events[index][1].type === types.paragraph) { + text = index + } + } + // Exit + else { + if (events[index][1].type === types.content) { + // Remove the content end (if needed we’ll add it later) + events.splice(index, 1) + } + + if (!definition && events[index][1].type === types.definition) { + definition = index + } + } + } + + assert(text !== undefined, 'expected a `text` index to be found') + assert(content !== undefined, 'expected a `text` index to be found') + assert(events[content][2] === context, 'enter context should be same') + assert( + events[events.length - 1][2] === context, + 'enter context should be same' + ) + const heading = { + type: types.setextHeading, + start: {...events[content][1].start}, + end: {...events[events.length - 1][1].end} + } + + // Change the paragraph to setext heading text. + events[text][1].type = types.setextHeadingText + + // If we have definitions in the content, we’ll keep on having content, + // but we need move it. + if (definition) { + events.splice(text, 0, ['enter', heading, context]) + events.splice(definition + 1, 0, ['exit', events[content][1], context]) + events[content][1].end = {...events[definition][1].end} + } else { + events[content][1] = heading + } + + // Add the heading exit at the end. + events.push(['exit', heading, context]) + + return events +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeSetextUnderline(effects, ok, nok) { + const self = this + /** @type {NonNullable} */ + let marker + + return start + + /** + * At start of heading (setext) underline. + * + * ```markdown + * | aa + * > | == + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + let index = self.events.length + /** @type {boolean | undefined} */ + let paragraph + + assert( + code === codes.dash || code === codes.equalsTo, + 'expected `=` or `-`' + ) + + // Find an opening. + while (index--) { + // Skip enter/exit of line ending, line prefix, and content. + // We can now either have a definition or a paragraph. + if ( + self.events[index][1].type !== types.lineEnding && + self.events[index][1].type !== types.linePrefix && + self.events[index][1].type !== types.content + ) { + paragraph = self.events[index][1].type === types.paragraph + break + } + } + + // To do: handle lazy/pierce like `markdown-rs`. + // To do: parse indent like `markdown-rs`. + if (!self.parser.lazy[self.now().line] && (self.interrupt || paragraph)) { + effects.enter(types.setextHeadingLine) + marker = code + return before(code) + } + + return nok(code) + } + + /** + * After optional whitespace, at `-` or `=`. + * + * ```markdown + * | aa + * > | == + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + effects.enter(types.setextHeadingLineSequence) + return inside(code) + } + + /** + * In sequence. + * + * ```markdown + * | aa + * > | == + * ^ + * ``` + * + * @type {State} + */ + function inside(code) { + if (code === marker) { + effects.consume(code) + return inside + } + + effects.exit(types.setextHeadingLineSequence) + + return markdownSpace(code) + ? factorySpace(effects, after, types.lineSuffix)(code) + : after(code) + } + + /** + * After sequence, after optional whitespace. + * + * ```markdown + * | aa + * > | == + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + if (code === codes.eof || markdownLineEnding(code)) { + effects.exit(types.setextHeadingLine) + return ok(code) + } + + return nok(code) + } +} diff --git a/node_modules/micromark-core-commonmark/dev/lib/thematic-break.d.ts b/node_modules/micromark-core-commonmark/dev/lib/thematic-break.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..51e9e97c650792cb0bc40c6e7065c1705796c4ac --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/thematic-break.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const thematicBreak: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=thematic-break.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/thematic-break.d.ts.map b/node_modules/micromark-core-commonmark/dev/lib/thematic-break.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..d10a65bbc279681c956eddb067552b05eb8ba5a3 --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/thematic-break.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"thematic-break.d.ts","sourceRoot":"","sources":["thematic-break.js"],"names":[],"mappings":"AAeA,wBAAwB;AACxB,4BADW,SAAS,CAInB;+BAZS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/dev/lib/thematic-break.js b/node_modules/micromark-core-commonmark/dev/lib/thematic-break.js new file mode 100644 index 0000000000000000000000000000000000000000..355dd6afd991c52871c0c2048cd8f262e51d776c --- /dev/null +++ b/node_modules/micromark-core-commonmark/dev/lib/thematic-break.js @@ -0,0 +1,120 @@ +/** + * @import { + * Code, + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import {ok as assert} from 'devlop' +import {factorySpace} from 'micromark-factory-space' +import {markdownLineEnding, markdownSpace} from 'micromark-util-character' +import {codes, constants, types} from 'micromark-util-symbol' + +/** @type {Construct} */ +export const thematicBreak = { + name: 'thematicBreak', + tokenize: tokenizeThematicBreak +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeThematicBreak(effects, ok, nok) { + let size = 0 + /** @type {NonNullable} */ + let marker + + return start + + /** + * Start of thematic break. + * + * ```markdown + * > | *** + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter(types.thematicBreak) + // To do: parse indent like `markdown-rs`. + return before(code) + } + + /** + * After optional whitespace, at marker. + * + * ```markdown + * > | *** + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + assert( + code === codes.asterisk || + code === codes.dash || + code === codes.underscore, + 'expected `*`, `-`, or `_`' + ) + marker = code + return atBreak(code) + } + + /** + * After something, before something else. + * + * ```markdown + * > | *** + * ^ + * ``` + * + * @type {State} + */ + function atBreak(code) { + if (code === marker) { + effects.enter(types.thematicBreakSequence) + return sequence(code) + } + + if ( + size >= constants.thematicBreakMarkerCountMin && + (code === codes.eof || markdownLineEnding(code)) + ) { + effects.exit(types.thematicBreak) + return ok(code) + } + + return nok(code) + } + + /** + * In sequence. + * + * ```markdown + * > | *** + * ^ + * ``` + * + * @type {State} + */ + function sequence(code) { + if (code === marker) { + effects.consume(code) + size++ + return sequence + } + + effects.exit(types.thematicBreakSequence) + return markdownSpace(code) + ? factorySpace(effects, atBreak, types.whitespace)(code) + : atBreak(code) + } +} diff --git a/node_modules/micromark-core-commonmark/index.d.ts b/node_modules/micromark-core-commonmark/index.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..bd832f665cfdf802955e1fb1663357efe8d03eff --- /dev/null +++ b/node_modules/micromark-core-commonmark/index.d.ts @@ -0,0 +1,23 @@ +export { attention } from "./lib/attention.js"; +export { autolink } from "./lib/autolink.js"; +export { blankLine } from "./lib/blank-line.js"; +export { blockQuote } from "./lib/block-quote.js"; +export { characterEscape } from "./lib/character-escape.js"; +export { characterReference } from "./lib/character-reference.js"; +export { codeFenced } from "./lib/code-fenced.js"; +export { codeIndented } from "./lib/code-indented.js"; +export { codeText } from "./lib/code-text.js"; +export { content } from "./lib/content.js"; +export { definition } from "./lib/definition.js"; +export { hardBreakEscape } from "./lib/hard-break-escape.js"; +export { headingAtx } from "./lib/heading-atx.js"; +export { htmlFlow } from "./lib/html-flow.js"; +export { htmlText } from "./lib/html-text.js"; +export { labelEnd } from "./lib/label-end.js"; +export { labelStartImage } from "./lib/label-start-image.js"; +export { labelStartLink } from "./lib/label-start-link.js"; +export { lineEnding } from "./lib/line-ending.js"; +export { list } from "./lib/list.js"; +export { setextUnderline } from "./lib/setext-underline.js"; +export { thematicBreak } from "./lib/thematic-break.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/index.d.ts.map b/node_modules/micromark-core-commonmark/index.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..ca7a93a9a2807d2076f2cc871f10d62d40e1265d --- /dev/null +++ b/node_modules/micromark-core-commonmark/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/index.js b/node_modules/micromark-core-commonmark/index.js new file mode 100644 index 0000000000000000000000000000000000000000..969b1cdf1228636c4ceccc85cea270ad47c3471f --- /dev/null +++ b/node_modules/micromark-core-commonmark/index.js @@ -0,0 +1,22 @@ +export { attention } from './lib/attention.js'; +export { autolink } from './lib/autolink.js'; +export { blankLine } from './lib/blank-line.js'; +export { blockQuote } from './lib/block-quote.js'; +export { characterEscape } from './lib/character-escape.js'; +export { characterReference } from './lib/character-reference.js'; +export { codeFenced } from './lib/code-fenced.js'; +export { codeIndented } from './lib/code-indented.js'; +export { codeText } from './lib/code-text.js'; +export { content } from './lib/content.js'; +export { definition } from './lib/definition.js'; +export { hardBreakEscape } from './lib/hard-break-escape.js'; +export { headingAtx } from './lib/heading-atx.js'; +export { htmlFlow } from './lib/html-flow.js'; +export { htmlText } from './lib/html-text.js'; +export { labelEnd } from './lib/label-end.js'; +export { labelStartImage } from './lib/label-start-image.js'; +export { labelStartLink } from './lib/label-start-link.js'; +export { lineEnding } from './lib/line-ending.js'; +export { list } from './lib/list.js'; +export { setextUnderline } from './lib/setext-underline.js'; +export { thematicBreak } from './lib/thematic-break.js'; \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/attention.d.ts b/node_modules/micromark-core-commonmark/lib/attention.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1c8a1747cd541882f27256474956bf083271d56d --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/attention.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const attention: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=attention.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/attention.d.ts.map b/node_modules/micromark-core-commonmark/lib/attention.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..a903a8668f8add6b01762fe3636413a980b97d87 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/attention.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"attention.d.ts","sourceRoot":"","sources":["attention.js"],"names":[],"mappings":"AAoBA,wBAAwB;AACxB,wBADW,SAAS,CAKnB;+BAdS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/attention.js b/node_modules/micromark-core-commonmark/lib/attention.js new file mode 100644 index 0000000000000000000000000000000000000000..1040eb0498e88cae2a24997296689f56add69a0c --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/attention.js @@ -0,0 +1,241 @@ +/** + * @import { + * Code, + * Construct, + * Event, + * Point, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import { push, splice } from 'micromark-util-chunked'; +import { classifyCharacter } from 'micromark-util-classify-character'; +import { resolveAll } from 'micromark-util-resolve-all'; +/** @type {Construct} */ +export const attention = { + name: 'attention', + resolveAll: resolveAllAttention, + tokenize: tokenizeAttention +}; + +/** + * Take all events and resolve attention to emphasis or strong. + * + * @type {Resolver} + */ +// eslint-disable-next-line complexity +function resolveAllAttention(events, context) { + let index = -1; + /** @type {number} */ + let open; + /** @type {Token} */ + let group; + /** @type {Token} */ + let text; + /** @type {Token} */ + let openingSequence; + /** @type {Token} */ + let closingSequence; + /** @type {number} */ + let use; + /** @type {Array} */ + let nextEvents; + /** @type {number} */ + let offset; + + // Walk through all events. + // + // Note: performance of this is fine on an mb of normal markdown, but it’s + // a bottleneck for malicious stuff. + 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 (events[open][0] === 'exit' && events[open][1].type === 'attentionSequence' && events[open][1]._open && + // If the markers are the same: + context.sliceSerialize(events[open][1]).charCodeAt(0) === context.sliceSerialize(events[index][1]).charCodeAt(0)) { + // If the opening can close or the closing can open, + // and the close size *is not* a multiple of three, + // but the sum of the opening and closing size *is* multiple of three, + // then don’t match. + if ((events[open][1]._close || events[index][1]._open) && (events[index][1].end.offset - events[index][1].start.offset) % 3 && !((events[open][1].end.offset - events[open][1].start.offset + events[index][1].end.offset - events[index][1].start.offset) % 3)) { + continue; + } + + // Number of markers to use from the sequence. + use = events[open][1].end.offset - events[open][1].start.offset > 1 && events[index][1].end.offset - events[index][1].start.offset > 1 ? 2 : 1; + const start = { + ...events[open][1].end + }; + const end = { + ...events[index][1].start + }; + movePoint(start, -use); + movePoint(end, use); + openingSequence = { + type: use > 1 ? "strongSequence" : "emphasisSequence", + start, + end: { + ...events[open][1].end + } + }; + closingSequence = { + type: use > 1 ? "strongSequence" : "emphasisSequence", + start: { + ...events[index][1].start + }, + end + }; + text = { + type: use > 1 ? "strongText" : "emphasisText", + start: { + ...events[open][1].end + }, + end: { + ...events[index][1].start + } + }; + group = { + type: use > 1 ? "strong" : "emphasis", + start: { + ...openingSequence.start + }, + end: { + ...closingSequence.end + } + }; + events[open][1].end = { + ...openingSequence.start + }; + events[index][1].start = { + ...closingSequence.end + }; + nextEvents = []; + + // If there are more markers in the opening, add them before. + if (events[open][1].end.offset - events[open][1].start.offset) { + nextEvents = push(nextEvents, [['enter', events[open][1], context], ['exit', events[open][1], context]]); + } + + // Opening. + nextEvents = push(nextEvents, [['enter', group, context], ['enter', openingSequence, context], ['exit', openingSequence, context], ['enter', text, context]]); + + // Always populated by defaults. + + // Between. + nextEvents = push(nextEvents, resolveAll(context.parser.constructs.insideSpan.null, events.slice(open + 1, index), context)); + + // Closing. + nextEvents = push(nextEvents, [['exit', text, context], ['enter', closingSequence, context], ['exit', closingSequence, context], ['exit', group, context]]); + + // If there are more markers in the closing, add them after. + if (events[index][1].end.offset - events[index][1].start.offset) { + offset = 2; + nextEvents = push(nextEvents, [['enter', events[index][1], context], ['exit', events[index][1], context]]); + } else { + offset = 0; + } + splice(events, open - 1, index - open + 3, nextEvents); + index = open + nextEvents.length - offset - 2; + break; + } + } + } + } + + // Remove remaining sequences. + index = -1; + while (++index < events.length) { + if (events[index][1].type === 'attentionSequence') { + events[index][1].type = 'data'; + } + } + return events; +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeAttention(effects, ok) { + const attentionMarkers = this.parser.constructs.attentionMarkers.null; + const previous = this.previous; + const before = classifyCharacter(previous); + + /** @type {NonNullable} */ + let marker; + return start; + + /** + * Before a sequence. + * + * ```markdown + * > | ** + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + marker = code; + effects.enter('attentionSequence'); + return inside(code); + } + + /** + * In a sequence. + * + * ```markdown + * > | ** + * ^^ + * ``` + * + * @type {State} + */ + function inside(code) { + if (code === marker) { + effects.consume(code); + return inside; + } + const token = effects.exit('attentionSequence'); + + // To do: next major: move this to resolver, just like `markdown-rs`. + const after = classifyCharacter(code); + + // Always populated by defaults. + + const open = !after || after === 2 && before || attentionMarkers.includes(code); + const close = !before || before === 2 && after || attentionMarkers.includes(previous); + token._open = Boolean(marker === 42 ? open : open && (before || !close)); + token._close = Boolean(marker === 42 ? close : close && (after || !open)); + return ok(code); + } +} + +/** + * Move a point a bit. + * + * Note: `move` only works inside lines! It’s not possible to move past other + * chunks (replacement characters, tabs, or line endings). + * + * @param {Point} point + * Point. + * @param {number} offset + * Amount to move. + * @returns {undefined} + * Nothing. + */ +function movePoint(point, offset) { + point.column += offset; + point.offset += offset; + point._bufferIndex += offset; +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/autolink.d.ts b/node_modules/micromark-core-commonmark/lib/autolink.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a69457b269fcc1d83c432756ca186d793bac5395 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/autolink.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const autolink: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=autolink.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/autolink.d.ts.map b/node_modules/micromark-core-commonmark/lib/autolink.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..7b0216b0a09072c2df4bee60f469f5ff8750c413 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/autolink.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"autolink.d.ts","sourceRoot":"","sources":["autolink.js"],"names":[],"mappings":"AAkBA,wBAAwB;AACxB,uBADW,SAAS,CACkD;+BAb5D,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/autolink.js b/node_modules/micromark-core-commonmark/lib/autolink.js new file mode 100644 index 0000000000000000000000000000000000000000..a73d2b5c6582704ae5e5f1120fa793769df0771b --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/autolink.js @@ -0,0 +1,233 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { asciiAlphanumeric, asciiAlpha, asciiAtext, asciiControl } from 'micromark-util-character'; +/** @type {Construct} */ +export const autolink = { + name: 'autolink', + tokenize: tokenizeAutolink +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeAutolink(effects, ok, nok) { + let size = 0; + return start; + + /** + * Start of an autolink. + * + * ```markdown + * > | ab + * ^ + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("autolink"); + effects.enter("autolinkMarker"); + effects.consume(code); + effects.exit("autolinkMarker"); + effects.enter("autolinkProtocol"); + return open; + } + + /** + * After `<`, at protocol or atext. + * + * ```markdown + * > | ab + * ^ + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (asciiAlpha(code)) { + effects.consume(code); + return schemeOrEmailAtext; + } + if (code === 64) { + return nok(code); + } + return emailAtext(code); + } + + /** + * At second byte of protocol or atext. + * + * ```markdown + * > | ab + * ^ + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function schemeOrEmailAtext(code) { + // ASCII alphanumeric and `+`, `-`, and `.`. + if (code === 43 || code === 45 || code === 46 || asciiAlphanumeric(code)) { + // Count the previous alphabetical from `open` too. + size = 1; + return schemeInsideOrEmailAtext(code); + } + return emailAtext(code); + } + + /** + * In ambiguous protocol or atext. + * + * ```markdown + * > | ab + * ^ + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function schemeInsideOrEmailAtext(code) { + if (code === 58) { + effects.consume(code); + size = 0; + return urlInside; + } + + // ASCII alphanumeric and `+`, `-`, and `.`. + if ((code === 43 || code === 45 || code === 46 || asciiAlphanumeric(code)) && size++ < 32) { + effects.consume(code); + return schemeInsideOrEmailAtext; + } + size = 0; + return emailAtext(code); + } + + /** + * After protocol, in URL. + * + * ```markdown + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function urlInside(code) { + if (code === 62) { + effects.exit("autolinkProtocol"); + effects.enter("autolinkMarker"); + effects.consume(code); + effects.exit("autolinkMarker"); + effects.exit("autolink"); + return ok; + } + + // ASCII control, space, or `<`. + if (code === null || code === 32 || code === 60 || asciiControl(code)) { + return nok(code); + } + effects.consume(code); + return urlInside; + } + + /** + * In email atext. + * + * ```markdown + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function emailAtext(code) { + if (code === 64) { + effects.consume(code); + return emailAtSignOrDot; + } + if (asciiAtext(code)) { + effects.consume(code); + return emailAtext; + } + return nok(code); + } + + /** + * In label, after at-sign or dot. + * + * ```markdown + * > | ab + * ^ ^ + * ``` + * + * @type {State} + */ + function emailAtSignOrDot(code) { + return asciiAlphanumeric(code) ? emailLabel(code) : nok(code); + } + + /** + * In label, where `.` and `>` are allowed. + * + * ```markdown + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function emailLabel(code) { + if (code === 46) { + effects.consume(code); + size = 0; + return emailAtSignOrDot; + } + if (code === 62) { + // Exit, then change the token type. + effects.exit("autolinkProtocol").type = "autolinkEmail"; + effects.enter("autolinkMarker"); + effects.consume(code); + effects.exit("autolinkMarker"); + effects.exit("autolink"); + return ok; + } + return emailValue(code); + } + + /** + * In label, where `.` and `>` are *not* allowed. + * + * Though, this is also used in `emailLabel` to parse other values. + * + * ```markdown + * > | ab + * ^ + * ``` + * + * @type {State} + */ + function emailValue(code) { + // ASCII alphanumeric or `-`. + if ((code === 45 || asciiAlphanumeric(code)) && size++ < 63) { + const next = code === 45 ? emailValue : emailLabel; + effects.consume(code); + return next; + } + return nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/blank-line.d.ts b/node_modules/micromark-core-commonmark/lib/blank-line.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..7a8deca617ee590e8028a5a3caec897d6c5b44d6 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/blank-line.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const blankLine: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=blank-line.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/blank-line.d.ts.map b/node_modules/micromark-core-commonmark/lib/blank-line.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..f12302d76e6834ec78fb367b18810cba19273ce7 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/blank-line.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"blank-line.d.ts","sourceRoot":"","sources":["blank-line.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,wBADW,SAAS,CACiD;+BAR3D,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/blank-line.js b/node_modules/micromark-core-commonmark/lib/blank-line.js new file mode 100644 index 0000000000000000000000000000000000000000..93a7eaa428f124698c08e8bdbf555d49147351a2 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/blank-line.js @@ -0,0 +1,61 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding, markdownSpace } from 'micromark-util-character'; +/** @type {Construct} */ +export const blankLine = { + partial: true, + tokenize: tokenizeBlankLine +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeBlankLine(effects, ok, nok) { + return start; + + /** + * Start of blank line. + * + * > 👉 **Note**: `␠` represents a space character. + * + * ```markdown + * > | ␠␠␊ + * ^ + * > | ␊ + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + return markdownSpace(code) ? factorySpace(effects, after, "linePrefix")(code) : after(code); + } + + /** + * At eof/eol, after optional whitespace. + * + * > 👉 **Note**: `␠` represents a space character. + * + * ```markdown + * > | ␠␠␊ + * ^ + * > | ␊ + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + return code === null || markdownLineEnding(code) ? ok(code) : nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/block-quote.d.ts b/node_modules/micromark-core-commonmark/lib/block-quote.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..bf91ff18e8eb3339cbeeda55b8e3a1a2875cddfa --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/block-quote.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const blockQuote: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=block-quote.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/block-quote.d.ts.map b/node_modules/micromark-core-commonmark/lib/block-quote.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b19ef02032e9d309cd3b3b73a696e968e77f916e --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/block-quote.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"block-quote.d.ts","sourceRoot":"","sources":["block-quote.js"],"names":[],"mappings":"AAeA,wBAAwB;AACxB,yBADW,SAAS,CAMnB;+BAdS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/block-quote.js b/node_modules/micromark-core-commonmark/lib/block-quote.js new file mode 100644 index 0000000000000000000000000000000000000000..57af7cccd48f4a7c59fc95e40e766d257590664b --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/block-quote.js @@ -0,0 +1,143 @@ +/** + * @import { + * Construct, + * Exiter, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownSpace } from 'micromark-util-character'; +/** @type {Construct} */ +export const blockQuote = { + continuation: { + tokenize: tokenizeBlockQuoteContinuation + }, + exit, + name: 'blockQuote', + tokenize: tokenizeBlockQuoteStart +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeBlockQuoteStart(effects, ok, nok) { + const self = this; + return start; + + /** + * Start of block quote. + * + * ```markdown + * > | > a + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + if (code === 62) { + const state = self.containerState; + if (!state.open) { + effects.enter("blockQuote", { + _container: true + }); + state.open = true; + } + effects.enter("blockQuotePrefix"); + effects.enter("blockQuoteMarker"); + effects.consume(code); + effects.exit("blockQuoteMarker"); + return after; + } + return nok(code); + } + + /** + * After `>`, before optional whitespace. + * + * ```markdown + * > | > a + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + if (markdownSpace(code)) { + effects.enter("blockQuotePrefixWhitespace"); + effects.consume(code); + effects.exit("blockQuotePrefixWhitespace"); + effects.exit("blockQuotePrefix"); + return ok; + } + effects.exit("blockQuotePrefix"); + return ok(code); + } +} + +/** + * Start of block quote continuation. + * + * ```markdown + * | > a + * > | > b + * ^ + * ``` + * + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeBlockQuoteContinuation(effects, ok, nok) { + const self = this; + return contStart; + + /** + * Start of block quote continuation. + * + * Also used to parse the first block quote opening. + * + * ```markdown + * | > a + * > | > b + * ^ + * ``` + * + * @type {State} + */ + function contStart(code) { + if (markdownSpace(code)) { + // Always populated by defaults. + + return factorySpace(effects, contBefore, "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4)(code); + } + return contBefore(code); + } + + /** + * At `>`, after optional whitespace. + * + * Also used to parse the first block quote opening. + * + * ```markdown + * | > a + * > | > b + * ^ + * ``` + * + * @type {State} + */ + function contBefore(code) { + return effects.attempt(blockQuote, ok, nok)(code); + } +} + +/** @type {Exiter} */ +function exit(effects) { + effects.exit("blockQuote"); +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/character-escape.d.ts b/node_modules/micromark-core-commonmark/lib/character-escape.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c61455e85f343e3acf8814d17091943e638f33d5 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/character-escape.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const characterEscape: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=character-escape.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/character-escape.d.ts.map b/node_modules/micromark-core-commonmark/lib/character-escape.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..e5ec56e148a65da3a2eae240e2502f900ec3e33b --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/character-escape.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"character-escape.d.ts","sourceRoot":"","sources":["character-escape.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,8BADW,SAAS,CAInB;+BAXS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/character-escape.js b/node_modules/micromark-core-commonmark/lib/character-escape.js new file mode 100644 index 0000000000000000000000000000000000000000..36fca818cf816ae7413707616e7d047bccb7218b --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/character-escape.js @@ -0,0 +1,64 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { asciiPunctuation } from 'micromark-util-character'; +/** @type {Construct} */ +export const characterEscape = { + name: 'characterEscape', + tokenize: tokenizeCharacterEscape +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCharacterEscape(effects, ok, nok) { + return start; + + /** + * Start of character escape. + * + * ```markdown + * > | a\*b + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("characterEscape"); + effects.enter("escapeMarker"); + effects.consume(code); + effects.exit("escapeMarker"); + return inside; + } + + /** + * After `\`, at punctuation. + * + * ```markdown + * > | a\*b + * ^ + * ``` + * + * @type {State} + */ + function inside(code) { + // ASCII punctuation. + if (asciiPunctuation(code)) { + effects.enter("characterEscapeValue"); + effects.consume(code); + effects.exit("characterEscapeValue"); + effects.exit("characterEscape"); + return ok; + } + return nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/character-reference.d.ts b/node_modules/micromark-core-commonmark/lib/character-reference.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..554fe30dbbb2ccee8dfeb83680019154a5f2ac99 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/character-reference.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const characterReference: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=character-reference.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/character-reference.d.ts.map b/node_modules/micromark-core-commonmark/lib/character-reference.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..dd03537d5ff767aaa06234517251c6d536c2f057 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/character-reference.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"character-reference.d.ts","sourceRoot":"","sources":["character-reference.js"],"names":[],"mappings":"AAmBA,wBAAwB;AACxB,iCADW,SAAS,CAInB;+BAhBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/character-reference.js b/node_modules/micromark-core-commonmark/lib/character-reference.js new file mode 100644 index 0000000000000000000000000000000000000000..e2d889e90038ea670104b6e136896172ef981692 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/character-reference.js @@ -0,0 +1,149 @@ +/** + * @import { + * Code, + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { decodeNamedCharacterReference } from 'decode-named-character-reference'; +import { asciiAlphanumeric, asciiDigit, asciiHexDigit } from 'micromark-util-character'; +/** @type {Construct} */ +export const characterReference = { + name: 'characterReference', + tokenize: tokenizeCharacterReference +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCharacterReference(effects, ok, nok) { + const self = this; + let size = 0; + /** @type {number} */ + let max; + /** @type {(code: Code) => boolean} */ + let test; + return start; + + /** + * Start of character reference. + * + * ```markdown + * > | a&b + * ^ + * > | a{b + * ^ + * > | a b + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("characterReference"); + effects.enter("characterReferenceMarker"); + effects.consume(code); + effects.exit("characterReferenceMarker"); + return open; + } + + /** + * After `&`, at `#` for numeric references or alphanumeric for named + * references. + * + * ```markdown + * > | a&b + * ^ + * > | a{b + * ^ + * > | a b + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (code === 35) { + effects.enter("characterReferenceMarkerNumeric"); + effects.consume(code); + effects.exit("characterReferenceMarkerNumeric"); + return numeric; + } + effects.enter("characterReferenceValue"); + max = 31; + test = asciiAlphanumeric; + return value(code); + } + + /** + * After `#`, at `x` for hexadecimals or digit for decimals. + * + * ```markdown + * > | a{b + * ^ + * > | a b + * ^ + * ``` + * + * @type {State} + */ + function numeric(code) { + if (code === 88 || code === 120) { + effects.enter("characterReferenceMarkerHexadecimal"); + effects.consume(code); + effects.exit("characterReferenceMarkerHexadecimal"); + effects.enter("characterReferenceValue"); + max = 6; + test = asciiHexDigit; + return value; + } + effects.enter("characterReferenceValue"); + max = 7; + test = asciiDigit; + return value(code); + } + + /** + * After markers (`&#x`, `&#`, or `&`), in value, before `;`. + * + * The character reference kind defines what and how many characters are + * allowed. + * + * ```markdown + * > | a&b + * ^^^ + * > | a{b + * ^^^ + * > | a b + * ^ + * ``` + * + * @type {State} + */ + function value(code) { + if (code === 59 && size) { + const token = effects.exit("characterReferenceValue"); + if (test === asciiAlphanumeric && !decodeNamedCharacterReference(self.sliceSerialize(token))) { + return nok(code); + } + + // To do: `markdown-rs` uses a different name: + // `CharacterReferenceMarkerSemi`. + effects.enter("characterReferenceMarker"); + effects.consume(code); + effects.exit("characterReferenceMarker"); + effects.exit("characterReference"); + return ok; + } + if (test(code) && size++ < max) { + effects.consume(code); + return value; + } + return nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-fenced.d.ts b/node_modules/micromark-core-commonmark/lib/code-fenced.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..6d5f5320e90c09fc3b7e2a2b3c8748a7434aa64d --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-fenced.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const codeFenced: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=code-fenced.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-fenced.d.ts.map b/node_modules/micromark-core-commonmark/lib/code-fenced.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..b0c28b2d96aa42605169d38e45403610eedd7f50 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-fenced.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"code-fenced.d.ts","sourceRoot":"","sources":["code-fenced.js"],"names":[],"mappings":"AAqBA,wBAAwB;AACxB,yBADW,SAAS,CAKnB;+BAnBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-fenced.js b/node_modules/micromark-core-commonmark/lib/code-fenced.js new file mode 100644 index 0000000000000000000000000000000000000000..3fe1407189a12674ef4b110312130e1624b7e746 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-fenced.js @@ -0,0 +1,460 @@ +/** + * @import { + * Code, + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding, markdownSpace } from 'micromark-util-character'; +/** @type {Construct} */ +const nonLazyContinuation = { + partial: true, + tokenize: tokenizeNonLazyContinuation +}; + +/** @type {Construct} */ +export const codeFenced = { + concrete: true, + name: 'codeFenced', + tokenize: tokenizeCodeFenced +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCodeFenced(effects, ok, nok) { + const self = this; + /** @type {Construct} */ + const closeStart = { + partial: true, + tokenize: tokenizeCloseStart + }; + let initialPrefix = 0; + let sizeOpen = 0; + /** @type {NonNullable} */ + let marker; + return start; + + /** + * Start of code. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function start(code) { + // To do: parse whitespace like `markdown-rs`. + return beforeSequenceOpen(code); + } + + /** + * In opening fence, after prefix, at sequence. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function beforeSequenceOpen(code) { + const tail = self.events[self.events.length - 1]; + initialPrefix = tail && tail[1].type === "linePrefix" ? tail[2].sliceSerialize(tail[1], true).length : 0; + marker = code; + effects.enter("codeFenced"); + effects.enter("codeFencedFence"); + effects.enter("codeFencedFenceSequence"); + return sequenceOpen(code); + } + + /** + * In opening fence sequence. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function sequenceOpen(code) { + if (code === marker) { + sizeOpen++; + effects.consume(code); + return sequenceOpen; + } + if (sizeOpen < 3) { + return nok(code); + } + effects.exit("codeFencedFenceSequence"); + return markdownSpace(code) ? factorySpace(effects, infoBefore, "whitespace")(code) : infoBefore(code); + } + + /** + * In opening fence, after the sequence (and optional whitespace), before info. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function infoBefore(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("codeFencedFence"); + return self.interrupt ? ok(code) : effects.check(nonLazyContinuation, atNonLazyBreak, after)(code); + } + effects.enter("codeFencedFenceInfo"); + effects.enter("chunkString", { + contentType: "string" + }); + return info(code); + } + + /** + * In info. + * + * ```markdown + * > | ~~~js + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function info(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("chunkString"); + effects.exit("codeFencedFenceInfo"); + return infoBefore(code); + } + if (markdownSpace(code)) { + effects.exit("chunkString"); + effects.exit("codeFencedFenceInfo"); + return factorySpace(effects, metaBefore, "whitespace")(code); + } + if (code === 96 && code === marker) { + return nok(code); + } + effects.consume(code); + return info; + } + + /** + * In opening fence, after info and whitespace, before meta. + * + * ```markdown + * > | ~~~js eval + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function metaBefore(code) { + if (code === null || markdownLineEnding(code)) { + return infoBefore(code); + } + effects.enter("codeFencedFenceMeta"); + effects.enter("chunkString", { + contentType: "string" + }); + return meta(code); + } + + /** + * In meta. + * + * ```markdown + * > | ~~~js eval + * ^ + * | alert(1) + * | ~~~ + * ``` + * + * @type {State} + */ + function meta(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("chunkString"); + effects.exit("codeFencedFenceMeta"); + return infoBefore(code); + } + if (code === 96 && code === marker) { + return nok(code); + } + effects.consume(code); + return meta; + } + + /** + * At eol/eof in code, before a non-lazy closing fence or content. + * + * ```markdown + * > | ~~~js + * ^ + * > | alert(1) + * ^ + * | ~~~ + * ``` + * + * @type {State} + */ + function atNonLazyBreak(code) { + return effects.attempt(closeStart, after, contentBefore)(code); + } + + /** + * Before code content, not a closing fence, at eol. + * + * ```markdown + * | ~~~js + * > | alert(1) + * ^ + * | ~~~ + * ``` + * + * @type {State} + */ + function contentBefore(code) { + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return contentStart; + } + + /** + * Before code content, not a closing fence. + * + * ```markdown + * | ~~~js + * > | alert(1) + * ^ + * | ~~~ + * ``` + * + * @type {State} + */ + function contentStart(code) { + return initialPrefix > 0 && markdownSpace(code) ? factorySpace(effects, beforeContentChunk, "linePrefix", initialPrefix + 1)(code) : beforeContentChunk(code); + } + + /** + * Before code content, after optional prefix. + * + * ```markdown + * | ~~~js + * > | alert(1) + * ^ + * | ~~~ + * ``` + * + * @type {State} + */ + function beforeContentChunk(code) { + if (code === null || markdownLineEnding(code)) { + return effects.check(nonLazyContinuation, atNonLazyBreak, after)(code); + } + effects.enter("codeFlowValue"); + return contentChunk(code); + } + + /** + * In code content. + * + * ```markdown + * | ~~~js + * > | alert(1) + * ^^^^^^^^ + * | ~~~ + * ``` + * + * @type {State} + */ + function contentChunk(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("codeFlowValue"); + return beforeContentChunk(code); + } + effects.consume(code); + return contentChunk; + } + + /** + * After code. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + effects.exit("codeFenced"); + return ok(code); + } + + /** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ + function tokenizeCloseStart(effects, ok, nok) { + let size = 0; + return startBefore; + + /** + * + * + * @type {State} + */ + function startBefore(code) { + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return start; + } + + /** + * Before closing fence, at optional whitespace. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // Always populated by defaults. + + // To do: `enter` here or in next state? + effects.enter("codeFencedFence"); + return markdownSpace(code) ? factorySpace(effects, beforeSequenceClose, "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4)(code) : beforeSequenceClose(code); + } + + /** + * In closing fence, after optional whitespace, at sequence. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function beforeSequenceClose(code) { + if (code === marker) { + effects.enter("codeFencedFenceSequence"); + return sequenceClose(code); + } + return nok(code); + } + + /** + * In closing fence sequence. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function sequenceClose(code) { + if (code === marker) { + size++; + effects.consume(code); + return sequenceClose; + } + if (size >= sizeOpen) { + effects.exit("codeFencedFenceSequence"); + return markdownSpace(code) ? factorySpace(effects, sequenceCloseAfter, "whitespace")(code) : sequenceCloseAfter(code); + } + return nok(code); + } + + /** + * After closing fence sequence, after optional whitespace. + * + * ```markdown + * | ~~~js + * | alert(1) + * > | ~~~ + * ^ + * ``` + * + * @type {State} + */ + function sequenceCloseAfter(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("codeFencedFence"); + return ok(code); + } + return nok(code); + } + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeNonLazyContinuation(effects, ok, nok) { + const self = this; + return start; + + /** + * + * + * @type {State} + */ + function start(code) { + if (code === null) { + return nok(code); + } + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return lineStart; + } + + /** + * + * + * @type {State} + */ + function lineStart(code) { + return self.parser.lazy[self.now().line] ? nok(code) : ok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-indented.d.ts b/node_modules/micromark-core-commonmark/lib/code-indented.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..3c06578bab6c0f9f73a7b88e3ee260db52ca5fa4 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-indented.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const codeIndented: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=code-indented.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-indented.d.ts.map b/node_modules/micromark-core-commonmark/lib/code-indented.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..099be93959e1da2e65f4924ed2b38877c736b22a --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-indented.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"code-indented.d.ts","sourceRoot":"","sources":["code-indented.js"],"names":[],"mappings":"AAcA,wBAAwB;AACxB,2BADW,SAAS,CAInB;+BAZS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-indented.js b/node_modules/micromark-core-commonmark/lib/code-indented.js new file mode 100644 index 0000000000000000000000000000000000000000..cde9a8719de9da36184814c48376496d512e2496 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-indented.js @@ -0,0 +1,177 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding, markdownSpace } from 'micromark-util-character'; +/** @type {Construct} */ +export const codeIndented = { + name: 'codeIndented', + tokenize: tokenizeCodeIndented +}; + +/** @type {Construct} */ +const furtherStart = { + partial: true, + tokenize: tokenizeFurtherStart +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCodeIndented(effects, ok, nok) { + const self = this; + return start; + + /** + * Start of code (indented). + * + * > **Parsing note**: it is not needed to check if this first line is a + * > filled line (that it has a non-whitespace character), because blank lines + * > are parsed already, so we never run into that. + * + * ```markdown + * > | aaa + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // To do: manually check if interrupting like `markdown-rs`. + + effects.enter("codeIndented"); + // To do: use an improved `space_or_tab` function like `markdown-rs`, + // so that we can drop the next state. + return factorySpace(effects, afterPrefix, "linePrefix", 4 + 1)(code); + } + + /** + * At start, after 1 or 4 spaces. + * + * ```markdown + * > | aaa + * ^ + * ``` + * + * @type {State} + */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1]; + return tail && tail[1].type === "linePrefix" && tail[2].sliceSerialize(tail[1], true).length >= 4 ? atBreak(code) : nok(code); + } + + /** + * At a break. + * + * ```markdown + * > | aaa + * ^ ^ + * ``` + * + * @type {State} + */ + function atBreak(code) { + if (code === null) { + return after(code); + } + if (markdownLineEnding(code)) { + return effects.attempt(furtherStart, atBreak, after)(code); + } + effects.enter("codeFlowValue"); + return inside(code); + } + + /** + * In code content. + * + * ```markdown + * > | aaa + * ^^^^ + * ``` + * + * @type {State} + */ + function inside(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("codeFlowValue"); + return atBreak(code); + } + effects.consume(code); + return inside; + } + + /** @type {State} */ + function after(code) { + effects.exit("codeIndented"); + // To do: allow interrupting like `markdown-rs`. + // Feel free to interrupt. + // tokenizer.interrupt = false + return ok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeFurtherStart(effects, ok, nok) { + const self = this; + return furtherStart; + + /** + * At eol, trying to parse another indent. + * + * ```markdown + * > | aaa + * ^ + * | bbb + * ``` + * + * @type {State} + */ + function furtherStart(code) { + // To do: improve `lazy` / `pierce` handling. + // If this is a lazy line, it can’t be code. + if (self.parser.lazy[self.now().line]) { + return nok(code); + } + if (markdownLineEnding(code)) { + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return furtherStart; + } + + // To do: the code here in `micromark-js` is a bit different from + // `markdown-rs` because there it can attempt spaces. + // We can’t yet. + // + // To do: use an improved `space_or_tab` function like `markdown-rs`, + // so that we can drop the next state. + return factorySpace(effects, afterPrefix, "linePrefix", 4 + 1)(code); + } + + /** + * At start, after 1 or 4 spaces. + * + * ```markdown + * > | aaa + * ^ + * ``` + * + * @type {State} + */ + function afterPrefix(code) { + const tail = self.events[self.events.length - 1]; + return tail && tail[1].type === "linePrefix" && tail[2].sliceSerialize(tail[1], true).length >= 4 ? ok(code) : markdownLineEnding(code) ? furtherStart(code) : nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-text.d.ts b/node_modules/micromark-core-commonmark/lib/code-text.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..8047b2c2204dcc2fc21094b69a06ba36881fc3fb --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-text.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const codeText: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=code-text.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-text.d.ts.map b/node_modules/micromark-core-commonmark/lib/code-text.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..d5558209fb9b70b3beeee714341631158163311a --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-text.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"code-text.d.ts","sourceRoot":"","sources":["code-text.js"],"names":[],"mappings":"AAgBA,wBAAwB;AACxB,uBADW,SAAS,CAMnB;+BAbS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/code-text.js b/node_modules/micromark-core-commonmark/lib/code-text.js new file mode 100644 index 0000000000000000000000000000000000000000..c31568e892015ff204b81f0693506bd1a20069c6 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/code-text.js @@ -0,0 +1,225 @@ +/** + * @import { + * Construct, + * Previous, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import { markdownLineEnding } from 'micromark-util-character'; +/** @type {Construct} */ +export const codeText = { + name: 'codeText', + previous, + resolve: resolveCodeText, + tokenize: tokenizeCodeText +}; + +// To do: next major: don’t resolve, like `markdown-rs`. +/** @type {Resolver} */ +function resolveCodeText(events) { + let tailExitIndex = events.length - 4; + let headEnterIndex = 3; + /** @type {number} */ + let index; + /** @type {number | undefined} */ + let enter; + + // If we start and end with an EOL or a space. + if ((events[headEnterIndex][1].type === "lineEnding" || events[headEnterIndex][1].type === 'space') && (events[tailExitIndex][1].type === "lineEnding" || events[tailExitIndex][1].type === 'space')) { + index = headEnterIndex; + + // And we have data. + while (++index < tailExitIndex) { + if (events[index][1].type === "codeTextData") { + // Then we have padding. + events[headEnterIndex][1].type = "codeTextPadding"; + events[tailExitIndex][1].type = "codeTextPadding"; + headEnterIndex += 2; + tailExitIndex -= 2; + break; + } + } + } + + // Merge adjacent spaces and data. + index = headEnterIndex - 1; + tailExitIndex++; + while (++index <= tailExitIndex) { + if (enter === undefined) { + if (index !== tailExitIndex && events[index][1].type !== "lineEnding") { + enter = index; + } + } else if (index === tailExitIndex || events[index][1].type === "lineEnding") { + events[enter][1].type = "codeTextData"; + if (index !== enter + 2) { + events[enter][1].end = events[index - 1][1].end; + events.splice(enter + 2, index - enter - 2); + tailExitIndex -= index - enter - 2; + index = enter + 2; + } + enter = undefined; + } + } + return events; +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Previous} + */ +function previous(code) { + // If there is a previous code, there will always be a tail. + return code !== 96 || this.events[this.events.length - 1][1].type === "characterEscape"; +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeCodeText(effects, ok, nok) { + const self = this; + let sizeOpen = 0; + /** @type {number} */ + let size; + /** @type {Token} */ + let token; + return start; + + /** + * Start of code (text). + * + * ```markdown + * > | `a` + * ^ + * > | \`a` + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("codeText"); + effects.enter("codeTextSequence"); + return sequenceOpen(code); + } + + /** + * In opening sequence. + * + * ```markdown + * > | `a` + * ^ + * ``` + * + * @type {State} + */ + function sequenceOpen(code) { + if (code === 96) { + effects.consume(code); + sizeOpen++; + return sequenceOpen; + } + effects.exit("codeTextSequence"); + return between(code); + } + + /** + * Between something and something else. + * + * ```markdown + * > | `a` + * ^^ + * ``` + * + * @type {State} + */ + function between(code) { + // EOF. + if (code === null) { + return nok(code); + } + + // To do: next major: don’t do spaces in resolve, but when compiling, + // like `markdown-rs`. + // Tabs don’t work, and virtual spaces don’t make sense. + if (code === 32) { + effects.enter('space'); + effects.consume(code); + effects.exit('space'); + return between; + } + + // Closing fence? Could also be data. + if (code === 96) { + token = effects.enter("codeTextSequence"); + size = 0; + return sequenceClose(code); + } + if (markdownLineEnding(code)) { + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return between; + } + + // Data. + effects.enter("codeTextData"); + return data(code); + } + + /** + * In data. + * + * ```markdown + * > | `a` + * ^ + * ``` + * + * @type {State} + */ + function data(code) { + if (code === null || code === 32 || code === 96 || markdownLineEnding(code)) { + effects.exit("codeTextData"); + return between(code); + } + effects.consume(code); + return data; + } + + /** + * In closing sequence. + * + * ```markdown + * > | `a` + * ^ + * ``` + * + * @type {State} + */ + function sequenceClose(code) { + // More. + if (code === 96) { + effects.consume(code); + size++; + return sequenceClose; + } + + // Done! + if (size === sizeOpen) { + effects.exit("codeTextSequence"); + effects.exit("codeText"); + return ok(code); + } + + // More or less accents: mark as data. + token.type = "codeTextData"; + return data(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/content.d.ts b/node_modules/micromark-core-commonmark/lib/content.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..eec537f9fdae61cfeefbff08e8211eed56228381 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/content.d.ts @@ -0,0 +1,7 @@ +/** + * No name because it must not be turned off. + * @type {Construct} + */ +export const content: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=content.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/content.d.ts.map b/node_modules/micromark-core-commonmark/lib/content.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..04ed7089749a041b50aa38f1ab4e94589ebed860 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/content.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["content.js"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,sBAFU,SAAS,CAEwD;+BAbjE,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/content.js b/node_modules/micromark-core-commonmark/lib/content.js new file mode 100644 index 0000000000000000000000000000000000000000..507bdb49e1ae551f8b774bdd80a4405ab0a07d0f --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/content.js @@ -0,0 +1,163 @@ +/** + * @import { + * Construct, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEnding } from 'micromark-util-character'; +import { subtokenize } from 'micromark-util-subtokenize'; +/** + * No name because it must not be turned off. + * @type {Construct} + */ +export const content = { + resolve: resolveContent, + tokenize: tokenizeContent +}; + +/** @type {Construct} */ +const continuationConstruct = { + partial: true, + tokenize: tokenizeContinuation +}; + +/** + * Content is transparent: it’s parsed right now. That way, definitions are also + * parsed right now: before text in paragraphs (specifically, media) are parsed. + * + * @type {Resolver} + */ +function resolveContent(events) { + subtokenize(events); + return events; +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeContent(effects, ok) { + /** @type {Token | undefined} */ + let previous; + return chunkStart; + + /** + * Before a content chunk. + * + * ```markdown + * > | abc + * ^ + * ``` + * + * @type {State} + */ + function chunkStart(code) { + effects.enter("content"); + previous = effects.enter("chunkContent", { + contentType: "content" + }); + return chunkInside(code); + } + + /** + * In a content chunk. + * + * ```markdown + * > | abc + * ^^^ + * ``` + * + * @type {State} + */ + function chunkInside(code) { + if (code === null) { + return contentEnd(code); + } + + // To do: in `markdown-rs`, each line is parsed on its own, and everything + // is stitched together resolving. + if (markdownLineEnding(code)) { + return effects.check(continuationConstruct, contentContinue, contentEnd)(code); + } + + // Data. + effects.consume(code); + return chunkInside; + } + + /** + * + * + * @type {State} + */ + function contentEnd(code) { + effects.exit("chunkContent"); + effects.exit("content"); + return ok(code); + } + + /** + * + * + * @type {State} + */ + function contentContinue(code) { + effects.consume(code); + effects.exit("chunkContent"); + previous.next = effects.enter("chunkContent", { + contentType: "content", + previous + }); + previous = previous.next; + return chunkInside; + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeContinuation(effects, ok, nok) { + const self = this; + return startLookahead; + + /** + * + * + * @type {State} + */ + function startLookahead(code) { + effects.exit("chunkContent"); + effects.enter("lineEnding"); + effects.consume(code); + effects.exit("lineEnding"); + return factorySpace(effects, prefixed, "linePrefix"); + } + + /** + * + * + * @type {State} + */ + function prefixed(code) { + if (code === null || markdownLineEnding(code)) { + return nok(code); + } + + // Always populated by defaults. + + const tail = self.events[self.events.length - 1]; + if (!self.parser.constructs.disable.null.includes('codeIndented') && tail && tail[1].type === "linePrefix" && tail[2].sliceSerialize(tail[1], true).length >= 4) { + return ok(code); + } + return effects.interrupt(self.parser.constructs.flow, nok, ok)(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/definition.d.ts b/node_modules/micromark-core-commonmark/lib/definition.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..f5a46930596f28abf7c913481080928e132a4ae0 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/definition.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const definition: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=definition.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/definition.d.ts.map b/node_modules/micromark-core-commonmark/lib/definition.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..46a16d3ad245346b876d819a8c326ce0d6da5d43 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/definition.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["definition.js"],"names":[],"mappings":"AAuBA,wBAAwB;AACxB,yBADW,SAAS,CACwD;+BAlBlE,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/definition.js b/node_modules/micromark-core-commonmark/lib/definition.js new file mode 100644 index 0000000000000000000000000000000000000000..5c74e9723835696280876a877d8664bca2cfbc6a --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/definition.js @@ -0,0 +1,254 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { factoryDestination } from 'micromark-factory-destination'; +import { factoryLabel } from 'micromark-factory-label'; +import { factorySpace } from 'micromark-factory-space'; +import { factoryTitle } from 'micromark-factory-title'; +import { factoryWhitespace } from 'micromark-factory-whitespace'; +import { markdownLineEndingOrSpace, markdownLineEnding, markdownSpace } from 'micromark-util-character'; +import { normalizeIdentifier } from 'micromark-util-normalize-identifier'; +/** @type {Construct} */ +export const definition = { + name: 'definition', + tokenize: tokenizeDefinition +}; + +/** @type {Construct} */ +const titleBefore = { + partial: true, + tokenize: tokenizeTitleBefore +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeDefinition(effects, ok, nok) { + const self = this; + /** @type {string} */ + let identifier; + return start; + + /** + * At start of a definition. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // Do not interrupt paragraphs (but do follow definitions). + // To do: do `interrupt` the way `markdown-rs` does. + // To do: parse whitespace the way `markdown-rs` does. + effects.enter("definition"); + return before(code); + } + + /** + * After optional whitespace, at `[`. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + // To do: parse whitespace the way `markdown-rs` does. + + return factoryLabel.call(self, effects, labelAfter, + // Note: we don’t need to reset the way `markdown-rs` does. + nok, "definitionLabel", "definitionLabelMarker", "definitionLabelString")(code); + } + + /** + * After label. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function labelAfter(code) { + identifier = normalizeIdentifier(self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1)); + if (code === 58) { + effects.enter("definitionMarker"); + effects.consume(code); + effects.exit("definitionMarker"); + return markerAfter; + } + return nok(code); + } + + /** + * After marker. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function markerAfter(code) { + // Note: whitespace is optional. + return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, destinationBefore)(code) : destinationBefore(code); + } + + /** + * Before destination. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function destinationBefore(code) { + return factoryDestination(effects, destinationAfter, + // Note: we don’t need to reset the way `markdown-rs` does. + nok, "definitionDestination", "definitionDestinationLiteral", "definitionDestinationLiteralMarker", "definitionDestinationRaw", "definitionDestinationString")(code); + } + + /** + * After destination. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function destinationAfter(code) { + return effects.attempt(titleBefore, after, after)(code); + } + + /** + * After definition. + * + * ```markdown + * > | [a]: b + * ^ + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function after(code) { + return markdownSpace(code) ? factorySpace(effects, afterWhitespace, "whitespace")(code) : afterWhitespace(code); + } + + /** + * After definition, after optional whitespace. + * + * ```markdown + * > | [a]: b + * ^ + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function afterWhitespace(code) { + if (code === null || markdownLineEnding(code)) { + effects.exit("definition"); + + // Note: we don’t care about uniqueness. + // It’s likely that that doesn’t happen very frequently. + // It is more likely that it wastes precious time. + self.parser.defined.push(identifier); + + // To do: `markdown-rs` interrupt. + // // You’d be interrupting. + // tokenizer.interrupt = true + return ok(code); + } + return nok(code); + } +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeTitleBefore(effects, ok, nok) { + return titleBefore; + + /** + * After destination, at whitespace. + * + * ```markdown + * > | [a]: b + * ^ + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function titleBefore(code) { + return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, beforeMarker)(code) : nok(code); + } + + /** + * At title. + * + * ```markdown + * | [a]: b + * > | "c" + * ^ + * ``` + * + * @type {State} + */ + function beforeMarker(code) { + return factoryTitle(effects, titleAfter, nok, "definitionTitle", "definitionTitleMarker", "definitionTitleString")(code); + } + + /** + * After title. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function titleAfter(code) { + return markdownSpace(code) ? factorySpace(effects, titleAfterOptionalWhitespace, "whitespace")(code) : titleAfterOptionalWhitespace(code); + } + + /** + * After title, after optional whitespace. + * + * ```markdown + * > | [a]: b "c" + * ^ + * ``` + * + * @type {State} + */ + function titleAfterOptionalWhitespace(code) { + return code === null || markdownLineEnding(code) ? ok(code) : nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/hard-break-escape.d.ts b/node_modules/micromark-core-commonmark/lib/hard-break-escape.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..eff01b324e2a82400b61eaecc7c842f6f8765865 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/hard-break-escape.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const hardBreakEscape: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=hard-break-escape.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/hard-break-escape.d.ts.map b/node_modules/micromark-core-commonmark/lib/hard-break-escape.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..923753ce13d86326b96e42e9de1a5674fbad0deb --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/hard-break-escape.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"hard-break-escape.d.ts","sourceRoot":"","sources":["hard-break-escape.js"],"names":[],"mappings":"AAaA,wBAAwB;AACxB,8BADW,SAAS,CAInB;+BAXS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/hard-break-escape.js b/node_modules/micromark-core-commonmark/lib/hard-break-escape.js new file mode 100644 index 0000000000000000000000000000000000000000..530ade444940b25445aa831a8161a7d5ae6cb079 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/hard-break-escape.js @@ -0,0 +1,60 @@ +/** + * @import { + * Construct, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { markdownLineEnding } from 'micromark-util-character'; +/** @type {Construct} */ +export const hardBreakEscape = { + name: 'hardBreakEscape', + tokenize: tokenizeHardBreakEscape +}; + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeHardBreakEscape(effects, ok, nok) { + return start; + + /** + * Start of a hard break (escape). + * + * ```markdown + * > | a\ + * ^ + * | b + * ``` + * + * @type {State} + */ + function start(code) { + effects.enter("hardBreakEscape"); + effects.consume(code); + return after; + } + + /** + * After `\`, at eol. + * + * ```markdown + * > | a\ + * ^ + * | b + * ``` + * + * @type {State} + */ + function after(code) { + if (markdownLineEnding(code)) { + effects.exit("hardBreakEscape"); + return ok(code); + } + return nok(code); + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/heading-atx.d.ts b/node_modules/micromark-core-commonmark/lib/heading-atx.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..a08353b6c5f1798ffd4e7ea29705a9b07d5ca9db --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/heading-atx.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const headingAtx: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=heading-atx.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/heading-atx.d.ts.map b/node_modules/micromark-core-commonmark/lib/heading-atx.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..8c8eebf31f2cfe32ca43e83fba9fc5d24bf786ea --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/heading-atx.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"heading-atx.d.ts","sourceRoot":"","sources":["heading-atx.js"],"names":[],"mappings":"AAqBA,wBAAwB;AACxB,yBADW,SAAS,CAKnB;+BAlBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/heading-atx.js b/node_modules/micromark-core-commonmark/lib/heading-atx.js new file mode 100644 index 0000000000000000000000000000000000000000..39db4a4555261a8c991789d8f529d4b3ce482809 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/heading-atx.js @@ -0,0 +1,195 @@ +/** + * @import { + * Construct, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer, + * Token + * } from 'micromark-util-types' + */ + +import { factorySpace } from 'micromark-factory-space'; +import { markdownLineEndingOrSpace, markdownLineEnding, markdownSpace } from 'micromark-util-character'; +import { splice } from 'micromark-util-chunked'; +/** @type {Construct} */ +export const headingAtx = { + name: 'headingAtx', + resolve: resolveHeadingAtx, + tokenize: tokenizeHeadingAtx +}; + +/** @type {Resolver} */ +function resolveHeadingAtx(events, context) { + let contentEnd = events.length - 2; + let contentStart = 3; + /** @type {Token} */ + let content; + /** @type {Token} */ + let text; + + // Prefix whitespace, part of the opening. + if (events[contentStart][1].type === "whitespace") { + contentStart += 2; + } + + // Suffix whitespace, part of the closing. + if (contentEnd - 2 > contentStart && events[contentEnd][1].type === "whitespace") { + contentEnd -= 2; + } + if (events[contentEnd][1].type === "atxHeadingSequence" && (contentStart === contentEnd - 1 || contentEnd - 4 > contentStart && events[contentEnd - 2][1].type === "whitespace")) { + contentEnd -= contentStart + 1 === contentEnd ? 2 : 4; + } + if (contentEnd > contentStart) { + content = { + type: "atxHeadingText", + start: events[contentStart][1].start, + end: events[contentEnd][1].end + }; + text = { + type: "chunkText", + start: events[contentStart][1].start, + end: events[contentEnd][1].end, + contentType: "text" + }; + splice(events, contentStart, contentEnd - contentStart + 1, [['enter', content, context], ['enter', text, context], ['exit', text, context], ['exit', content, context]]); + } + return events; +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeHeadingAtx(effects, ok, nok) { + let size = 0; + return start; + + /** + * Start of a heading (atx). + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // To do: parse indent like `markdown-rs`. + effects.enter("atxHeading"); + return before(code); + } + + /** + * After optional whitespace, at `#`. + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + effects.enter("atxHeadingSequence"); + return sequenceOpen(code); + } + + /** + * In opening sequence. + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function sequenceOpen(code) { + if (code === 35 && size++ < 6) { + effects.consume(code); + return sequenceOpen; + } + + // Always at least one `#`. + if (code === null || markdownLineEndingOrSpace(code)) { + effects.exit("atxHeadingSequence"); + return atBreak(code); + } + return nok(code); + } + + /** + * After something, before something else. + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function atBreak(code) { + if (code === 35) { + effects.enter("atxHeadingSequence"); + return sequenceFurther(code); + } + if (code === null || markdownLineEnding(code)) { + effects.exit("atxHeading"); + // To do: interrupt like `markdown-rs`. + // // Feel free to interrupt. + // tokenizer.interrupt = false + return ok(code); + } + if (markdownSpace(code)) { + return factorySpace(effects, atBreak, "whitespace")(code); + } + + // To do: generate `data` tokens, add the `text` token later. + // Needs edit map, see: `markdown.rs`. + effects.enter("atxHeadingText"); + return data(code); + } + + /** + * In further sequence (after whitespace). + * + * Could be normal “visible” hashes in the heading or a final sequence. + * + * ```markdown + * > | ## aa ## + * ^ + * ``` + * + * @type {State} + */ + function sequenceFurther(code) { + if (code === 35) { + effects.consume(code); + return sequenceFurther; + } + effects.exit("atxHeadingSequence"); + return atBreak(code); + } + + /** + * In text. + * + * ```markdown + * > | ## aa + * ^ + * ``` + * + * @type {State} + */ + function data(code) { + if (code === null || code === 35 || markdownLineEndingOrSpace(code)) { + effects.exit("atxHeadingText"); + return atBreak(code); + } + effects.consume(code); + return data; + } +} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/html-flow.d.ts b/node_modules/micromark-core-commonmark/lib/html-flow.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..83fa70cd1b092c05d7d32527bc43aef4b7c4baa3 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/html-flow.d.ts @@ -0,0 +1,4 @@ +/** @type {Construct} */ +export const htmlFlow: Construct; +import type { Construct } from 'micromark-util-types'; +//# sourceMappingURL=html-flow.d.ts.map \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/html-flow.d.ts.map b/node_modules/micromark-core-commonmark/lib/html-flow.d.ts.map new file mode 100644 index 0000000000000000000000000000000000000000..1a23a6fde0f60733d2f8ab684f91172a97f1a661 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/html-flow.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"html-flow.d.ts","sourceRoot":"","sources":["html-flow.js"],"names":[],"mappings":"AAuBA,wBAAwB;AACxB,uBADW,SAAS,CAMnB;+BArBS,sBAAsB"} \ No newline at end of file diff --git a/node_modules/micromark-core-commonmark/lib/html-flow.js b/node_modules/micromark-core-commonmark/lib/html-flow.js new file mode 100644 index 0000000000000000000000000000000000000000..2d4b5f39f127fc23a8803bface2f309eddb19231 --- /dev/null +++ b/node_modules/micromark-core-commonmark/lib/html-flow.js @@ -0,0 +1,876 @@ +/** + * @import { + * Code, + * Construct, + * Resolver, + * State, + * TokenizeContext, + * Tokenizer + * } from 'micromark-util-types' + */ + +import { asciiAlphanumeric, asciiAlpha, markdownLineEndingOrSpace, markdownLineEnding, markdownSpace } from 'micromark-util-character'; +import { htmlBlockNames, htmlRawNames } from 'micromark-util-html-tag-name'; +import { blankLine } from './blank-line.js'; + +/** @type {Construct} */ +export const htmlFlow = { + concrete: true, + name: 'htmlFlow', + resolveTo: resolveToHtmlFlow, + tokenize: tokenizeHtmlFlow +}; + +/** @type {Construct} */ +const blankLineBefore = { + partial: true, + tokenize: tokenizeBlankLineBefore +}; +const nonLazyContinuationStart = { + partial: true, + tokenize: tokenizeNonLazyContinuationStart +}; + +/** @type {Resolver} */ +function resolveToHtmlFlow(events) { + let index = events.length; + while (index--) { + if (events[index][0] === 'enter' && events[index][1].type === "htmlFlow") { + break; + } + } + if (index > 1 && events[index - 2][1].type === "linePrefix") { + // Add the prefix start to the HTML token. + events[index][1].start = events[index - 2][1].start; + // Add the prefix start to the HTML line token. + events[index + 1][1].start = events[index - 2][1].start; + // Remove the line prefix. + events.splice(index - 2, 2); + } + return events; +} + +/** + * @this {TokenizeContext} + * Context. + * @type {Tokenizer} + */ +function tokenizeHtmlFlow(effects, ok, nok) { + const self = this; + /** @type {number} */ + let marker; + /** @type {boolean} */ + let closingTag; + /** @type {string} */ + let buffer; + /** @type {number} */ + let index; + /** @type {Code} */ + let markerB; + return start; + + /** + * Start of HTML (flow). + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function start(code) { + // To do: parse indent like `markdown-rs`. + return before(code); + } + + /** + * At `<`, after optional whitespace. + * + * ```markdown + * > | + * ^ + * ``` + * + * @type {State} + */ + function before(code) { + effects.enter("htmlFlow"); + effects.enter("htmlFlowData"); + effects.consume(code); + return open; + } + + /** + * After `<`, at tag name or other stuff. + * + * ```markdown + * > | + * ^ + * > | + * ^ + * > | + * ^ + * ``` + * + * @type {State} + */ + function open(code) { + if (code === 33) { + effects.consume(code); + return declarationOpen; + } + if (code === 47) { + effects.consume(code); + closingTag = true; + return tagCloseStart; + } + if (code === 63) { + effects.consume(code); + marker = 3; + // To do: + // tokenizer.concrete = true + // To do: use `markdown-rs` style interrupt. + // While we’re in an instruction instead of a declaration, we’re on a `?` + // right now, so we do need to search for `>`, similar to declarations. + return self.interrupt ? ok : continuationDeclarationInside; + } + + // ASCII alphabetical. + if (asciiAlpha(code)) { + // Always the case. + effects.consume(code); + buffer = String.fromCharCode(code); + return tagName; + } + return nok(code); + } + + /** + * After ` | + * ^ + * > | + * ^ + * > | &<]]> + * ^ + * ``` + * + * @type {State} + */ + function declarationOpen(code) { + if (code === 45) { + effects.consume(code); + marker = 2; + return commentOpenInside; + } + if (code === 91) { + effects.consume(code); + marker = 5; + index = 0; + return cdataOpenInside; + } + + // ASCII alphabetical. + if (asciiAlpha(code)) { + effects.consume(code); + marker = 4; + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok : continuationDeclarationInside; + } + return nok(code); + } + + /** + * After ` | + * ^ + * ``` + * + * @type {State} + */ + function commentOpenInside(code) { + if (code === 45) { + effects.consume(code); + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok : continuationDeclarationInside; + } + return nok(code); + } + + /** + * After ` | &<]]> + * ^^^^^^ + * ``` + * + * @type {State} + */ + function cdataOpenInside(code) { + const value = "CDATA["; + if (code === value.charCodeAt(index++)) { + effects.consume(code); + if (index === value.length) { + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok : continuation; + } + return cdataOpenInside; + } + return nok(code); + } + + /** + * After ` | + * ^ + * ``` + * + * @type {State} + */ + function tagCloseStart(code) { + if (asciiAlpha(code)) { + // Always the case. + effects.consume(code); + buffer = String.fromCharCode(code); + return tagName; + } + return nok(code); + } + + /** + * In tag name. + * + * ```markdown + * > | + * ^^ + * > | + * ^^ + * ``` + * + * @type {State} + */ + function tagName(code) { + if (code === null || code === 47 || code === 62 || markdownLineEndingOrSpace(code)) { + const slash = code === 47; + const name = buffer.toLowerCase(); + if (!slash && !closingTag && htmlRawNames.includes(name)) { + marker = 1; + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok(code) : continuation(code); + } + if (htmlBlockNames.includes(buffer.toLowerCase())) { + marker = 6; + if (slash) { + effects.consume(code); + return basicSelfClosing; + } + + // // Do not form containers. + // tokenizer.concrete = true + return self.interrupt ? ok(code) : continuation(code); + } + marker = 7; + // Do not support complete HTML when interrupting. + return self.interrupt && !self.parser.lazy[self.now().line] ? nok(code) : closingTag ? completeClosingTagAfter(code) : completeAttributeNameBefore(code); + } + + // ASCII alphanumerical and `-`. + if (code === 45 || asciiAlphanumeric(code)) { + effects.consume(code); + buffer += String.fromCharCode(code); + return tagName; + } + return nok(code); + } + + /** + * After closing slash of a basic tag name. + * + * ```markdown + * > |