feat: use go tool

This commit is contained in:
2026-07-03 19:24:01 -04:00
parent 39548b4332
commit 4d0cab1fe0
1542 changed files with 252399 additions and 14 deletions
@@ -0,0 +1,4 @@
/** @type {Construct} */
export const directiveContainer: Construct;
import type { Construct } from 'micromark-util-types';
//# sourceMappingURL=directive-container.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"directive-container.d.ts","sourceRoot":"","sources":["directive-container.js"],"names":[],"mappings":"AAYA,wBAAwB;AACxB,iCADW,SAAS,CAInB;+BAfqE,sBAAsB"}
+259
View File
@@ -0,0 +1,259 @@
/**
* @import {Construct, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types'
*/
import { factorySpace } from 'micromark-factory-space';
import { markdownLineEnding } from 'micromark-util-character';
import { factoryAttributes } from './factory-attributes.js';
import { factoryLabel } from './factory-label.js';
import { factoryName } from './factory-name.js';
/** @type {Construct} */
export const directiveContainer = {
tokenize: tokenizeDirectiveContainer,
concrete: true
};
const label = {
tokenize: tokenizeLabel,
partial: true
};
const attributes = {
tokenize: tokenizeAttributes,
partial: true
};
const nonLazyLine = {
tokenize: tokenizeNonLazyLine,
partial: true
};
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeDirectiveContainer(effects, ok, nok) {
const self = this;
const tail = self.events[self.events.length - 1];
const initialSize = tail && tail[1].type === "linePrefix" ? tail[2].sliceSerialize(tail[1], true).length : 0;
let sizeOpen = 0;
/** @type {Token} */
let previous;
return start;
/** @type {State} */
function start(code) {
effects.enter('directiveContainer');
effects.enter('directiveContainerFence');
effects.enter('directiveContainerSequence');
return sequenceOpen(code);
}
/** @type {State} */
function sequenceOpen(code) {
if (code === 58) {
effects.consume(code);
sizeOpen++;
return sequenceOpen;
}
if (sizeOpen < 3) {
return nok(code);
}
effects.exit('directiveContainerSequence');
return factoryName.call(self, effects, afterName, nok, 'directiveContainerName')(code);
}
/** @type {State} */
function afterName(code) {
return code === 91 ? effects.attempt(label, afterLabel, afterLabel)(code) : afterLabel(code);
}
/** @type {State} */
function afterLabel(code) {
return code === 123 ? effects.attempt(attributes, afterAttributes, afterAttributes)(code) : afterAttributes(code);
}
/** @type {State} */
function afterAttributes(code) {
return factorySpace(effects, openAfter, "whitespace")(code);
}
/** @type {State} */
function openAfter(code) {
effects.exit('directiveContainerFence');
if (code === null) {
return after(code);
}
if (markdownLineEnding(code)) {
if (self.interrupt) {
return ok(code);
}
return effects.attempt(nonLazyLine, contentStart, after)(code);
}
return nok(code);
}
/** @type {State} */
function contentStart(code) {
if (code === null) {
return after(code);
}
if (markdownLineEnding(code)) {
return effects.check(nonLazyLine, emptyContentNonLazyLineAfter, after)(code);
}
effects.enter('directiveContainerContent');
return lineStart(code);
}
/** @type {State} */
function lineStart(code) {
return effects.attempt({
tokenize: tokenizeClosingFence,
partial: true
}, afterContent, initialSize ? factorySpace(effects, chunkStart, "linePrefix", initialSize + 1) : chunkStart)(code);
}
/** @type {State} */
function chunkStart(code) {
if (code === null) {
return afterContent(code);
}
if (markdownLineEnding(code)) {
return effects.check(nonLazyLine, chunkNonLazyStart, afterContent)(code);
}
return chunkNonLazyStart(code);
}
/** @type {State} */
function contentContinue(code) {
if (code === null) {
const t = effects.exit("chunkDocument");
self.parser.lazy[t.start.line] = false;
return afterContent(code);
}
if (markdownLineEnding(code)) {
return effects.check(nonLazyLine, nonLazyLineAfter, lineAfter)(code);
}
effects.consume(code);
return contentContinue;
}
/** @type {State} */
function chunkNonLazyStart(code) {
const token = effects.enter("chunkDocument", {
contentType: "document",
previous
});
if (previous) previous.next = token;
previous = token;
return contentContinue(code);
}
/** @type {State} */
function emptyContentNonLazyLineAfter(code) {
effects.enter('directiveContainerContent');
return lineStart(code);
}
/** @type {State} */
function nonLazyLineAfter(code) {
effects.consume(code);
const t = effects.exit("chunkDocument");
self.parser.lazy[t.start.line] = false;
return lineStart;
}
/** @type {State} */
function lineAfter(code) {
const t = effects.exit("chunkDocument");
self.parser.lazy[t.start.line] = false;
return afterContent(code);
}
/** @type {State} */
function afterContent(code) {
effects.exit('directiveContainerContent');
return after(code);
}
/** @type {State} */
function after(code) {
effects.exit('directiveContainer');
return ok(code);
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeClosingFence(effects, ok, nok) {
let size = 0;
return factorySpace(effects, closingPrefixAfter, "linePrefix", self.parser.constructs.disable.null.includes('codeIndented') ? undefined : 4);
/** @type {State} */
function closingPrefixAfter(code) {
effects.enter('directiveContainerFence');
effects.enter('directiveContainerSequence');
return closingSequence(code);
}
/** @type {State} */
function closingSequence(code) {
if (code === 58) {
effects.consume(code);
size++;
return closingSequence;
}
if (size < sizeOpen) return nok(code);
effects.exit('directiveContainerSequence');
return factorySpace(effects, closingSequenceEnd, "whitespace")(code);
}
/** @type {State} */
function closingSequenceEnd(code) {
if (code === null || markdownLineEnding(code)) {
effects.exit('directiveContainerFence');
return ok(code);
}
return nok(code);
}
}
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeLabel(effects, ok, nok) {
// Always a `[`
return factoryLabel(effects, ok, nok, 'directiveContainerLabel', 'directiveContainerLabelMarker', 'directiveContainerLabelString', true);
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeAttributes(effects, ok, nok) {
// Always a `{`
return factoryAttributes(effects, ok, nok, 'directiveContainerAttributes', 'directiveContainerAttributesMarker', 'directiveContainerAttribute', 'directiveContainerAttributeId', 'directiveContainerAttributeClass', 'directiveContainerAttributeName', 'directiveContainerAttributeInitializerMarker', 'directiveContainerAttributeValueLiteral', 'directiveContainerAttributeValue', 'directiveContainerAttributeValueMarker', 'directiveContainerAttributeValueData', true);
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeNonLazyLine(effects, ok, nok) {
const self = this;
return start;
/** @type {State} */
function start(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);
}
}
+4
View File
@@ -0,0 +1,4 @@
/** @type {Construct} */
export const directiveLeaf: Construct;
import type { Construct } from 'micromark-util-types';
//# sourceMappingURL=directive-leaf.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"directive-leaf.d.ts","sourceRoot":"","sources":["directive-leaf.js"],"names":[],"mappings":"AAYA,wBAAwB;AACxB,4BADW,SAAS,CAC0C;+BAZC,sBAAsB"}
+91
View File
@@ -0,0 +1,91 @@
/**
* @import {Construct, State, TokenizeContext, Tokenizer} from 'micromark-util-types'
*/
import { factorySpace } from 'micromark-factory-space';
import { markdownLineEnding } from 'micromark-util-character';
import { factoryAttributes } from './factory-attributes.js';
import { factoryLabel } from './factory-label.js';
import { factoryName } from './factory-name.js';
/** @type {Construct} */
export const directiveLeaf = {
tokenize: tokenizeDirectiveLeaf
};
const label = {
tokenize: tokenizeLabel,
partial: true
};
const attributes = {
tokenize: tokenizeAttributes,
partial: true
};
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeDirectiveLeaf(effects, ok, nok) {
const self = this;
return start;
/** @type {State} */
function start(code) {
effects.enter('directiveLeaf');
effects.enter('directiveLeafSequence');
effects.consume(code);
return inStart;
}
/** @type {State} */
function inStart(code) {
if (code === 58) {
effects.consume(code);
effects.exit('directiveLeafSequence');
return factoryName.call(self, effects, afterName, nok, 'directiveLeafName');
}
return nok(code);
}
/** @type {State} */
function afterName(code) {
return code === 91 ? effects.attempt(label, afterLabel, afterLabel)(code) : afterLabel(code);
}
/** @type {State} */
function afterLabel(code) {
return code === 123 ? effects.attempt(attributes, afterAttributes, afterAttributes)(code) : afterAttributes(code);
}
/** @type {State} */
function afterAttributes(code) {
return factorySpace(effects, end, "whitespace")(code);
}
/** @type {State} */
function end(code) {
if (code === null || markdownLineEnding(code)) {
effects.exit('directiveLeaf');
return ok(code);
}
return nok(code);
}
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeLabel(effects, ok, nok) {
// Always a `[`
return factoryLabel(effects, ok, nok, 'directiveLeafLabel', 'directiveLeafLabelMarker', 'directiveLeafLabelString', true);
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeAttributes(effects, ok, nok) {
// Always a `{`
return factoryAttributes(effects, ok, nok, 'directiveLeafAttributes', 'directiveLeafAttributesMarker', 'directiveLeafAttribute', 'directiveLeafAttributeId', 'directiveLeafAttributeClass', 'directiveLeafAttributeName', 'directiveLeafAttributeInitializerMarker', 'directiveLeafAttributeValueLiteral', 'directiveLeafAttributeValue', 'directiveLeafAttributeValueMarker', 'directiveLeafAttributeValueData', true);
}
+4
View File
@@ -0,0 +1,4 @@
/** @type {Construct} */
export const directiveText: Construct;
import type { Construct } from 'micromark-util-types';
//# sourceMappingURL=directive-text.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"directive-text.d.ts","sourceRoot":"","sources":["directive-text.js"],"names":[],"mappings":"AAUA,wBAAwB;AACxB,4BADW,SAAS,CAInB;+BAbwE,sBAAsB"}
+82
View File
@@ -0,0 +1,82 @@
/**
* @import {Construct, Previous, State, TokenizeContext, Tokenizer} from 'micromark-util-types'
*/
import { factoryAttributes } from './factory-attributes.js';
import { factoryLabel } from './factory-label.js';
import { factoryName } from './factory-name.js';
/** @type {Construct} */
export const directiveText = {
tokenize: tokenizeDirectiveText,
previous
};
const label = {
tokenize: tokenizeLabel,
partial: true
};
const attributes = {
tokenize: tokenizeAttributes,
partial: true
};
/**
* @this {TokenizeContext}
* @type {Previous}
*/
function previous(code) {
// If there is a previous code, there will always be a tail.
return code !== 58 || this.events[this.events.length - 1][1].type === "characterEscape";
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeDirectiveText(effects, ok, nok) {
const self = this;
return start;
/** @type {State} */
function start(code) {
effects.enter('directiveText');
effects.enter('directiveTextMarker');
effects.consume(code);
effects.exit('directiveTextMarker');
return factoryName.call(self, effects, afterName, nok, 'directiveTextName');
}
/** @type {State} */
function afterName(code) {
return code === 58 ? nok(code) : code === 91 ? effects.attempt(label, afterLabel, afterLabel)(code) : afterLabel(code);
}
/** @type {State} */
function afterLabel(code) {
return code === 123 ? effects.attempt(attributes, afterAttributes, afterAttributes)(code) : afterAttributes(code);
}
/** @type {State} */
function afterAttributes(code) {
effects.exit('directiveText');
return ok(code);
}
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeLabel(effects, ok, nok) {
// Always a `[`
return factoryLabel(effects, ok, nok, 'directiveTextLabel', 'directiveTextLabelMarker', 'directiveTextLabelString');
}
/**
* @this {TokenizeContext}
* @type {Tokenizer}
*/
function tokenizeAttributes(effects, ok, nok) {
// Always a `{`
return factoryAttributes(effects, ok, nok, 'directiveTextAttributes', 'directiveTextAttributesMarker', 'directiveTextAttribute', 'directiveTextAttributeId', 'directiveTextAttributeClass', 'directiveTextAttributeName', 'directiveTextAttributeInitializerMarker', 'directiveTextAttributeValueLiteral', 'directiveTextAttributeValue', 'directiveTextAttributeValueMarker', 'directiveTextAttributeValueData');
}
+23
View File
@@ -0,0 +1,23 @@
/**
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {TokenType} attributesType
* @param {TokenType} attributesMarkerType
* @param {TokenType} attributeType
* @param {TokenType} attributeIdType
* @param {TokenType} attributeClassType
* @param {TokenType} attributeNameType
* @param {TokenType} attributeInitializerType
* @param {TokenType} attributeValueLiteralType
* @param {TokenType} attributeValueType
* @param {TokenType} attributeValueMarker
* @param {TokenType} attributeValueData
* @param {boolean | undefined} [disallowEol=false]
*/
export function factoryAttributes(effects: Effects, ok: State, nok: State, attributesType: TokenType, attributesMarkerType: TokenType, attributeType: TokenType, attributeIdType: TokenType, attributeClassType: TokenType, attributeNameType: TokenType, attributeInitializerType: TokenType, attributeValueLiteralType: TokenType, attributeValueType: TokenType, attributeValueMarker: TokenType, attributeValueData: TokenType, disallowEol?: boolean | undefined): (code: Code) => State | undefined;
import type { Effects } from 'micromark-util-types';
import type { State } from 'micromark-util-types';
import type { TokenType } from 'micromark-util-types';
import type { Code } from 'micromark-util-types';
//# sourceMappingURL=factory-attributes.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"factory-attributes.d.ts","sourceRoot":"","sources":["factory-attributes.js"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;GAgBG;AACH,2CAhBW,OAAO,MACP,KAAK,OACL,KAAK,kBACL,SAAS,wBACT,SAAS,iBACT,SAAS,mBACT,SAAS,sBACT,SAAS,qBACT,SAAS,4BACT,SAAS,6BACT,SAAS,sBACT,SAAS,wBACT,SAAS,sBACT,SAAS,gBACT,OAAO,GAAG,SAAS,qCA4T7B;6BA1ViD,sBAAsB;2BAAtB,sBAAsB;+BAAtB,sBAAsB;0BAAtB,sBAAsB"}
+238
View File
@@ -0,0 +1,238 @@
/**
* @import {Code, Effects, State, TokenType} from 'micromark-util-types'
*/
import { factorySpace } from 'micromark-factory-space';
import { factoryWhitespace } from 'micromark-factory-whitespace';
import { markdownLineEnding, markdownLineEndingOrSpace, markdownSpace, unicodePunctuation, unicodeWhitespace } from 'micromark-util-character';
/**
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {TokenType} attributesType
* @param {TokenType} attributesMarkerType
* @param {TokenType} attributeType
* @param {TokenType} attributeIdType
* @param {TokenType} attributeClassType
* @param {TokenType} attributeNameType
* @param {TokenType} attributeInitializerType
* @param {TokenType} attributeValueLiteralType
* @param {TokenType} attributeValueType
* @param {TokenType} attributeValueMarker
* @param {TokenType} attributeValueData
* @param {boolean | undefined} [disallowEol=false]
*/
export function factoryAttributes(effects, ok, nok, attributesType, attributesMarkerType, attributeType, attributeIdType, attributeClassType, attributeNameType, attributeInitializerType, attributeValueLiteralType, attributeValueType, attributeValueMarker, attributeValueData, disallowEol) {
/** @type {TokenType} */
let type;
/** @type {Code | undefined} */
let marker;
return start;
/** @type {State} */
function start(code) {
effects.enter(attributesType);
effects.enter(attributesMarkerType);
effects.consume(code);
effects.exit(attributesMarkerType);
return between;
}
/** @type {State} */
function between(code) {
if (code === 35) {
type = attributeIdType;
return shortcutStart(code);
}
if (code === 46) {
type = attributeClassType;
return shortcutStart(code);
}
if (disallowEol && markdownSpace(code)) {
return factorySpace(effects, between, "whitespace")(code);
}
if (!disallowEol && markdownLineEndingOrSpace(code)) {
return factoryWhitespace(effects, between)(code);
}
if (code === null || markdownLineEnding(code) || unicodeWhitespace(code) || unicodePunctuation(code) && code !== 45 && code !== 95) {
return end(code);
}
effects.enter(attributeType);
effects.enter(attributeNameType);
effects.consume(code);
return name;
}
/** @type {State} */
function shortcutStart(code) {
// Assume its registered.
const markerType = /** @type {TokenType} */type + 'Marker';
effects.enter(attributeType);
effects.enter(type);
effects.enter(markerType);
effects.consume(code);
effects.exit(markerType);
return shortcutStartAfter;
}
/** @type {State} */
function shortcutStartAfter(code) {
if (code === null || code === 34 || code === 35 || code === 39 || code === 46 || code === 60 || code === 61 || code === 62 || code === 96 || code === 125 || markdownLineEndingOrSpace(code)) {
return nok(code);
}
// Assume its registered.
const valueType = /** @type {TokenType} */type + 'Value';
effects.enter(valueType);
effects.consume(code);
return shortcut;
}
/** @type {State} */
function shortcut(code) {
if (code === null || code === 34 || code === 39 || code === 60 || code === 61 || code === 62 || code === 96) {
return nok(code);
}
if (code === 35 || code === 46 || code === 125 || markdownLineEndingOrSpace(code)) {
// Assume its registered.
const valueType = /** @type {TokenType} */type + 'Value';
effects.exit(valueType);
effects.exit(type);
effects.exit(attributeType);
return between(code);
}
effects.consume(code);
return shortcut;
}
/** @type {State} */
function name(code) {
if (code === null || markdownLineEnding(code) || unicodeWhitespace(code) || unicodePunctuation(code) && code !== 45 && code !== 46 && code !== 58 && code !== 95) {
effects.exit(attributeNameType);
if (disallowEol && markdownSpace(code)) {
return factorySpace(effects, nameAfter, "whitespace")(code);
}
if (!disallowEol && markdownLineEndingOrSpace(code)) {
return factoryWhitespace(effects, nameAfter)(code);
}
return nameAfter(code);
}
effects.consume(code);
return name;
}
/** @type {State} */
function nameAfter(code) {
if (code === 61) {
effects.enter(attributeInitializerType);
effects.consume(code);
effects.exit(attributeInitializerType);
return valueBefore;
}
// Attribute w/o value.
effects.exit(attributeType);
return between(code);
}
/** @type {State} */
function valueBefore(code) {
if (code === null || code === 60 || code === 61 || code === 62 || code === 96 || code === 125 || disallowEol && markdownLineEnding(code)) {
return nok(code);
}
if (code === 34 || code === 39) {
effects.enter(attributeValueLiteralType);
effects.enter(attributeValueMarker);
effects.consume(code);
effects.exit(attributeValueMarker);
marker = code;
return valueQuotedStart;
}
if (disallowEol && markdownSpace(code)) {
return factorySpace(effects, valueBefore, "whitespace")(code);
}
if (!disallowEol && markdownLineEndingOrSpace(code)) {
return factoryWhitespace(effects, valueBefore)(code);
}
effects.enter(attributeValueType);
effects.enter(attributeValueData);
effects.consume(code);
marker = undefined;
return valueUnquoted;
}
/** @type {State} */
function valueUnquoted(code) {
if (code === null || code === 34 || code === 39 || code === 60 || code === 61 || code === 62 || code === 96) {
return nok(code);
}
if (code === 125 || markdownLineEndingOrSpace(code)) {
effects.exit(attributeValueData);
effects.exit(attributeValueType);
effects.exit(attributeType);
return between(code);
}
effects.consume(code);
return valueUnquoted;
}
/** @type {State} */
function valueQuotedStart(code) {
if (code === marker) {
effects.enter(attributeValueMarker);
effects.consume(code);
effects.exit(attributeValueMarker);
effects.exit(attributeValueLiteralType);
effects.exit(attributeType);
return valueQuotedAfter;
}
effects.enter(attributeValueType);
return valueQuotedBetween(code);
}
/** @type {State} */
function valueQuotedBetween(code) {
if (code === marker) {
effects.exit(attributeValueType);
return valueQuotedStart(code);
}
if (code === null) {
return nok(code);
}
// Note: blank lines cant exist in content.
if (markdownLineEnding(code)) {
return disallowEol ? nok(code) : factoryWhitespace(effects, valueQuotedBetween)(code);
}
effects.enter(attributeValueData);
effects.consume(code);
return valueQuoted;
}
/** @type {State} */
function valueQuoted(code) {
if (code === marker || code === null || markdownLineEnding(code)) {
effects.exit(attributeValueData);
return valueQuotedBetween(code);
}
effects.consume(code);
return valueQuoted;
}
/** @type {State} */
function valueQuotedAfter(code) {
return code === 125 || markdownLineEndingOrSpace(code) ? between(code) : end(code);
}
/** @type {State} */
function end(code) {
if (code === 125) {
effects.enter(attributesMarkerType);
effects.consume(code);
effects.exit(attributesMarkerType);
effects.exit(attributesType);
return ok;
}
return nok(code);
}
}
+15
View File
@@ -0,0 +1,15 @@
/**
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {TokenType} type
* @param {TokenType} markerType
* @param {TokenType} stringType
* @param {boolean | undefined} [disallowEol=false]
*/
export function factoryLabel(effects: Effects, ok: State, nok: State, type: TokenType, markerType: TokenType, stringType: TokenType, disallowEol?: boolean | undefined): (code: Code) => State | undefined;
import type { Effects } from 'micromark-util-types';
import type { State } from 'micromark-util-types';
import type { TokenType } from 'micromark-util-types';
import type { Code } from 'micromark-util-types';
//# sourceMappingURL=factory-label.d.ts.map
@@ -0,0 +1 @@
{"version":3,"file":"factory-label.d.ts","sourceRoot":"","sources":["factory-label.js"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,sCARW,OAAO,MACP,KAAK,OACL,KAAK,QACL,SAAS,cACT,SAAS,cACT,SAAS,gBACT,OAAO,GAAG,SAAS,qCAkH7B;6BArIwD,sBAAsB;2BAAtB,sBAAsB;+BAAtB,sBAAsB;0BAAtB,sBAAsB"}
+107
View File
@@ -0,0 +1,107 @@
/**
* @import {Code, Effects, State, Token, TokenType} from 'micromark-util-types'
*/
import { markdownLineEnding } from 'micromark-util-character';
// This is a fork of:
// <https://github.com/micromark/micromark/tree/main/packages/micromark-factory-label>
// to allow empty labels, balanced brackets (such as for nested directives),
// text instead of strings, and optionally disallows EOLs.
/**
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {TokenType} type
* @param {TokenType} markerType
* @param {TokenType} stringType
* @param {boolean | undefined} [disallowEol=false]
*/
export function factoryLabel(effects, ok, nok, type, markerType, stringType, disallowEol) {
let size = 0;
let balance = 0;
/** @type {Token | undefined} */
let previous;
return start;
/** @type {State} */
function start(code) {
effects.enter(type);
effects.enter(markerType);
effects.consume(code);
effects.exit(markerType);
return afterStart;
}
/** @type {State} */
function afterStart(code) {
if (code === 93) {
effects.enter(markerType);
effects.consume(code);
effects.exit(markerType);
effects.exit(type);
return ok;
}
effects.enter(stringType);
return lineStart(code);
}
/** @type {State} */
function lineStart(code) {
if (code === 93 && !balance) {
return atClosingBrace(code);
}
const token = effects.enter("chunkText", {
_contentTypeTextTrailing: true,
contentType: "text",
previous
});
if (previous) previous.next = token;
previous = token;
return data(code);
}
/** @type {State} */
function data(code) {
if (code === null || size > 999) {
return nok(code);
}
if (code === 91 && ++balance > 32) {
return nok(code);
}
if (code === 93 && !balance--) {
effects.exit("chunkText");
return atClosingBrace(code);
}
if (markdownLineEnding(code)) {
if (disallowEol) {
return nok(code);
}
effects.consume(code);
effects.exit("chunkText");
return lineStart;
}
effects.consume(code);
return code === 92 ? dataEscape : data;
}
/** @type {State} */
function dataEscape(code) {
if (code === 91 || code === 92 || code === 93) {
effects.consume(code);
size++;
return data;
}
return data(code);
}
/** @type {State} */
function atClosingBrace(code) {
effects.exit(stringType);
effects.enter(markerType);
effects.consume(code);
effects.exit(markerType);
effects.exit(type);
return ok;
}
}
+14
View File
@@ -0,0 +1,14 @@
/**
* @this {TokenizeContext}
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {TokenType} type
*/
export function factoryName(this: TokenizeContext, effects: Effects, ok: State, nok: State, type: TokenType): (code: Code) => State | undefined;
import type { Effects } from 'micromark-util-types';
import type { State } from 'micromark-util-types';
import type { TokenType } from 'micromark-util-types';
import type { TokenizeContext } from 'micromark-util-types';
import type { Code } from 'micromark-util-types';
//# sourceMappingURL=factory-name.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"factory-name.d.ts","sourceRoot":"","sources":["factory-name.js"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH,4DALW,OAAO,MACP,KAAK,OACL,KAAK,QACL,SAAS,qCA0CnB;6BAzDkE,sBAAsB;2BAAtB,sBAAsB;+BAAtB,sBAAsB;qCAAtB,sBAAsB;0BAAtB,sBAAsB"}
+36
View File
@@ -0,0 +1,36 @@
/**
* @import {Code, Effects, State, TokenizeContext, TokenType} from 'micromark-util-types'
*/
import { markdownLineEnding, unicodePunctuation, unicodeWhitespace } from 'micromark-util-character';
/**
* @this {TokenizeContext}
* @param {Effects} effects
* @param {State} ok
* @param {State} nok
* @param {TokenType} type
*/
export function factoryName(effects, ok, nok, type) {
const self = this;
return start;
/** @type {State} */
function start(code) {
if (code === null || markdownLineEnding(code) || unicodePunctuation(code) || unicodeWhitespace(code)) {
return nok(code);
}
effects.enter(type);
effects.consume(code);
return name;
}
/** @type {State} */
function name(code) {
if (code === null || markdownLineEnding(code) || unicodeWhitespace(code) || unicodePunctuation(code) && code !== 45 && code !== 95) {
effects.exit(type);
return self.previous === 45 || self.previous === 95 ? nok(code) : ok(code);
}
effects.consume(code);
return name;
}
}
+14
View File
@@ -0,0 +1,14 @@
/**
* Create an extension for `micromark` to support directives when serializing
* to HTML.
*
* @param {HtmlOptions | null | undefined} [options={}]
* Configuration (default: `{}`).
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions`, to
* support directives when serializing to HTML.
*/
export function directiveHtml(options?: HtmlOptions | null | undefined): HtmlExtension;
import type { HtmlOptions } from 'micromark-extension-directive';
import type { HtmlExtension } from 'micromark-util-types';
//# sourceMappingURL=html.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["html.js"],"names":[],"mappings":"AAUA;;;;;;;;;GASG;AACH,wCANW,WAAW,GAAG,IAAI,GAAG,SAAS,GAE5B,aAAa,CAwPzB;iCAvQwC,+BAA+B;mCACG,sBAAsB"}
+233
View File
@@ -0,0 +1,233 @@
/**
* @import {Directive, HtmlOptions} from 'micromark-extension-directive'
* @import {CompileContext, Handle as MicromarkHandle, HtmlExtension} from 'micromark-util-types'
*/
import { parseEntities } from 'parse-entities';
const own = {}.hasOwnProperty;
/**
* Create an extension for `micromark` to support directives when serializing
* to HTML.
*
* @param {HtmlOptions | null | undefined} [options={}]
* Configuration (default: `{}`).
* @returns {HtmlExtension}
* Extension for `micromark` that can be passed in `htmlExtensions`, to
* support directives when serializing to HTML.
*/
export function directiveHtml(options) {
const options_ = options || {};
return {
enter: {
directiveContainer() {
enter.call(this, 'containerDirective');
},
directiveContainerAttributes: enterAttributes,
directiveContainerLabel: enterLabel,
directiveContainerContent() {
this.buffer();
},
directiveLeaf() {
enter.call(this, 'leafDirective');
},
directiveLeafAttributes: enterAttributes,
directiveLeafLabel: enterLabel,
directiveText() {
enter.call(this, 'textDirective');
},
directiveTextAttributes: enterAttributes,
directiveTextLabel: enterLabel
},
exit: {
directiveContainer: exit,
directiveContainerAttributeClassValue: exitAttributeClassValue,
directiveContainerAttributeIdValue: exitAttributeIdValue,
directiveContainerAttributeName: exitAttributeName,
directiveContainerAttributeValue: exitAttributeValue,
directiveContainerAttributes: exitAttributes,
directiveContainerContent: exitContainerContent,
directiveContainerFence: exitContainerFence,
directiveContainerLabel: exitLabel,
directiveContainerName: exitName,
directiveLeaf: exit,
directiveLeafAttributeClassValue: exitAttributeClassValue,
directiveLeafAttributeIdValue: exitAttributeIdValue,
directiveLeafAttributeName: exitAttributeName,
directiveLeafAttributeValue: exitAttributeValue,
directiveLeafAttributes: exitAttributes,
directiveLeafLabel: exitLabel,
directiveLeafName: exitName,
directiveText: exit,
directiveTextAttributeClassValue: exitAttributeClassValue,
directiveTextAttributeIdValue: exitAttributeIdValue,
directiveTextAttributeName: exitAttributeName,
directiveTextAttributeValue: exitAttributeValue,
directiveTextAttributes: exitAttributes,
directiveTextLabel: exitLabel,
directiveTextName: exitName
}
};
/**
* @this {CompileContext}
* @param {Directive['type']} type
*/
function enter(type) {
let stack = this.getData('directiveStack');
if (!stack) this.setData('directiveStack', stack = []);
stack.push({
type,
name: ''
});
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitName(token) {
const stack = this.getData('directiveStack');
stack[stack.length - 1].name = this.sliceSerialize(token);
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function enterLabel() {
this.buffer();
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitLabel() {
const data = this.resume();
const stack = this.getData('directiveStack');
stack[stack.length - 1].label = data;
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function enterAttributes() {
this.buffer();
this.setData('directiveAttributes', []);
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitAttributeIdValue(token) {
const attributes = this.getData('directiveAttributes');
attributes.push(['id', parseEntities(this.sliceSerialize(token), {
attribute: true
})]);
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitAttributeClassValue(token) {
const attributes = this.getData('directiveAttributes');
attributes.push(['class', parseEntities(this.sliceSerialize(token), {
attribute: true
})]);
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitAttributeName(token) {
// Attribute names in CommonMark are significantly limited, so character
// references cant exist.
const attributes = this.getData('directiveAttributes');
attributes.push([this.sliceSerialize(token), '']);
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitAttributeValue(token) {
const attributes = this.getData('directiveAttributes');
attributes[attributes.length - 1][1] = parseEntities(this.sliceSerialize(token), {
attribute: true
});
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitAttributes() {
const stack = this.getData('directiveStack');
const attributes = this.getData('directiveAttributes');
/** @type {Record<string, string>} */
const cleaned = {};
let index = -1;
while (++index < attributes.length) {
const attribute = attributes[index];
if (attribute[0] === 'class' && cleaned.class) {
cleaned.class += ' ' + attribute[1];
} else {
cleaned[attribute[0]] = attribute[1];
}
}
this.resume();
this.setData('directiveAttributes');
stack[stack.length - 1].attributes = cleaned;
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitContainerContent() {
const data = this.resume();
const stack = this.getData('directiveStack');
stack[stack.length - 1].content = data;
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exitContainerFence() {
const stack = this.getData('directiveStack');
const directive = stack[stack.length - 1];
if (!directive._fenceCount) directive._fenceCount = 0;
directive._fenceCount++;
if (directive._fenceCount === 1) this.setData('slurpOneLineEnding', true);
}
/**
* @this {CompileContext}
* @type {MicromarkHandle}
*/
function exit() {
const stack = this.getData('directiveStack');
const directive = stack.pop();
/** @type {boolean | undefined} */
let found;
/** @type {boolean | undefined} */
let result;
if (own.call(options_, directive.name)) {
result = options_[directive.name].call(this, directive);
found = result !== false;
}
if (!found && own.call(options_, '*')) {
result = options_['*'].call(this, directive);
found = result !== false;
}
if (!found && directive.type !== 'textDirective') {
this.setData('slurpOneLineEnding', true);
}
}
}
+10
View File
@@ -0,0 +1,10 @@
/**
* Create an extension for `micromark` to enable directive syntax.
*
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions`, to
* enable directive syntax.
*/
export function directive(): Extension;
import type { Extension } from 'micromark-util-types';
//# sourceMappingURL=syntax.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["syntax.js"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,6BAJa,SAAS,CASrB;+BApB2B,sBAAsB"}
+25
View File
@@ -0,0 +1,25 @@
/**
* @import {Extension} from 'micromark-util-types'
*/
import { directiveContainer } from './directive-container.js';
import { directiveLeaf } from './directive-leaf.js';
import { directiveText } from './directive-text.js';
/**
* Create an extension for `micromark` to enable directive syntax.
*
* @returns {Extension}
* Extension for `micromark` that can be passed in `extensions`, to
* enable directive syntax.
*/
export function directive() {
return {
text: {
[58]: directiveText
},
flow: {
[58]: [directiveContainer, directiveLeaf]
}
};
}