Skip to content

Commit

Permalink
馃П Add div directive (#1140)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Apr 19, 2024
1 parent 76903a7 commit 3241933
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-moose-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-directives": patch
---

Add div directive
31 changes: 31 additions & 0 deletions packages/myst-directives/src/div.ts
Original file line number Diff line number Diff line change
@@ -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];
},
};
3 changes: 3 additions & 0 deletions packages/myst-directives/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,6 +42,7 @@ export const defaultDirectives = [
mystdemoDirective,
outputDirective,
rawDirective,
divDirective,
];

export { admonitionDirective } from './admonition.js';
Expand All @@ -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';

0 comments on commit 3241933

Please sign in to comment.