diff --git a/.changeset/afraid-moose-compete.md b/.changeset/afraid-moose-compete.md new file mode 100644 index 000000000..274cc4847 --- /dev/null +++ b/.changeset/afraid-moose-compete.md @@ -0,0 +1,5 @@ +--- +"myst-directives": patch +--- + +Add div directive diff --git a/packages/myst-directives/src/div.ts b/packages/myst-directives/src/div.ts new file mode 100644 index 000000000..d829dbc45 --- /dev/null +++ b/packages/myst-directives/src/div.ts @@ -0,0 +1,31 @@ +import type { DirectiveSpec, DirectiveData, GenericNode } from 'myst-common'; +import type { FlowContent, ListContent, PhrasingContent } from 'myst-spec'; +import { normalizeLabel } from 'myst-common'; + +export const divDirective: DirectiveSpec = { + name: 'div', + options: { + label: { + type: String, + alias: ['name'], + }, + class: { + type: String, + }, + }, + body: { + type: 'myst', + required: true, + }, + run(data: DirectiveData): GenericNode[] { + const { label, identifier } = normalizeLabel(data.options?.label as string | undefined) || {}; + const div: GenericNode = { + type: 'div', + children: data.body as unknown as (FlowContent | ListContent | PhrasingContent)[], + class: data.options?.class as string | undefined, + label, + identifier, + }; + return [div]; + }, +}; diff --git a/packages/myst-directives/src/index.ts b/packages/myst-directives/src/index.ts index 2a855bb84..77e9e9d5d 100644 --- a/packages/myst-directives/src/index.ts +++ b/packages/myst-directives/src/index.ts @@ -17,6 +17,7 @@ import { mystdemoDirective } from './mystdemo.js'; import { outputDirective } from './output.js'; import { blockquoteDirective } from './blockquote.js'; import { rawDirective } from './raw.js'; +import { divDirective } from './div.js'; export const defaultDirectives = [ admonitionDirective, @@ -41,6 +42,7 @@ export const defaultDirectives = [ mystdemoDirective, outputDirective, rawDirective, + divDirective, ]; export { admonitionDirective } from './admonition.js'; @@ -61,3 +63,4 @@ export { mystdemoDirective } from './mystdemo.js'; export { outputDirective } from './output.js'; export { blockquoteDirective } from './blockquote.js'; export { rawDirective } from './raw.js'; +export { divDirective } from './div.js';