Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧱 Add div directive #1140

Merged
merged 1 commit into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Loading