Skip to content

Commit

Permalink
feat: add aside directive
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Mar 20, 2024
1 parent e79c929 commit b688080
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-comics-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"myst-directives": minor
---

Add `aside` directive
2 changes: 1 addition & 1 deletion docs/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ description: Code and code-blocks can be used to show programming languages.
:::{myst:directive} list-table
:::

:::{myst:directive} margin
:::{myst:directive} aside
:::

:::{myst:directive} math
Expand Down
21 changes: 21 additions & 0 deletions packages/myst-directives/src/aside.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { DirectiveSpec, DirectiveData, GenericNode } from 'myst-common';
import type { Aside } from 'myst-spec-ext';
import type { FlowContent, ListContent, PhrasingContent } from 'myst-spec';

export const asideDirective: DirectiveSpec = {
name: 'aside',
alias: ['margin', 'sidebar'],
body: {
type: 'myst',
required: true,
},
run(data: DirectiveData): GenericNode[] {
const aside: Aside = {
type: 'aside',
kind:
data.name == 'aside' || data.name == 'margin' ? undefined : (data.name as Aside['kind']),
children: data.body as (FlowContent | ListContent | PhrasingContent)[],
};
return [aside];
},
};
6 changes: 3 additions & 3 deletions packages/myst-directives/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { iframeDirective } from './iframe.js';
import { imageDirective } from './image.js';
import { includeDirective } from './include.js';
import { tableDirective, listTableDirective } from './table.js';
import { marginDirective } from './margin.js';
import { asideDirective } from './aside.js';
import { glossaryDirective } from './glossary.js';
import { mathDirective } from './math.js';
import { mdastDirective } from './mdast.js';
Expand All @@ -32,7 +32,7 @@ export const defaultDirectives = [
includeDirective,
tableDirective,
listTableDirective,
marginDirective,
asideDirective,
glossaryDirective,
mathDirective,
mdastDirective,
Expand All @@ -52,7 +52,7 @@ export { iframeDirective } from './iframe.js';
export { imageDirective } from './image.js';
export { includeDirective } from './include.js';
export { listTableDirective, tableDirective } from './table.js';
export { marginDirective } from './margin.js';
export { asideDirective } from './aside.js';
export { mathDirective } from './math.js';
export { mdastDirective } from './mdast.js';
export { mermaidDirective } from './mermaid.js';
Expand Down
17 changes: 0 additions & 17 deletions packages/myst-directives/src/margin.ts

This file was deleted.

7 changes: 7 additions & 0 deletions packages/myst-spec-ext/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,10 @@ export type Output = Node & {
visibility?: Visibility;
children?: (FlowContent | ListContent | PhrasingContent)[];
};


export type Aside = Node & {
type: 'aside';
kind?: 'sidebar'
children?: (FlowContent | ListContent | PhrasingContent)[];
}

0 comments on commit b688080

Please sign in to comment.