Skip to content

Commit

Permalink
🐛 Identifiers added to directive child (#438)
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 authored Jun 21, 2023
1 parent 9e3c04c commit 714b594
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/seven-seas-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'myst-transforms': patch
'myst-cli': patch
---

Propogate identifiers from mystRoles and mystDirectives to their children when lifting
12 changes: 12 additions & 0 deletions packages/myst-transforms/src/liftMystDirectivesAndRoles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Plugin } from 'unified';
import type { Root } from 'mdast';
import type { GenericNode } from 'myst-common';
import { liftChildren } from 'myst-common';
import { selectAll } from 'unist-util-select';

/**
* Lift directives and roles and remove them from the tree
Expand All @@ -10,6 +12,16 @@ import { liftChildren } from 'myst-common';
* @param tree The tree which is modified in place.
*/
export function liftMystDirectivesAndRolesTransform(tree: Root) {
const directives = selectAll('mystDirective,mystRole', tree) as GenericNode[];
directives.forEach((n) => {
const child = n.children?.[0];
if (!child) return;
if (n.identifier && !child.identifier) {
child.identifier = n.identifier;
child.label = n.label;
child.html_id = n.html_id;
}
});
liftChildren(tree, 'mystDirective');
liftChildren(tree, 'mystRole');
}
Expand Down

0 comments on commit 714b594

Please sign in to comment.