mdast-util-directive
Advanced tools
Comparing version 2.2.4 to 3.0.0
109
index.d.ts
import type { | ||
Data, | ||
Parent, | ||
@@ -10,3 +11,5 @@ BlockContent, | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
/** | ||
* Fields shared by directives. | ||
*/ | ||
interface DirectiveFields { | ||
@@ -21,3 +24,2 @@ /** | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
attributes?: Record<string, string | null | undefined> | null | undefined | ||
@@ -27,9 +29,7 @@ } | ||
/** | ||
* Directive in flow content (such as in the root document, or block | ||
* quotes), which contains further flow content. | ||
* Markdown directive (container form). | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface ContainerDirective extends Parent, DirectiveFields { | ||
/** | ||
* Node type. | ||
* Node type of container directive. | ||
*/ | ||
@@ -39,15 +39,23 @@ type: 'containerDirective' | ||
/** | ||
* Content. | ||
* Children of container directive. | ||
*/ | ||
children: Array<BlockContent | DefinitionContent> | ||
/** | ||
* Data associated with the mdast container directive. | ||
*/ | ||
data?: ContainerDirectiveData | undefined | ||
} | ||
/** | ||
* Directive in flow content (such as in the root document, or block | ||
* quotes), which contains nothing. | ||
* Info associated with mdast container directive nodes by the ecosystem. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface ContainerDirectiveData extends Data {} | ||
/** | ||
* Markdown directive (leaf form). | ||
*/ | ||
export interface LeafDirective extends Parent, DirectiveFields { | ||
/** | ||
* Node type. | ||
* Node type of leaf directive. | ||
*/ | ||
@@ -57,14 +65,23 @@ type: 'leafDirective' | ||
/** | ||
* Content. | ||
* Children of leaf directive. | ||
*/ | ||
children: PhrasingContent[] | ||
/** | ||
* Data associated with the mdast leaf directive. | ||
*/ | ||
data?: LeafDirectiveData | undefined | ||
} | ||
/** | ||
* Directive in phrasing content (such as in paragraphs, headings). | ||
* Info associated with mdast leaf directive nodes by the ecosystem. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export interface LeafDirectiveData extends Data {} | ||
/** | ||
* Markdown directive (text form). | ||
*/ | ||
export interface TextDirective extends Parent, DirectiveFields { | ||
/** | ||
* Node type. | ||
* Node type of text directive. | ||
*/ | ||
@@ -74,15 +91,26 @@ type: 'textDirective' | ||
/** | ||
* Content. | ||
* Children of text directive. | ||
*/ | ||
children: PhrasingContent[] | ||
/** | ||
* Data associated with the text leaf directive. | ||
*/ | ||
data?: TextDirectiveData | undefined | ||
} | ||
/** | ||
* The different directive nodes. | ||
* Info associated with mdast text directive nodes by the ecosystem. | ||
*/ | ||
export type Directive = ContainerDirective | LeafDirective | TextDirective | ||
export interface TextDirectiveData extends Data {} | ||
/** | ||
* Union of registered mdast directive nodes. | ||
* | ||
* It is not possible to register custom mdast directive node types. | ||
*/ | ||
export type Directives = ContainerDirective | LeafDirective | TextDirective | ||
// Add custom data tracked to turn markdown into a tree. | ||
declare module 'mdast-util-from-markdown' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface CompileData { | ||
@@ -98,3 +126,2 @@ /** | ||
declare module 'mdast-util-to-markdown' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface ConstructNameMap { | ||
@@ -166,7 +193,35 @@ /** | ||
// Add nodes to content. | ||
// Add nodes to content, register `data` on paragraph. | ||
declare module 'mdast' { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface StaticPhrasingContentMap { | ||
interface BlockContentMap { | ||
/** | ||
* Directive in flow content (such as in the root document, or block | ||
* quotes), which contains further flow content. | ||
*/ | ||
containerDirective: ContainerDirective | ||
/** | ||
* Directive in flow content (such as in the root document, or block | ||
* quotes), which contains nothing. | ||
*/ | ||
leafDirective: LeafDirective | ||
} | ||
interface ParagraphData { | ||
/** | ||
* Field set on the first paragraph which is a child of a container | ||
* directive. | ||
* When this is `true`, that means the paragraph represents the *label*: | ||
* | ||
* ```markdown | ||
* :::a[This is the label] | ||
* This is further things. | ||
* ::: | ||
* ``` | ||
*/ | ||
directiveLabel?: boolean | null | undefined | ||
} | ||
interface PhrasingContentMap { | ||
/** | ||
* Directive in phrasing content (such as in paragraphs, headings). | ||
@@ -177,4 +232,3 @@ */ | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
interface BlockContentMap { | ||
interface RootContentMap { | ||
/** | ||
@@ -191,3 +245,8 @@ * Directive in flow content (such as in the root document, or block | ||
leafDirective: LeafDirective | ||
/** | ||
* Directive in phrasing content (such as in paragraphs, headings). | ||
*/ | ||
textDirective: TextDirective | ||
} | ||
} |
/** | ||
* Extension for `mdast-util-from-markdown` to enable directives. | ||
* Create an extension for `mdast-util-from-markdown` to enable directives in | ||
* markdown. | ||
* | ||
* @type {FromMarkdownExtension} | ||
* @returns {FromMarkdownExtension} | ||
* Extension for `mdast-util-from-markdown` to enable directives. | ||
*/ | ||
export const directiveFromMarkdown: FromMarkdownExtension | ||
export function directiveFromMarkdown(): FromMarkdownExtension | ||
/** | ||
* Extension for `mdast-util-to-markdown` to enable directives. | ||
* Create an extension for `mdast-util-to-markdown` to enable directives in | ||
* markdown. | ||
* | ||
* @type {ToMarkdownExtension} | ||
* @returns {ToMarkdownExtension} | ||
* Extension for `mdast-util-to-markdown` to enable directives. | ||
*/ | ||
export const directiveToMarkdown: ToMarkdownExtension | ||
export type BlockContent = import('mdast').BlockContent | ||
export type DefinitionContent = import('mdast').DefinitionContent | ||
export function directiveToMarkdown(): ToMarkdownExtension | ||
export type Nodes = import('mdast').Nodes | ||
export type Paragraph = import('mdast').Paragraph | ||
@@ -24,4 +27,4 @@ export type CompileContext = import('mdast-util-from-markdown').CompileContext | ||
export type State = import('mdast-util-to-markdown').State | ||
export type Directives = import('../index.js').Directives | ||
export type LeafDirective = import('../index.js').LeafDirective | ||
export type TextDirective = import('../index.js').TextDirective | ||
export type Directive = import('../index.js').Directive |
213
lib/index.js
/** | ||
* @typedef {import('mdast').BlockContent} BlockContent | ||
* @typedef {import('mdast').DefinitionContent} DefinitionContent | ||
* @typedef {import('mdast').Nodes} Nodes | ||
* @typedef {import('mdast').Paragraph} Paragraph | ||
@@ -16,19 +15,12 @@ * | ||
* | ||
* @typedef {import('../index.js').Directives} Directives | ||
* @typedef {import('../index.js').LeafDirective} LeafDirective | ||
* @typedef {import('../index.js').TextDirective} TextDirective | ||
* @typedef {import('../index.js').Directive} Directive | ||
*/ | ||
import {ok as assert} from 'devlop' | ||
import {parseEntities} from 'parse-entities' | ||
import {stringifyEntitiesLight} from 'stringify-entities' | ||
import {visitParents} from 'unist-util-visit-parents' | ||
import {containerFlow} from 'mdast-util-to-markdown/lib/util/container-flow.js' | ||
import {containerPhrasing} from 'mdast-util-to-markdown/lib/util/container-phrasing.js' | ||
import {checkQuote} from 'mdast-util-to-markdown/lib/util/check-quote.js' | ||
import {track} from 'mdast-util-to-markdown/lib/util/track.js' | ||
// To do: next major: replace `containerFlow`, `containerPhrasing`, `track` | ||
// with `state` methods. | ||
// To do: next major: expose functions. | ||
const own = {}.hasOwnProperty | ||
@@ -41,44 +33,48 @@ | ||
/** | ||
* Extension for `mdast-util-from-markdown` to enable directives. | ||
* Create an extension for `mdast-util-from-markdown` to enable directives in | ||
* markdown. | ||
* | ||
* @type {FromMarkdownExtension} | ||
* @returns {FromMarkdownExtension} | ||
* Extension for `mdast-util-from-markdown` to enable directives. | ||
*/ | ||
export const directiveFromMarkdown = { | ||
canContainEols: ['textDirective'], | ||
enter: { | ||
directiveContainer: enterContainer, | ||
directiveContainerAttributes: enterAttributes, | ||
directiveContainerLabel: enterContainerLabel, | ||
export function directiveFromMarkdown() { | ||
return { | ||
canContainEols: ['textDirective'], | ||
enter: { | ||
directiveContainer: enterContainer, | ||
directiveContainerAttributes: enterAttributes, | ||
directiveContainerLabel: enterContainerLabel, | ||
directiveLeaf: enterLeaf, | ||
directiveLeafAttributes: enterAttributes, | ||
directiveLeaf: enterLeaf, | ||
directiveLeafAttributes: enterAttributes, | ||
directiveText: enterText, | ||
directiveTextAttributes: enterAttributes | ||
}, | ||
exit: { | ||
directiveContainer: exit, | ||
directiveContainerAttributeClassValue: exitAttributeClassValue, | ||
directiveContainerAttributeIdValue: exitAttributeIdValue, | ||
directiveContainerAttributeName: exitAttributeName, | ||
directiveContainerAttributeValue: exitAttributeValue, | ||
directiveContainerAttributes: exitAttributes, | ||
directiveContainerLabel: exitContainerLabel, | ||
directiveContainerName: exitName, | ||
directiveText: enterText, | ||
directiveTextAttributes: enterAttributes | ||
}, | ||
exit: { | ||
directiveContainer: exit, | ||
directiveContainerAttributeClassValue: exitAttributeClassValue, | ||
directiveContainerAttributeIdValue: exitAttributeIdValue, | ||
directiveContainerAttributeName: exitAttributeName, | ||
directiveContainerAttributeValue: exitAttributeValue, | ||
directiveContainerAttributes: exitAttributes, | ||
directiveContainerLabel: exitContainerLabel, | ||
directiveContainerName: exitName, | ||
directiveLeaf: exit, | ||
directiveLeafAttributeClassValue: exitAttributeClassValue, | ||
directiveLeafAttributeIdValue: exitAttributeIdValue, | ||
directiveLeafAttributeName: exitAttributeName, | ||
directiveLeafAttributeValue: exitAttributeValue, | ||
directiveLeafAttributes: exitAttributes, | ||
directiveLeafName: exitName, | ||
directiveLeaf: exit, | ||
directiveLeafAttributeClassValue: exitAttributeClassValue, | ||
directiveLeafAttributeIdValue: exitAttributeIdValue, | ||
directiveLeafAttributeName: exitAttributeName, | ||
directiveLeafAttributeValue: exitAttributeValue, | ||
directiveLeafAttributes: exitAttributes, | ||
directiveLeafName: exitName, | ||
directiveText: exit, | ||
directiveTextAttributeClassValue: exitAttributeClassValue, | ||
directiveTextAttributeIdValue: exitAttributeIdValue, | ||
directiveTextAttributeName: exitAttributeName, | ||
directiveTextAttributeValue: exitAttributeValue, | ||
directiveTextAttributes: exitAttributes, | ||
directiveTextName: exitName | ||
directiveText: exit, | ||
directiveTextAttributeClassValue: exitAttributeClassValue, | ||
directiveTextAttributeIdValue: exitAttributeIdValue, | ||
directiveTextAttributeName: exitAttributeName, | ||
directiveTextAttributeValue: exitAttributeValue, | ||
directiveTextAttributes: exitAttributes, | ||
directiveTextName: exitName | ||
} | ||
} | ||
@@ -88,28 +84,32 @@ } | ||
/** | ||
* Extension for `mdast-util-to-markdown` to enable directives. | ||
* Create an extension for `mdast-util-to-markdown` to enable directives in | ||
* markdown. | ||
* | ||
* @type {ToMarkdownExtension} | ||
* @returns {ToMarkdownExtension} | ||
* Extension for `mdast-util-to-markdown` to enable directives. | ||
*/ | ||
export const directiveToMarkdown = { | ||
unsafe: [ | ||
{ | ||
character: '\r', | ||
inConstruct: ['leafDirectiveLabel', 'containerDirectiveLabel'] | ||
}, | ||
{ | ||
character: '\n', | ||
inConstruct: ['leafDirectiveLabel', 'containerDirectiveLabel'] | ||
}, | ||
{ | ||
before: '[^:]', | ||
character: ':', | ||
after: '[A-Za-z]', | ||
inConstruct: ['phrasing'] | ||
}, | ||
{atBreak: true, character: ':', after: ':'} | ||
], | ||
handlers: { | ||
containerDirective: handleDirective, | ||
leafDirective: handleDirective, | ||
textDirective: handleDirective | ||
export function directiveToMarkdown() { | ||
return { | ||
unsafe: [ | ||
{ | ||
character: '\r', | ||
inConstruct: ['leafDirectiveLabel', 'containerDirectiveLabel'] | ||
}, | ||
{ | ||
character: '\n', | ||
inConstruct: ['leafDirectiveLabel', 'containerDirectiveLabel'] | ||
}, | ||
{ | ||
before: '[^:]', | ||
character: ':', | ||
after: '[A-Za-z]', | ||
inConstruct: ['phrasing'] | ||
}, | ||
{atBreak: true, character: ':', after: ':'} | ||
], | ||
handlers: { | ||
containerDirective: handleDirective, | ||
leafDirective: handleDirective, | ||
textDirective: handleDirective | ||
} | ||
} | ||
@@ -144,3 +144,3 @@ } | ||
* @this {CompileContext} | ||
* @param {Directive['type']} type | ||
* @param {Directives['type']} type | ||
* @param {Token} token | ||
@@ -157,3 +157,8 @@ */ | ||
function exitName(token) { | ||
const node = /** @type {Directive} */ (this.stack[this.stack.length - 1]) | ||
const node = this.stack[this.stack.length - 1] | ||
assert( | ||
node.type === 'containerDirective' || | ||
node.type === 'leafDirective' || | ||
node.type === 'textDirective' | ||
) | ||
node.name = this.sliceSerialize(token) | ||
@@ -186,3 +191,3 @@ } | ||
function enterAttributes() { | ||
this.setData('directiveAttributes', []) | ||
this.data.directiveAttributes = [] | ||
this.buffer() // Capture EOLs | ||
@@ -196,5 +201,4 @@ } | ||
function exitAttributeIdValue(token) { | ||
const list = /** @type {Array<[string, string]>} */ ( | ||
this.getData('directiveAttributes') | ||
) | ||
const list = this.data.directiveAttributes | ||
assert(list, 'expected `directiveAttributes`') | ||
list.push([ | ||
@@ -213,5 +217,4 @@ 'id', | ||
function exitAttributeClassValue(token) { | ||
const list = /** @type {Array<[string, string]>} */ ( | ||
this.getData('directiveAttributes') | ||
) | ||
const list = this.data.directiveAttributes | ||
assert(list, 'expected `directiveAttributes`') | ||
list.push([ | ||
@@ -230,5 +233,4 @@ 'class', | ||
function exitAttributeValue(token) { | ||
const list = /** @type {Array<[string, string]>} */ ( | ||
this.getData('directiveAttributes') | ||
) | ||
const list = this.data.directiveAttributes | ||
assert(list, 'expected `directiveAttributes`') | ||
list[list.length - 1][1] = parseEntities(this.sliceSerialize(token), { | ||
@@ -244,5 +246,4 @@ attribute: true | ||
function exitAttributeName(token) { | ||
const list = /** @type {Array<[string, string]>} */ ( | ||
this.getData('directiveAttributes') | ||
) | ||
const list = this.data.directiveAttributes | ||
assert(list, 'expected `directiveAttributes`') | ||
@@ -259,5 +260,4 @@ // Attribute names in CommonMark are significantly limited, so character | ||
function exitAttributes() { | ||
const list = /** @type {Array<[string, string]>} */ ( | ||
this.getData('directiveAttributes') | ||
) | ||
const list = this.data.directiveAttributes | ||
assert(list, 'expected `directiveAttributes`') | ||
/** @type {Record<string, string>} */ | ||
@@ -277,5 +277,10 @@ const cleaned = {} | ||
this.setData('directiveAttributes') | ||
this.data.directiveAttributes = undefined | ||
this.resume() // Drop EOLs | ||
const node = /** @type {Directive} */ (this.stack[this.stack.length - 1]) | ||
const node = this.stack[this.stack.length - 1] | ||
assert( | ||
node.type === 'containerDirective' || | ||
node.type === 'leafDirective' || | ||
node.type === 'textDirective' | ||
) | ||
node.attributes = cleaned | ||
@@ -294,10 +299,10 @@ } | ||
* @type {ToMarkdownHandle} | ||
* @param {Directive} node | ||
* @param {Directives} node | ||
*/ | ||
function handleDirective(node, _, state, safeOptions) { | ||
const tracker = track(safeOptions) | ||
function handleDirective(node, _, state, info) { | ||
const tracker = state.createTracker(info) | ||
const sequence = fence(node) | ||
const exit = state.enter(node.type) | ||
let value = tracker.move(sequence + (node.name || '')) | ||
/** @type {Paragraph | LeafDirective | TextDirective | undefined} */ | ||
/** @type {LeafDirective | Paragraph | TextDirective | undefined} */ | ||
let label | ||
@@ -319,3 +324,7 @@ | ||
value += tracker.move( | ||
containerPhrasing(label, state, { | ||
// @ts-expect-error: `containerPhrasing` is typed correctly, but TS | ||
// generates *hardcoded* types, which means that our dynamically added | ||
// directives are not present. | ||
// At some point, TS should fix that, and `from-markdown` should be fine. | ||
state.containerPhrasing(label, { | ||
...tracker.current(), | ||
@@ -343,3 +352,3 @@ before: value, | ||
value += tracker.move('\n') | ||
value += tracker.move(containerFlow(shallow, state, tracker.current())) | ||
value += tracker.move(state.containerFlow(shallow, tracker.current())) | ||
} | ||
@@ -360,3 +369,3 @@ | ||
/** | ||
* @param {Directive} node | ||
* @param {Directives} node | ||
* @param {State} state | ||
@@ -366,3 +375,3 @@ * @returns {string} | ||
function attributes(node, state) { | ||
const quote = checkQuote(state) | ||
const quote = state.options.quote || '"' | ||
const subset = node.type === 'textDirective' ? [quote] : [quote, '\n', '\r'] | ||
@@ -446,4 +455,4 @@ const attrs = node.attributes || {} | ||
/** | ||
* @param {BlockContent | DefinitionContent} node | ||
* @returns {node is Paragraph & {data: {directiveLabel: boolean}}} | ||
* @param {Nodes} node | ||
* @returns {node is Paragraph & {data: {directiveLabel: true}}} | ||
*/ | ||
@@ -457,3 +466,3 @@ function inlineDirectiveLabel(node) { | ||
/** | ||
* @param {Directive} node | ||
* @param {Directives} node | ||
* @returns {string} | ||
@@ -460,0 +469,0 @@ */ |
{ | ||
"name": "mdast-util-directive", | ||
"version": "2.2.4", | ||
"version": "3.0.0", | ||
"description": "mdast extension to parse and serialize generic directives (`:cite[smith04]`)", | ||
@@ -31,7 +31,5 @@ "license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"exports": "./index.js", | ||
"files": [ | ||
"lib/", | ||
"complex-types.d.ts", | ||
"index.d.ts", | ||
@@ -41,15 +39,15 @@ "index.js" | ||
"dependencies": { | ||
"@types/mdast": "^3.0.0", | ||
"@types/unist": "^2.0.0", | ||
"mdast-util-from-markdown": "^1.3.0", | ||
"mdast-util-to-markdown": "^1.5.0", | ||
"@types/mdast": "^4.0.0", | ||
"@types/unist": "^3.0.0", | ||
"devlop": "^1.0.0", | ||
"mdast-util-from-markdown": "^2.0.0", | ||
"mdast-util-to-markdown": "^2.0.0", | ||
"parse-entities": "^4.0.0", | ||
"stringify-entities": "^4.0.0", | ||
"unist-util-visit-parents": "^5.1.3" | ||
"unist-util-visit-parents": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.0.0", | ||
"c8": "^7.0.0", | ||
"mdast-util-from-markdown": "^1.0.0", | ||
"micromark-extension-directive": "^2.0.0", | ||
"@types/node": "^20.0.0", | ||
"c8": "^8.0.0", | ||
"micromark-extension-directive": "^3.0.0", | ||
"prettier": "^2.0.0", | ||
@@ -59,5 +57,5 @@ "remark-cli": "^11.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"unist-util-remove-position": "^4.0.0", | ||
"xo": "^0.53.0" | ||
"typescript": "^5.0.0", | ||
"unist-util-remove-position": "^5.0.0", | ||
"xo": "^0.54.0" | ||
}, | ||
@@ -68,20 +66,19 @@ "scripts": { | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", | ||
"test-api-prod": "node --conditions production test.js", | ||
"test-api-dev": "node --conditions development test.js", | ||
"test-api": "npm run test-api-dev && npm run test-api-prod", | ||
"test-coverage": "c8 --100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"prettier": { | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"singleQuote": true, | ||
"bracketSpacing": false, | ||
"semi": false, | ||
"trailingComma": "none" | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"xo": { | ||
"prettier": true | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -92,5 +89,19 @@ }, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"overrides": [ | ||
{ | ||
"files": [ | ||
"**/*.ts" | ||
], | ||
"rules": { | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/consistent-type-definitions": "off" | ||
} | ||
} | ||
], | ||
"prettier": true | ||
} | ||
} |
@@ -22,6 +22,6 @@ # mdast-util-directive | ||
* [API](#api) | ||
* [`directiveFromMarkdown`](#directivefrommarkdown) | ||
* [`directiveToMarkdown`](#directivetomarkdown) | ||
* [`directiveFromMarkdown()`](#directivefrommarkdown) | ||
* [`directiveToMarkdown()`](#directivetomarkdown) | ||
* [`ContainerDirective`](#containerdirective) | ||
* [`Directive`](#directive) | ||
* [`Directives`](#directives) | ||
* [`LeafDirective`](#leafdirective) | ||
@@ -86,3 +86,3 @@ * [`TextDirective`](#textdirective) | ||
This package is [ESM only][esm]. | ||
In Node.js (version 14.14+ and 16.0+), install with [npm][]: | ||
In Node.js (version 16+), install with [npm][]: | ||
@@ -96,3 +96,3 @@ ```sh | ||
```js | ||
import {directiveFromMarkdown, directiveToMarkdown} from 'https://esm.sh/mdast-util-directive@2' | ||
import {directiveFromMarkdown, directiveToMarkdown} from 'https://esm.sh/mdast-util-directive@3' | ||
``` | ||
@@ -104,3 +104,3 @@ | ||
<script type="module"> | ||
import {directiveFromMarkdown, directiveToMarkdown} from 'https://esm.sh/mdast-util-directive@2?bundle' | ||
import {directiveFromMarkdown, directiveToMarkdown} from 'https://esm.sh/mdast-util-directive@3?bundle' | ||
</script> | ||
@@ -130,3 +130,3 @@ ``` | ||
extensions: [directive()], | ||
mdastExtensions: [directiveFromMarkdown] | ||
mdastExtensions: [directiveFromMarkdown()] | ||
}) | ||
@@ -136,3 +136,3 @@ | ||
const out = toMarkdown(tree, {extensions: [directiveToMarkdown]}) | ||
const out = toMarkdown(tree, {extensions: [directiveToMarkdown()]}) | ||
@@ -172,19 +172,29 @@ console.log(out) | ||
This package exports the identifiers | ||
[`directiveFromMarkdown`][api-directivefrommarkdown] and | ||
[`directiveToMarkdown`][api-directivetomarkdown]. | ||
[`directiveFromMarkdown`][api-directive-from-markdown] and | ||
[`directiveToMarkdown`][api-directive-to-markdown]. | ||
There is no default export. | ||
### `directiveFromMarkdown` | ||
### `directiveFromMarkdown()` | ||
Extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] to enable | ||
directives ([`FromMarkdownExtension`][frommarkdownextension]). | ||
Create an extension for [`mdast-util-from-markdown`][mdast-util-from-markdown] | ||
to enable directives in markdown. | ||
### `directiveToMarkdown` | ||
###### Returns | ||
Extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] to enable | ||
directives ([`ToMarkdownExtension`][tomarkdownextension]). | ||
Extension for `mdast-util-from-markdown` to enable directives | ||
([`FromMarkdownExtension`][from-markdown-extension]). | ||
### `directiveToMarkdown()` | ||
Create an extension for [`mdast-util-to-markdown`][mdast-util-to-markdown] | ||
to enable directives in markdown. | ||
There are no options, but passing [`options.quote`][quote] to | ||
`mdast-util-to-markdown` is honored for attributes. | ||
###### Returns | ||
Extension for `mdast-util-to-markdown` to enable directives | ||
([`ToMarkdownExtension`][to-markdown-extension]). | ||
### `ContainerDirective` | ||
@@ -208,3 +218,3 @@ | ||
### `Directive` | ||
### `Directives` | ||
@@ -216,3 +226,3 @@ The different directive nodes (TypeScript type). | ||
```ts | ||
type Directive = ContainerDirective | LeafDirective | TextDirective | ||
type Directives = ContainerDirective | LeafDirective | TextDirective | ||
``` | ||
@@ -421,5 +431,5 @@ | ||
This package is fully typed with [TypeScript][]. | ||
It exports the additional types [`ContainerDirective`][api-containerdirective], | ||
[`Directive`][api-directive], [`LeafDirective`][api-leafdirective], and | ||
[`TextDirective`][api-textdirective]. | ||
It exports the additional types [`ContainerDirective`][api-container-directive], | ||
[`Directives`][api-directives], [`LeafDirective`][api-leaf-directive], and | ||
[`TextDirective`][api-text-directive]. | ||
@@ -440,3 +450,3 @@ It also registers the node types with `@types/mdast`. | ||
visit(tree, (node) => { | ||
visit(tree, function (node) { | ||
// `node` can now be one of the nodes for directives. | ||
@@ -448,10 +458,13 @@ }) | ||
Projects maintained by the unified collective are compatible with all maintained | ||
Projects maintained by the unified collective are compatible with maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 14.14+ and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
This plugin works with `mdast-util-from-markdown` version 1+ and | ||
`mdast-util-to-markdown` version 1+. | ||
When we cut a new major release, we drop support for unmaintained versions of | ||
Node. | ||
This means we try to keep the current release line, `mdast-util-directive@^3`, | ||
compatible with Node.js 16. | ||
This utility works with `mdast-util-from-markdown` version 2+ and | ||
`mdast-util-to-markdown` version 2+. | ||
## Related | ||
@@ -492,5 +505,5 @@ | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/mdast-util-directive.svg | ||
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=mdast-util-directive | ||
[size]: https://bundlephobia.com/result?p=mdast-util-directive | ||
[size]: https://bundlejs.com/?q=mdast-util-directive | ||
@@ -555,18 +568,18 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[frommarkdownextension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension | ||
[from-markdown-extension]: https://github.com/syntax-tree/mdast-util-from-markdown#extension | ||
[tomarkdownextension]: https://github.com/syntax-tree/mdast-util-to-markdown#options | ||
[to-markdown-extension]: https://github.com/syntax-tree/mdast-util-to-markdown#options | ||
[api-directivefrommarkdown]: #directivefrommarkdown | ||
[api-directive-from-markdown]: #directivefrommarkdown | ||
[api-directivetomarkdown]: #directivetomarkdown | ||
[api-directive-to-markdown]: #directivetomarkdown | ||
[api-containerdirective]: #containerdirective | ||
[api-container-directive]: #containerdirective | ||
[api-directive]: #directive | ||
[api-directives]: #directives | ||
[api-leafdirective]: #leafdirective | ||
[api-leaf-directive]: #leafdirective | ||
[api-textdirective]: #textdirective | ||
[api-text-directive]: #textdirective | ||
[dfn-mxn-directive]: #directive-1 | ||
[dfn-mxn-directive]: #directive |
37863
10
666
572
8
7
+ Addeddevlop@^1.0.0
+ Added@types/mdast@4.0.4(transitive)
+ Added@types/unist@3.0.3(transitive)
+ Addeddevlop@1.1.0(transitive)
+ Addedmdast-util-from-markdown@2.0.2(transitive)
+ Addedmdast-util-phrasing@4.1.0(transitive)
+ Addedmdast-util-to-markdown@2.1.2(transitive)
+ Addedmdast-util-to-string@4.0.0(transitive)
+ Addedmicromark@4.0.1(transitive)
+ Addedmicromark-core-commonmark@2.0.2(transitive)
+ Addedmicromark-factory-destination@2.0.1(transitive)
+ Addedmicromark-factory-label@2.0.1(transitive)
+ Addedmicromark-factory-space@2.0.1(transitive)
+ Addedmicromark-factory-title@2.0.1(transitive)
+ Addedmicromark-factory-whitespace@2.0.1(transitive)
+ Addedmicromark-util-character@2.1.1(transitive)
+ Addedmicromark-util-chunked@2.0.1(transitive)
+ Addedmicromark-util-classify-character@2.0.1(transitive)
+ Addedmicromark-util-combine-extensions@2.0.1(transitive)
+ Addedmicromark-util-decode-numeric-character-reference@2.0.2(transitive)
+ Addedmicromark-util-decode-string@2.0.1(transitive)
+ Addedmicromark-util-encode@2.0.1(transitive)
+ Addedmicromark-util-html-tag-name@2.0.1(transitive)
+ Addedmicromark-util-normalize-identifier@2.0.1(transitive)
+ Addedmicromark-util-resolve-all@2.0.1(transitive)
+ Addedmicromark-util-sanitize-uri@2.0.1(transitive)
+ Addedmicromark-util-subtokenize@2.0.3(transitive)
+ Addedmicromark-util-symbol@2.0.1(transitive)
+ Addedmicromark-util-types@2.0.1(transitive)
+ Addedunist-util-is@6.0.0(transitive)
+ Addedunist-util-stringify-position@4.0.0(transitive)
+ Addedunist-util-visit@5.0.0(transitive)
+ Addedunist-util-visit-parents@6.0.1(transitive)
- Removed@types/mdast@3.0.15(transitive)
- Removeddiff@5.2.0(transitive)
- Removedkleur@4.1.5(transitive)
- Removedmdast-util-from-markdown@1.3.1(transitive)
- Removedmdast-util-phrasing@3.0.1(transitive)
- Removedmdast-util-to-markdown@1.5.0(transitive)
- Removedmdast-util-to-string@3.2.0(transitive)
- Removedmicromark@3.2.0(transitive)
- Removedmicromark-core-commonmark@1.1.0(transitive)
- Removedmicromark-factory-destination@1.1.0(transitive)
- Removedmicromark-factory-label@1.1.0(transitive)
- Removedmicromark-factory-space@1.1.0(transitive)
- Removedmicromark-factory-title@1.1.0(transitive)
- Removedmicromark-factory-whitespace@1.1.0(transitive)
- Removedmicromark-util-character@1.2.0(transitive)
- Removedmicromark-util-chunked@1.1.0(transitive)
- Removedmicromark-util-classify-character@1.1.0(transitive)
- Removedmicromark-util-combine-extensions@1.1.0(transitive)
- Removedmicromark-util-decode-numeric-character-reference@1.1.0(transitive)
- Removedmicromark-util-decode-string@1.1.0(transitive)
- Removedmicromark-util-encode@1.1.0(transitive)
- Removedmicromark-util-html-tag-name@1.2.0(transitive)
- Removedmicromark-util-normalize-identifier@1.1.0(transitive)
- Removedmicromark-util-resolve-all@1.1.0(transitive)
- Removedmicromark-util-sanitize-uri@1.2.0(transitive)
- Removedmicromark-util-subtokenize@1.1.0(transitive)
- Removedmicromark-util-symbol@1.1.0(transitive)
- Removedmicromark-util-types@1.1.0(transitive)
- Removedmri@1.2.0(transitive)
- Removedsade@1.8.1(transitive)
- Removedunist-util-is@5.2.1(transitive)
- Removedunist-util-stringify-position@3.0.3(transitive)
- Removedunist-util-visit@4.1.2(transitive)
- Removedunist-util-visit-parents@5.1.3(transitive)
- Removeduvu@0.5.6(transitive)
Updated@types/mdast@^4.0.0
Updated@types/unist@^3.0.0