feat: use go tool
This commit is contained in:
+4
@@ -0,0 +1,4 @@
|
||||
/** @type {Construct} */
|
||||
export const directiveContainer: Construct;
|
||||
import type { Construct } from 'micromark-util-types';
|
||||
//# sourceMappingURL=directive-container.d.ts.map
|
||||
+1
@@ -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"}
|
||||
+323
@@ -0,0 +1,323 @@
|
||||
/**
|
||||
* @import {Construct, State, Token, 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 {codes, constants, types} from 'micromark-util-symbol'
|
||||
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 === types.linePrefix
|
||||
? tail[2].sliceSerialize(tail[1], true).length
|
||||
: 0
|
||||
let sizeOpen = 0
|
||||
/** @type {Token} */
|
||||
let previous
|
||||
|
||||
return start
|
||||
|
||||
/** @type {State} */
|
||||
function start(code) {
|
||||
assert(code === codes.colon, 'expected `:`')
|
||||
effects.enter('directiveContainer')
|
||||
effects.enter('directiveContainerFence')
|
||||
effects.enter('directiveContainerSequence')
|
||||
return sequenceOpen(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function sequenceOpen(code) {
|
||||
if (code === codes.colon) {
|
||||
effects.consume(code)
|
||||
sizeOpen++
|
||||
return sequenceOpen
|
||||
}
|
||||
|
||||
if (sizeOpen < constants.codeFencedSequenceSizeMin) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
effects.exit('directiveContainerSequence')
|
||||
return factoryName.call(
|
||||
self,
|
||||
effects,
|
||||
afterName,
|
||||
nok,
|
||||
'directiveContainerName'
|
||||
)(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function afterName(code) {
|
||||
return code === codes.leftSquareBracket
|
||||
? effects.attempt(label, afterLabel, afterLabel)(code)
|
||||
: afterLabel(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function afterLabel(code) {
|
||||
return code === codes.leftCurlyBrace
|
||||
? effects.attempt(attributes, afterAttributes, afterAttributes)(code)
|
||||
: afterAttributes(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function afterAttributes(code) {
|
||||
return factorySpace(effects, openAfter, types.whitespace)(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function openAfter(code) {
|
||||
effects.exit('directiveContainerFence')
|
||||
|
||||
if (code === codes.eof) {
|
||||
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 === codes.eof) {
|
||||
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, types.linePrefix, initialSize + 1)
|
||||
: chunkStart
|
||||
)(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function chunkStart(code) {
|
||||
if (code === codes.eof) {
|
||||
return afterContent(code)
|
||||
}
|
||||
|
||||
if (markdownLineEnding(code)) {
|
||||
return effects.check(nonLazyLine, chunkNonLazyStart, afterContent)(code)
|
||||
}
|
||||
|
||||
return chunkNonLazyStart(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function contentContinue(code) {
|
||||
if (code === codes.eof) {
|
||||
const t = effects.exit(types.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(types.chunkDocument, {
|
||||
contentType: constants.contentTypeDocument,
|
||||
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(types.chunkDocument)
|
||||
self.parser.lazy[t.start.line] = false
|
||||
return lineStart
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function lineAfter(code) {
|
||||
const t = effects.exit(types.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
|
||||
assert(self.parser.constructs.disable.null, 'expected `disable.null`')
|
||||
return factorySpace(
|
||||
effects,
|
||||
closingPrefixAfter,
|
||||
types.linePrefix,
|
||||
self.parser.constructs.disable.null.includes('codeIndented')
|
||||
? undefined
|
||||
: constants.tabSize
|
||||
)
|
||||
|
||||
/** @type {State} */
|
||||
function closingPrefixAfter(code) {
|
||||
effects.enter('directiveContainerFence')
|
||||
effects.enter('directiveContainerSequence')
|
||||
return closingSequence(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function closingSequence(code) {
|
||||
if (code === codes.colon) {
|
||||
effects.consume(code)
|
||||
size++
|
||||
return closingSequence
|
||||
}
|
||||
|
||||
if (size < sizeOpen) return nok(code)
|
||||
effects.exit('directiveContainerSequence')
|
||||
return factorySpace(effects, closingSequenceEnd, types.whitespace)(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function closingSequenceEnd(code) {
|
||||
if (code === codes.eof || 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) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
/** @type {Construct} */
|
||||
export const directiveLeaf: Construct;
|
||||
import type { Construct } from 'micromark-util-types';
|
||||
//# sourceMappingURL=directive-leaf.d.ts.map
|
||||
+1
@@ -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"}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* @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 {codes, types} from 'micromark-util-symbol'
|
||||
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) {
|
||||
assert(code === codes.colon, 'expected `:`')
|
||||
effects.enter('directiveLeaf')
|
||||
effects.enter('directiveLeafSequence')
|
||||
effects.consume(code)
|
||||
return inStart
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function inStart(code) {
|
||||
if (code === codes.colon) {
|
||||
effects.consume(code)
|
||||
effects.exit('directiveLeafSequence')
|
||||
return factoryName.call(
|
||||
self,
|
||||
effects,
|
||||
afterName,
|
||||
nok,
|
||||
'directiveLeafName'
|
||||
)
|
||||
}
|
||||
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function afterName(code) {
|
||||
return code === codes.leftSquareBracket
|
||||
? effects.attempt(label, afterLabel, afterLabel)(code)
|
||||
: afterLabel(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function afterLabel(code) {
|
||||
return code === codes.leftCurlyBrace
|
||||
? effects.attempt(attributes, afterAttributes, afterAttributes)(code)
|
||||
: afterAttributes(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function afterAttributes(code) {
|
||||
return factorySpace(effects, end, types.whitespace)(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function end(code) {
|
||||
if (code === codes.eof || 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
@@ -0,0 +1,4 @@
|
||||
/** @type {Construct} */
|
||||
export const directiveText: Construct;
|
||||
import type { Construct } from 'micromark-util-types';
|
||||
//# sourceMappingURL=directive-text.d.ts.map
|
||||
+1
@@ -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"}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* @import {Construct, Previous, State, TokenizeContext, Tokenizer} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
import {ok as assert} from 'devlop'
|
||||
import {codes, types} from 'micromark-util-symbol'
|
||||
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 !== codes.colon ||
|
||||
this.events[this.events.length - 1][1].type === types.characterEscape
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {TokenizeContext}
|
||||
* @type {Tokenizer}
|
||||
*/
|
||||
function tokenizeDirectiveText(effects, ok, nok) {
|
||||
const self = this
|
||||
|
||||
return start
|
||||
|
||||
/** @type {State} */
|
||||
function start(code) {
|
||||
assert(code === codes.colon, 'expected `:`')
|
||||
assert(previous.call(self, self.previous), 'expected correct previous')
|
||||
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 === codes.colon
|
||||
? nok(code)
|
||||
: code === codes.leftSquareBracket
|
||||
? effects.attempt(label, afterLabel, afterLabel)(code)
|
||||
: afterLabel(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function afterLabel(code) {
|
||||
return code === codes.leftCurlyBrace
|
||||
? 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
@@ -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
|
||||
+1
@@ -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"}
|
||||
+348
@@ -0,0 +1,348 @@
|
||||
/**
|
||||
* @import {Code, Effects, State, TokenType} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
import {ok as assert} from 'devlop'
|
||||
import {factorySpace} from 'micromark-factory-space'
|
||||
import {factoryWhitespace} from 'micromark-factory-whitespace'
|
||||
import {
|
||||
markdownLineEnding,
|
||||
markdownLineEndingOrSpace,
|
||||
markdownSpace,
|
||||
unicodePunctuation,
|
||||
unicodeWhitespace
|
||||
} from 'micromark-util-character'
|
||||
import {codes, types} from 'micromark-util-symbol'
|
||||
|
||||
/**
|
||||
* @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) {
|
||||
assert(code === codes.leftCurlyBrace, 'expected `{`')
|
||||
effects.enter(attributesType)
|
||||
effects.enter(attributesMarkerType)
|
||||
effects.consume(code)
|
||||
effects.exit(attributesMarkerType)
|
||||
return between
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function between(code) {
|
||||
if (code === codes.numberSign) {
|
||||
type = attributeIdType
|
||||
return shortcutStart(code)
|
||||
}
|
||||
|
||||
if (code === codes.dot) {
|
||||
type = attributeClassType
|
||||
return shortcutStart(code)
|
||||
}
|
||||
|
||||
if (disallowEol && markdownSpace(code)) {
|
||||
return factorySpace(effects, between, types.whitespace)(code)
|
||||
}
|
||||
|
||||
if (!disallowEol && markdownLineEndingOrSpace(code)) {
|
||||
return factoryWhitespace(effects, between)(code)
|
||||
}
|
||||
|
||||
if (
|
||||
code === codes.eof ||
|
||||
markdownLineEnding(code) ||
|
||||
unicodeWhitespace(code) ||
|
||||
(unicodePunctuation(code) &&
|
||||
code !== codes.dash &&
|
||||
code !== codes.underscore)
|
||||
) {
|
||||
return end(code)
|
||||
}
|
||||
|
||||
effects.enter(attributeType)
|
||||
effects.enter(attributeNameType)
|
||||
effects.consume(code)
|
||||
return name
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function shortcutStart(code) {
|
||||
// Assume it’s 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 === codes.eof ||
|
||||
code === codes.quotationMark ||
|
||||
code === codes.numberSign ||
|
||||
code === codes.apostrophe ||
|
||||
code === codes.dot ||
|
||||
code === codes.lessThan ||
|
||||
code === codes.equalsTo ||
|
||||
code === codes.greaterThan ||
|
||||
code === codes.graveAccent ||
|
||||
code === codes.rightCurlyBrace ||
|
||||
markdownLineEndingOrSpace(code)
|
||||
) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
// Assume it’s registered.
|
||||
const valueType = /** @type {TokenType} */ (type + 'Value')
|
||||
effects.enter(valueType)
|
||||
effects.consume(code)
|
||||
return shortcut
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function shortcut(code) {
|
||||
if (
|
||||
code === codes.eof ||
|
||||
code === codes.quotationMark ||
|
||||
code === codes.apostrophe ||
|
||||
code === codes.lessThan ||
|
||||
code === codes.equalsTo ||
|
||||
code === codes.greaterThan ||
|
||||
code === codes.graveAccent
|
||||
) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
if (
|
||||
code === codes.numberSign ||
|
||||
code === codes.dot ||
|
||||
code === codes.rightCurlyBrace ||
|
||||
markdownLineEndingOrSpace(code)
|
||||
) {
|
||||
// Assume it’s 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 === codes.eof ||
|
||||
markdownLineEnding(code) ||
|
||||
unicodeWhitespace(code) ||
|
||||
(unicodePunctuation(code) &&
|
||||
code !== codes.dash &&
|
||||
code !== codes.dot &&
|
||||
code !== codes.colon &&
|
||||
code !== codes.underscore)
|
||||
) {
|
||||
effects.exit(attributeNameType)
|
||||
|
||||
if (disallowEol && markdownSpace(code)) {
|
||||
return factorySpace(effects, nameAfter, types.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 === codes.equalsTo) {
|
||||
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 === codes.eof ||
|
||||
code === codes.lessThan ||
|
||||
code === codes.equalsTo ||
|
||||
code === codes.greaterThan ||
|
||||
code === codes.graveAccent ||
|
||||
code === codes.rightCurlyBrace ||
|
||||
(disallowEol && markdownLineEnding(code))
|
||||
) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
if (code === codes.quotationMark || code === codes.apostrophe) {
|
||||
effects.enter(attributeValueLiteralType)
|
||||
effects.enter(attributeValueMarker)
|
||||
effects.consume(code)
|
||||
effects.exit(attributeValueMarker)
|
||||
marker = code
|
||||
return valueQuotedStart
|
||||
}
|
||||
|
||||
if (disallowEol && markdownSpace(code)) {
|
||||
return factorySpace(effects, valueBefore, types.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 === codes.eof ||
|
||||
code === codes.quotationMark ||
|
||||
code === codes.apostrophe ||
|
||||
code === codes.lessThan ||
|
||||
code === codes.equalsTo ||
|
||||
code === codes.greaterThan ||
|
||||
code === codes.graveAccent
|
||||
) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
if (code === codes.rightCurlyBrace || 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 === codes.eof) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
// Note: blank lines can’t 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 === codes.eof || markdownLineEnding(code)) {
|
||||
effects.exit(attributeValueData)
|
||||
return valueQuotedBetween(code)
|
||||
}
|
||||
|
||||
effects.consume(code)
|
||||
return valueQuoted
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function valueQuotedAfter(code) {
|
||||
return code === codes.rightCurlyBrace || markdownLineEndingOrSpace(code)
|
||||
? between(code)
|
||||
: end(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function end(code) {
|
||||
if (code === codes.rightCurlyBrace) {
|
||||
effects.enter(attributesMarkerType)
|
||||
effects.consume(code)
|
||||
effects.exit(attributesMarkerType)
|
||||
effects.exit(attributesType)
|
||||
return ok
|
||||
}
|
||||
|
||||
return nok(code)
|
||||
}
|
||||
}
|
||||
+15
@@ -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
|
||||
+1
@@ -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"}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* @import {Code, Effects, State, Token, TokenType} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
import {ok as assert} from 'devlop'
|
||||
import {markdownLineEnding} from 'micromark-util-character'
|
||||
import {codes, constants, types} from 'micromark-util-symbol'
|
||||
|
||||
// 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) {
|
||||
assert(code === codes.leftSquareBracket, 'expected `[`')
|
||||
effects.enter(type)
|
||||
effects.enter(markerType)
|
||||
effects.consume(code)
|
||||
effects.exit(markerType)
|
||||
return afterStart
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function afterStart(code) {
|
||||
if (code === codes.rightSquareBracket) {
|
||||
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 === codes.rightSquareBracket && !balance) {
|
||||
return atClosingBrace(code)
|
||||
}
|
||||
|
||||
const token = effects.enter(types.chunkText, {
|
||||
_contentTypeTextTrailing: true,
|
||||
contentType: constants.contentTypeText,
|
||||
previous
|
||||
})
|
||||
if (previous) previous.next = token
|
||||
previous = token
|
||||
return data(code)
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function data(code) {
|
||||
if (code === codes.eof || size > constants.linkReferenceSizeMax) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
if (
|
||||
code === codes.leftSquareBracket &&
|
||||
++balance > constants.linkResourceDestinationBalanceMax
|
||||
) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
if (code === codes.rightSquareBracket && !balance--) {
|
||||
effects.exit(types.chunkText)
|
||||
return atClosingBrace(code)
|
||||
}
|
||||
|
||||
if (markdownLineEnding(code)) {
|
||||
if (disallowEol) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
effects.consume(code)
|
||||
effects.exit(types.chunkText)
|
||||
return lineStart
|
||||
}
|
||||
|
||||
effects.consume(code)
|
||||
return code === codes.backslash ? dataEscape : data
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function dataEscape(code) {
|
||||
if (
|
||||
code === codes.leftSquareBracket ||
|
||||
code === codes.backslash ||
|
||||
code === codes.rightSquareBracket
|
||||
) {
|
||||
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
@@ -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
@@ -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"}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* @import {Code, Effects, State, TokenizeContext, TokenType} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
import {
|
||||
markdownLineEnding,
|
||||
unicodePunctuation,
|
||||
unicodeWhitespace
|
||||
} from 'micromark-util-character'
|
||||
import {codes} from 'micromark-util-symbol'
|
||||
|
||||
/**
|
||||
* @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 === codes.eof ||
|
||||
markdownLineEnding(code) ||
|
||||
unicodePunctuation(code) ||
|
||||
unicodeWhitespace(code)
|
||||
) {
|
||||
return nok(code)
|
||||
}
|
||||
|
||||
effects.enter(type)
|
||||
effects.consume(code)
|
||||
return name
|
||||
}
|
||||
|
||||
/** @type {State} */
|
||||
function name(code) {
|
||||
if (
|
||||
code === codes.eof ||
|
||||
markdownLineEnding(code) ||
|
||||
unicodeWhitespace(code) ||
|
||||
(unicodePunctuation(code) &&
|
||||
code !== codes.dash &&
|
||||
code !== codes.underscore)
|
||||
) {
|
||||
effects.exit(type)
|
||||
return self.previous === codes.dash || self.previous === codes.underscore
|
||||
? nok(code)
|
||||
: ok(code)
|
||||
}
|
||||
|
||||
effects.consume(code)
|
||||
return name
|
||||
}
|
||||
}
|
||||
+14
@@ -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
@@ -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"}
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
/**
|
||||
* @import {Directive, HtmlOptions} from 'micromark-extension-directive'
|
||||
* @import {CompileContext, Handle as MicromarkHandle, HtmlExtension} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
import {ok as assert} from 'devlop'
|
||||
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')
|
||||
assert(stack, 'expected directive stack')
|
||||
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')
|
||||
assert(stack, 'expected directive stack')
|
||||
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')
|
||||
assert(attributes, 'expected attributes')
|
||||
attributes.push([
|
||||
'id',
|
||||
parseEntities(this.sliceSerialize(token), {
|
||||
attribute: true
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {CompileContext}
|
||||
* @type {MicromarkHandle}
|
||||
*/
|
||||
function exitAttributeClassValue(token) {
|
||||
const attributes = this.getData('directiveAttributes')
|
||||
assert(attributes, 'expected attributes')
|
||||
|
||||
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 can’t exist.
|
||||
const attributes = this.getData('directiveAttributes')
|
||||
assert(attributes, 'expected attributes')
|
||||
|
||||
attributes.push([this.sliceSerialize(token), ''])
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {CompileContext}
|
||||
* @type {MicromarkHandle}
|
||||
*/
|
||||
function exitAttributeValue(token) {
|
||||
const attributes = this.getData('directiveAttributes')
|
||||
assert(attributes, 'expected attributes')
|
||||
attributes[attributes.length - 1][1] = parseEntities(
|
||||
this.sliceSerialize(token),
|
||||
{attribute: true}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {CompileContext}
|
||||
* @type {MicromarkHandle}
|
||||
*/
|
||||
function exitAttributes() {
|
||||
const stack = this.getData('directiveStack')
|
||||
assert(stack, 'expected directive stack')
|
||||
const attributes = this.getData('directiveAttributes')
|
||||
assert(attributes, 'expected attributes')
|
||||
/** @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')
|
||||
assert(stack, 'expected directive stack')
|
||||
stack[stack.length - 1].content = data
|
||||
}
|
||||
|
||||
/**
|
||||
* @this {CompileContext}
|
||||
* @type {MicromarkHandle}
|
||||
*/
|
||||
function exitContainerFence() {
|
||||
const stack = this.getData('directiveStack')
|
||||
assert(stack, 'expected directive stack')
|
||||
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')
|
||||
assert(stack, 'expected directive stack')
|
||||
const directive = stack.pop()
|
||||
assert(directive, 'expected directive')
|
||||
/** @type {boolean | undefined} */
|
||||
let found
|
||||
/** @type {boolean | undefined} */
|
||||
let result
|
||||
|
||||
assert(directive.name, 'expected `name`')
|
||||
|
||||
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
@@ -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
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"syntax.d.ts","sourceRoot":"","sources":["syntax.js"],"names":[],"mappings":"AASA;;;;;;GAMG;AACH,6BAJa,SAAS,CASrB;+BApB2B,sBAAsB"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* @import {Extension} from 'micromark-util-types'
|
||||
*/
|
||||
|
||||
import {codes} from 'micromark-util-symbol'
|
||||
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: {[codes.colon]: directiveText},
|
||||
flow: {[codes.colon]: [directiveContainer, directiveLeaf]}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user