micromark-extension-directive
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -0,5 +1,82 @@ | ||
import type {Attribute, Directive} from './lib/html.js' | ||
export {directive} from './lib/syntax.js' | ||
export {directiveHtml} from './lib/html.js' | ||
export type Directive = import('./lib/html.js').Directive | ||
export type Handle = import('./lib/html.js').Handle | ||
export type HtmlOptions = import('./lib/html.js').HtmlOptions | ||
export { | ||
directiveHtml, | ||
type Directive, | ||
type Handle, | ||
type HtmlOptions | ||
} from './lib/html.js' | ||
declare module 'micromark-util-types' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface TokenTypeMap { | ||
directiveContainer: 'directiveContainer' | ||
directiveContainerAttributes: 'directiveContainerAttributes' | ||
directiveContainerAttributesMarker: 'directiveContainerAttributesMarker' | ||
directiveContainerAttribute: 'directiveContainerAttribute' | ||
directiveContainerAttributeId: 'directiveContainerAttributeId' | ||
directiveContainerAttributeIdValue: 'directiveContainerAttributeIdValue' | ||
directiveContainerAttributeClass: 'directiveContainerAttributeClass' | ||
directiveContainerAttributeClassValue: 'directiveContainerAttributeClassValue' | ||
directiveContainerAttributeName: 'directiveContainerAttributeName' | ||
directiveContainerAttributeInitializerMarker: 'directiveContainerAttributeInitializerMarker' | ||
directiveContainerAttributeValueLiteral: 'directiveContainerAttributeValueLiteral' | ||
directiveContainerAttributeValue: 'directiveContainerAttributeValue' | ||
directiveContainerAttributeValueMarker: 'directiveContainerAttributeValueMarker' | ||
directiveContainerAttributeValueData: 'directiveContainerAttributeValueData' | ||
directiveContainerContent: 'directiveContainerContent' | ||
directiveContainerFence: 'directiveContainerFence' | ||
directiveContainerLabel: 'directiveContainerLabel' | ||
directiveContainerLabelMarker: 'directiveContainerLabelMarker' | ||
directiveContainerLabelString: 'directiveContainerLabelString' | ||
directiveContainerName: 'directiveContainerName' | ||
directiveContainerSequence: 'directiveContainerSequence' | ||
directiveLeaf: 'directiveLeaf' | ||
directiveLeafAttributes: 'directiveLeafAttributes' | ||
directiveLeafAttributesMarker: 'directiveLeafAttributesMarker' | ||
directiveLeafAttribute: 'directiveLeafAttribute' | ||
directiveLeafAttributeId: 'directiveLeafAttributeId' | ||
directiveLeafAttributeIdValue: 'directiveLeafAttributeIdValue' | ||
directiveLeafAttributeClass: 'directiveLeafAttributeClass' | ||
directiveLeafAttributeClassValue: 'directiveLeafAttributeClassValue' | ||
directiveLeafAttributeName: 'directiveLeafAttributeName' | ||
directiveLeafAttributeInitializerMarker: 'directiveLeafAttributeInitializerMarker' | ||
directiveLeafAttributeValueLiteral: 'directiveLeafAttributeValueLiteral' | ||
directiveLeafAttributeValue: 'directiveLeafAttributeValue' | ||
directiveLeafAttributeValueMarker: 'directiveLeafAttributeValueMarker' | ||
directiveLeafAttributeValueData: 'directiveLeafAttributeValueData' | ||
directiveLeafLabel: 'directiveLeafLabel' | ||
directiveLeafLabelMarker: 'directiveLeafLabelMarker' | ||
directiveLeafLabelString: 'directiveLeafLabelString' | ||
directiveLeafName: 'directiveLeafName' | ||
directiveLeafSequence: 'directiveLeafSequence' | ||
directiveText: 'directiveText' | ||
directiveTextAttributes: 'directiveTextAttributes' | ||
directiveTextAttributesMarker: 'directiveTextAttributesMarker' | ||
directiveTextAttribute: 'directiveTextAttribute' | ||
directiveTextAttributeId: 'directiveTextAttributeId' | ||
directiveTextAttributeIdValue: 'directiveTextAttributeIdValue' | ||
directiveTextAttributeClass: 'directiveTextAttributeClass' | ||
directiveTextAttributeClassValue: 'directiveTextAttributeClassValue' | ||
directiveTextAttributeName: 'directiveTextAttributeName' | ||
directiveTextAttributeInitializerMarker: 'directiveTextAttributeInitializerMarker' | ||
directiveTextAttributeValueLiteral: 'directiveTextAttributeValueLiteral' | ||
directiveTextAttributeValue: 'directiveTextAttributeValue' | ||
directiveTextAttributeValueMarker: 'directiveTextAttributeValueMarker' | ||
directiveTextAttributeValueData: 'directiveTextAttributeValueData' | ||
directiveTextLabel: 'directiveTextLabel' | ||
directiveTextLabelMarker: 'directiveTextLabelMarker' | ||
directiveTextLabelString: 'directiveTextLabelString' | ||
directiveTextMarker: 'directiveTextMarker' | ||
directiveTextName: 'directiveTextName' | ||
} | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface CompileData { | ||
directiveAttributes?: Attribute[] | ||
directiveStack?: Directive[] | ||
} | ||
} |
@@ -1,8 +0,3 @@ | ||
/** | ||
* @typedef {import('./lib/html.js').Directive} Directive | ||
* @typedef {import('./lib/html.js').Handle} Handle | ||
* @typedef {import('./lib/html.js').HtmlOptions} HtmlOptions | ||
*/ | ||
// Note: more types exported from `index.d.ts`. | ||
export {directive} from './lib/syntax.js' | ||
export {directiveHtml} from './lib/html.js' |
@@ -5,13 +5,13 @@ /** | ||
* @param {State} nok | ||
* @param {string} attributesType | ||
* @param {string} attributesMarkerType | ||
* @param {string} attributeType | ||
* @param {string} attributeIdType | ||
* @param {string} attributeClassType | ||
* @param {string} attributeNameType | ||
* @param {string} attributeInitializerType | ||
* @param {string} attributeValueLiteralType | ||
* @param {string} attributeValueType | ||
* @param {string} attributeValueMarker | ||
* @param {string} attributeValueData | ||
* @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} [disallowEol=false] | ||
@@ -23,13 +23,13 @@ */ | ||
nok: State, | ||
attributesType: string, | ||
attributesMarkerType: string, | ||
attributeType: string, | ||
attributeIdType: string, | ||
attributeClassType: string, | ||
attributeNameType: string, | ||
attributeInitializerType: string, | ||
attributeValueLiteralType: string, | ||
attributeValueType: string, | ||
attributeValueMarker: string, | ||
attributeValueData: string, | ||
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 | ||
@@ -42,1 +42,2 @@ ): ( | ||
export type State = import('micromark-util-types').State | ||
export type TokenType = import('micromark-util-types').TokenType |
@@ -5,2 +5,3 @@ /** | ||
* @typedef {import('micromark-util-types').State} State | ||
* @typedef {import('micromark-util-types').TokenType} TokenType | ||
*/ | ||
@@ -25,13 +26,13 @@ | ||
* @param {State} nok | ||
* @param {string} attributesType | ||
* @param {string} attributesMarkerType | ||
* @param {string} attributeType | ||
* @param {string} attributeIdType | ||
* @param {string} attributeClassType | ||
* @param {string} attributeNameType | ||
* @param {string} attributeInitializerType | ||
* @param {string} attributeValueLiteralType | ||
* @param {string} attributeValueType | ||
* @param {string} attributeValueMarker | ||
* @param {string} attributeValueData | ||
* @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} [disallowEol=false] | ||
@@ -57,5 +58,5 @@ */ | ||
) { | ||
/** @type {string} */ | ||
/** @type {TokenType} */ | ||
let type | ||
/** @type {Code|undefined} */ | ||
/** @type {Code | undefined} */ | ||
let marker | ||
@@ -107,7 +108,9 @@ | ||
function shortcutStart(code) { | ||
// Assume it’s registered. | ||
const markerType = /** @type {TokenType} */ (type + 'Marker') | ||
effects.enter(attributeType) | ||
effects.enter(type) | ||
effects.enter(type + 'Marker') | ||
effects.enter(markerType) | ||
effects.consume(code) | ||
effects.exit(type + 'Marker') | ||
effects.exit(markerType) | ||
return shortcutStartAfter | ||
@@ -134,3 +137,5 @@ } | ||
effects.enter(type + 'Value') | ||
// Assume it’s registered. | ||
const valueType = /** @type {TokenType} */ (type + 'Value') | ||
effects.enter(valueType) | ||
effects.consume(code) | ||
@@ -160,3 +165,5 @@ return shortcut | ||
) { | ||
effects.exit(type + 'Value') | ||
// Assume it’s registered. | ||
const valueType = /** @type {TokenType} */ (type + 'Value') | ||
effects.exit(valueType) | ||
effects.exit(type) | ||
@@ -163,0 +170,0 @@ effects.exit(attributeType) |
@@ -5,5 +5,5 @@ /** | ||
* @param {State} nok | ||
* @param {string} type | ||
* @param {string} markerType | ||
* @param {string} stringType | ||
* @param {TokenType} type | ||
* @param {TokenType} markerType | ||
* @param {TokenType} stringType | ||
* @param {boolean} [disallowEol=false] | ||
@@ -15,5 +15,5 @@ */ | ||
nok: State, | ||
type: string, | ||
markerType: string, | ||
stringType: string, | ||
type: TokenType, | ||
markerType: TokenType, | ||
stringType: TokenType, | ||
disallowEol?: boolean | undefined | ||
@@ -26,1 +26,2 @@ ): ( | ||
export type Token = import('micromark-util-types').Token | ||
export type TokenType = import('micromark-util-types').TokenType |
@@ -5,2 +5,3 @@ /** | ||
* @typedef {import('micromark-util-types').Token} Token | ||
* @typedef {import('micromark-util-types').TokenType} TokenType | ||
*/ | ||
@@ -23,5 +24,5 @@ | ||
* @param {State} nok | ||
* @param {string} type | ||
* @param {string} markerType | ||
* @param {string} stringType | ||
* @param {TokenType} type | ||
* @param {TokenType} markerType | ||
* @param {TokenType} stringType | ||
* @param {boolean} [disallowEol=false] | ||
@@ -28,0 +29,0 @@ */ |
@@ -6,3 +6,3 @@ /** | ||
* @param {State} nok | ||
* @param {string} type | ||
* @param {TokenType} type | ||
*/ | ||
@@ -14,3 +14,3 @@ export function factoryName( | ||
nok: State, | ||
type: string | ||
type: TokenType | ||
): ( | ||
@@ -22,1 +22,2 @@ code: import('micromark-util-types').Code | ||
export type TokenizeContext = import('micromark-util-types').TokenizeContext | ||
export type TokenType = import('micromark-util-types').TokenType |
@@ -5,2 +5,3 @@ /** | ||
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext | ||
* @typedef {import('micromark-util-types').TokenType} TokenType | ||
*/ | ||
@@ -16,3 +17,3 @@ | ||
* @param {State} nok | ||
* @param {string} type | ||
* @param {TokenType} type | ||
*/ | ||
@@ -19,0 +20,0 @@ export function factoryName(effects, ok, nok, type) { |
@@ -125,4 +125,2 @@ /** | ||
function enter(type) { | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
let stack = this.getData('directiveStack') | ||
@@ -138,5 +136,4 @@ if (!stack) this.setData('directiveStack', (stack = [])) | ||
function exitName(token) { | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
assert(stack, 'expected directive stack') | ||
stack[stack.length - 1].name = this.sliceSerialize(token) | ||
@@ -159,5 +156,4 @@ } | ||
const data = this.resume() | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
assert(stack, 'expected directive stack') | ||
stack[stack.length - 1].label = data | ||
@@ -180,5 +176,4 @@ } | ||
function exitAttributeIdValue(token) { | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
assert(attributes, 'expected attributes') | ||
attributes.push([ | ||
@@ -197,5 +192,4 @@ 'id', | ||
function exitAttributeClassValue(token) { | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
assert(attributes, 'expected attributes') | ||
@@ -217,5 +211,4 @@ attributes.push([ | ||
// references can’t exist. | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
assert(attributes, 'expected attributes') | ||
@@ -230,5 +223,4 @@ attributes.push([this.sliceSerialize(token), '']) | ||
function exitAttributeValue(token) { | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
assert(attributes, 'expected attributes') | ||
attributes[attributes.length - 1][1] = parseEntities( | ||
@@ -245,16 +237,12 @@ this.sliceSerialize(token), | ||
function exitAttributes() { | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
assert(stack, 'expected directive stack') | ||
const attributes = this.getData('directiveAttributes') | ||
assert(attributes, 'expected attributes') | ||
/** @type {Directive['attributes']} */ | ||
const cleaned = {} | ||
/** @type {Attribute} */ | ||
let attribute | ||
let index = -1 | ||
while (++index < attributes.length) { | ||
attribute = attributes[index] | ||
const attribute = attributes[index] | ||
@@ -279,5 +267,4 @@ if (attribute[0] === 'class' && cleaned.class) { | ||
const data = this.resume() | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
assert(stack, 'expected directive stack') | ||
stack[stack.length - 1].content = data | ||
@@ -291,5 +278,4 @@ } | ||
function exitContainerFence() { | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
assert(stack, 'expected directive stack') | ||
const directive = stack[stack.length - 1] | ||
@@ -306,5 +292,6 @@ if (!directive._fenceCount) directive._fenceCount = 0 | ||
function exit() { | ||
/** @type {Directive} */ | ||
// @ts-expect-error | ||
const directive = this.getData('directiveStack').pop() | ||
const stack = this.getData('directiveStack') | ||
assert(stack, 'expected directive stack') | ||
const directive = stack.pop() | ||
assert(directive, 'expected directive') | ||
/** @type {boolean|undefined} */ | ||
@@ -311,0 +298,0 @@ let found |
@@ -0,5 +1,82 @@ | ||
import type {Attribute, Directive} from './lib/html.js' | ||
export {directive} from './lib/syntax.js' | ||
export {directiveHtml} from './lib/html.js' | ||
export type Directive = import('./lib/html.js').Directive | ||
export type Handle = import('./lib/html.js').Handle | ||
export type HtmlOptions = import('./lib/html.js').HtmlOptions | ||
export { | ||
directiveHtml, | ||
type Directive, | ||
type Handle, | ||
type HtmlOptions | ||
} from './lib/html.js' | ||
declare module 'micromark-util-types' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface TokenTypeMap { | ||
directiveContainer: 'directiveContainer' | ||
directiveContainerAttributes: 'directiveContainerAttributes' | ||
directiveContainerAttributesMarker: 'directiveContainerAttributesMarker' | ||
directiveContainerAttribute: 'directiveContainerAttribute' | ||
directiveContainerAttributeId: 'directiveContainerAttributeId' | ||
directiveContainerAttributeIdValue: 'directiveContainerAttributeIdValue' | ||
directiveContainerAttributeClass: 'directiveContainerAttributeClass' | ||
directiveContainerAttributeClassValue: 'directiveContainerAttributeClassValue' | ||
directiveContainerAttributeName: 'directiveContainerAttributeName' | ||
directiveContainerAttributeInitializerMarker: 'directiveContainerAttributeInitializerMarker' | ||
directiveContainerAttributeValueLiteral: 'directiveContainerAttributeValueLiteral' | ||
directiveContainerAttributeValue: 'directiveContainerAttributeValue' | ||
directiveContainerAttributeValueMarker: 'directiveContainerAttributeValueMarker' | ||
directiveContainerAttributeValueData: 'directiveContainerAttributeValueData' | ||
directiveContainerContent: 'directiveContainerContent' | ||
directiveContainerFence: 'directiveContainerFence' | ||
directiveContainerLabel: 'directiveContainerLabel' | ||
directiveContainerLabelMarker: 'directiveContainerLabelMarker' | ||
directiveContainerLabelString: 'directiveContainerLabelString' | ||
directiveContainerName: 'directiveContainerName' | ||
directiveContainerSequence: 'directiveContainerSequence' | ||
directiveLeaf: 'directiveLeaf' | ||
directiveLeafAttributes: 'directiveLeafAttributes' | ||
directiveLeafAttributesMarker: 'directiveLeafAttributesMarker' | ||
directiveLeafAttribute: 'directiveLeafAttribute' | ||
directiveLeafAttributeId: 'directiveLeafAttributeId' | ||
directiveLeafAttributeIdValue: 'directiveLeafAttributeIdValue' | ||
directiveLeafAttributeClass: 'directiveLeafAttributeClass' | ||
directiveLeafAttributeClassValue: 'directiveLeafAttributeClassValue' | ||
directiveLeafAttributeName: 'directiveLeafAttributeName' | ||
directiveLeafAttributeInitializerMarker: 'directiveLeafAttributeInitializerMarker' | ||
directiveLeafAttributeValueLiteral: 'directiveLeafAttributeValueLiteral' | ||
directiveLeafAttributeValue: 'directiveLeafAttributeValue' | ||
directiveLeafAttributeValueMarker: 'directiveLeafAttributeValueMarker' | ||
directiveLeafAttributeValueData: 'directiveLeafAttributeValueData' | ||
directiveLeafLabel: 'directiveLeafLabel' | ||
directiveLeafLabelMarker: 'directiveLeafLabelMarker' | ||
directiveLeafLabelString: 'directiveLeafLabelString' | ||
directiveLeafName: 'directiveLeafName' | ||
directiveLeafSequence: 'directiveLeafSequence' | ||
directiveText: 'directiveText' | ||
directiveTextAttributes: 'directiveTextAttributes' | ||
directiveTextAttributesMarker: 'directiveTextAttributesMarker' | ||
directiveTextAttribute: 'directiveTextAttribute' | ||
directiveTextAttributeId: 'directiveTextAttributeId' | ||
directiveTextAttributeIdValue: 'directiveTextAttributeIdValue' | ||
directiveTextAttributeClass: 'directiveTextAttributeClass' | ||
directiveTextAttributeClassValue: 'directiveTextAttributeClassValue' | ||
directiveTextAttributeName: 'directiveTextAttributeName' | ||
directiveTextAttributeInitializerMarker: 'directiveTextAttributeInitializerMarker' | ||
directiveTextAttributeValueLiteral: 'directiveTextAttributeValueLiteral' | ||
directiveTextAttributeValue: 'directiveTextAttributeValue' | ||
directiveTextAttributeValueMarker: 'directiveTextAttributeValueMarker' | ||
directiveTextAttributeValueData: 'directiveTextAttributeValueData' | ||
directiveTextLabel: 'directiveTextLabel' | ||
directiveTextLabelMarker: 'directiveTextLabelMarker' | ||
directiveTextLabelString: 'directiveTextLabelString' | ||
directiveTextMarker: 'directiveTextMarker' | ||
directiveTextName: 'directiveTextName' | ||
} | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface CompileData { | ||
directiveAttributes?: Attribute[] | ||
directiveStack?: Directive[] | ||
} | ||
} |
@@ -1,8 +0,3 @@ | ||
/** | ||
* @typedef {import('./lib/html.js').Directive} Directive | ||
* @typedef {import('./lib/html.js').Handle} Handle | ||
* @typedef {import('./lib/html.js').HtmlOptions} HtmlOptions | ||
*/ | ||
// Note: more types exported from `index.d.ts`. | ||
export {directive} from './lib/syntax.js' | ||
export {directiveHtml} from './lib/html.js' |
@@ -5,13 +5,13 @@ /** | ||
* @param {State} nok | ||
* @param {string} attributesType | ||
* @param {string} attributesMarkerType | ||
* @param {string} attributeType | ||
* @param {string} attributeIdType | ||
* @param {string} attributeClassType | ||
* @param {string} attributeNameType | ||
* @param {string} attributeInitializerType | ||
* @param {string} attributeValueLiteralType | ||
* @param {string} attributeValueType | ||
* @param {string} attributeValueMarker | ||
* @param {string} attributeValueData | ||
* @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} [disallowEol=false] | ||
@@ -23,13 +23,13 @@ */ | ||
nok: State, | ||
attributesType: string, | ||
attributesMarkerType: string, | ||
attributeType: string, | ||
attributeIdType: string, | ||
attributeClassType: string, | ||
attributeNameType: string, | ||
attributeInitializerType: string, | ||
attributeValueLiteralType: string, | ||
attributeValueType: string, | ||
attributeValueMarker: string, | ||
attributeValueData: string, | ||
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 | ||
@@ -42,1 +42,2 @@ ): ( | ||
export type State = import('micromark-util-types').State | ||
export type TokenType = import('micromark-util-types').TokenType |
@@ -5,2 +5,3 @@ /** | ||
* @typedef {import('micromark-util-types').State} State | ||
* @typedef {import('micromark-util-types').TokenType} TokenType | ||
*/ | ||
@@ -21,13 +22,13 @@ | ||
* @param {State} nok | ||
* @param {string} attributesType | ||
* @param {string} attributesMarkerType | ||
* @param {string} attributeType | ||
* @param {string} attributeIdType | ||
* @param {string} attributeClassType | ||
* @param {string} attributeNameType | ||
* @param {string} attributeInitializerType | ||
* @param {string} attributeValueLiteralType | ||
* @param {string} attributeValueType | ||
* @param {string} attributeValueMarker | ||
* @param {string} attributeValueData | ||
* @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} [disallowEol=false] | ||
@@ -53,5 +54,5 @@ */ | ||
) { | ||
/** @type {string} */ | ||
/** @type {TokenType} */ | ||
let type | ||
/** @type {Code|undefined} */ | ||
/** @type {Code | undefined} */ | ||
let marker | ||
@@ -96,7 +97,9 @@ return start | ||
function shortcutStart(code) { | ||
// Assume it’s registered. | ||
const markerType = /** @type {TokenType} */ type + 'Marker' | ||
effects.enter(attributeType) | ||
effects.enter(type) | ||
effects.enter(type + 'Marker') | ||
effects.enter(markerType) | ||
effects.consume(code) | ||
effects.exit(type + 'Marker') | ||
effects.exit(markerType) | ||
return shortcutStartAfter | ||
@@ -122,3 +125,6 @@ } | ||
} | ||
effects.enter(type + 'Value') | ||
// Assume it’s registered. | ||
const valueType = /** @type {TokenType} */ type + 'Value' | ||
effects.enter(valueType) | ||
effects.consume(code) | ||
@@ -147,3 +153,5 @@ return shortcut | ||
) { | ||
effects.exit(type + 'Value') | ||
// Assume it’s registered. | ||
const valueType = /** @type {TokenType} */ type + 'Value' | ||
effects.exit(valueType) | ||
effects.exit(type) | ||
@@ -150,0 +158,0 @@ effects.exit(attributeType) |
@@ -5,5 +5,5 @@ /** | ||
* @param {State} nok | ||
* @param {string} type | ||
* @param {string} markerType | ||
* @param {string} stringType | ||
* @param {TokenType} type | ||
* @param {TokenType} markerType | ||
* @param {TokenType} stringType | ||
* @param {boolean} [disallowEol=false] | ||
@@ -15,5 +15,5 @@ */ | ||
nok: State, | ||
type: string, | ||
markerType: string, | ||
stringType: string, | ||
type: TokenType, | ||
markerType: TokenType, | ||
stringType: TokenType, | ||
disallowEol?: boolean | undefined | ||
@@ -26,1 +26,2 @@ ): ( | ||
export type Token = import('micromark-util-types').Token | ||
export type TokenType = import('micromark-util-types').TokenType |
@@ -5,2 +5,3 @@ /** | ||
* @typedef {import('micromark-util-types').Token} Token | ||
* @typedef {import('micromark-util-types').TokenType} TokenType | ||
*/ | ||
@@ -18,8 +19,7 @@ | ||
* @param {State} nok | ||
* @param {string} type | ||
* @param {string} markerType | ||
* @param {string} stringType | ||
* @param {TokenType} type | ||
* @param {TokenType} markerType | ||
* @param {TokenType} stringType | ||
* @param {boolean} [disallowEol=false] | ||
*/ | ||
// eslint-disable-next-line max-params | ||
*/ // eslint-disable-next-line max-params | ||
export function factoryLabel( | ||
@@ -26,0 +26,0 @@ effects, |
@@ -6,3 +6,3 @@ /** | ||
* @param {State} nok | ||
* @param {string} type | ||
* @param {TokenType} type | ||
*/ | ||
@@ -14,3 +14,3 @@ export function factoryName( | ||
nok: State, | ||
type: string | ||
type: TokenType | ||
): ( | ||
@@ -22,1 +22,2 @@ code: import('micromark-util-types').Code | ||
export type TokenizeContext = import('micromark-util-types').TokenizeContext | ||
export type TokenType = import('micromark-util-types').TokenType |
@@ -5,2 +5,3 @@ /** | ||
* @typedef {import('micromark-util-types').TokenizeContext} TokenizeContext | ||
* @typedef {import('micromark-util-types').TokenType} TokenType | ||
*/ | ||
@@ -14,3 +15,3 @@ | ||
* @param {State} nok | ||
* @param {string} type | ||
* @param {TokenType} type | ||
*/ | ||
@@ -17,0 +18,0 @@ export function factoryName(effects, ok, nok, type) { |
@@ -119,4 +119,2 @@ /** | ||
function enter(type) { | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
let stack = this.getData('directiveStack') | ||
@@ -135,4 +133,2 @@ if (!stack) this.setData('directiveStack', (stack = [])) | ||
function exitName(token) { | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
@@ -156,4 +152,2 @@ stack[stack.length - 1].name = this.sliceSerialize(token) | ||
const data = this.resume() | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
@@ -177,4 +171,2 @@ stack[stack.length - 1].label = data | ||
function exitAttributeIdValue(token) { | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
@@ -194,4 +186,2 @@ attributes.push([ | ||
function exitAttributeClassValue(token) { | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
@@ -213,4 +203,2 @@ attributes.push([ | ||
// references can’t exist. | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
@@ -225,4 +213,2 @@ attributes.push([this.sliceSerialize(token), '']) | ||
function exitAttributeValue(token) { | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
@@ -242,15 +228,9 @@ attributes[attributes.length - 1][1] = parseEntities( | ||
function exitAttributes() { | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
/** @type {Array<Attribute>} */ | ||
// @ts-expect-error | ||
const attributes = this.getData('directiveAttributes') | ||
/** @type {Directive['attributes']} */ | ||
const cleaned = {} | ||
/** @type {Attribute} */ | ||
let attribute | ||
let index = -1 | ||
while (++index < attributes.length) { | ||
attribute = attributes[index] | ||
const attribute = attributes[index] | ||
if (attribute[0] === 'class' && cleaned.class) { | ||
@@ -273,4 +253,2 @@ cleaned.class += ' ' + attribute[1] | ||
const data = this.resume() | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
@@ -285,4 +263,2 @@ stack[stack.length - 1].content = data | ||
function exitContainerFence() { | ||
/** @type {Directive[]} */ | ||
// @ts-expect-error | ||
const stack = this.getData('directiveStack') | ||
@@ -300,5 +276,4 @@ const directive = stack[stack.length - 1] | ||
function exit() { | ||
/** @type {Directive} */ | ||
// @ts-expect-error | ||
const directive = this.getData('directiveStack').pop() | ||
const stack = this.getData('directiveStack') | ||
const directive = stack.pop() | ||
/** @type {boolean|undefined} */ | ||
@@ -305,0 +280,0 @@ let found |
{ | ||
"name": "micromark-extension-directive", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "micromark extension to support generic directives (`:cite[smith04]`)", | ||
@@ -51,3 +51,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"@types/node": "^20.0.0", | ||
"c8": "^7.0.0", | ||
@@ -60,6 +60,5 @@ "html-void-elements": "^2.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"tape": "^5.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^5.0.0", | ||
"xo": "^0.53.0" | ||
"xo": "^0.54.0" | ||
}, | ||
@@ -66,0 +65,0 @@ "scripts": { |
@@ -214,6 +214,15 @@ # micromark-extension-directive | ||
When authoring markdown with directives, keep in mind that they don’t work in | ||
most places. | ||
On your own site it can be great! | ||
## HTML | ||
You can define how directives are turned into HTML. | ||
If directives are not handled, they do not emit anything. | ||
## CSS | ||
How to display directives is left as an exercise for the reader. | ||
## Syntax | ||
@@ -220,0 +229,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105261
11
2998
416