@@ -3,18 +3,18 @@ import type {
33 DirectiveData ,
44 DirectiveSpec ,
55 DirectiveContext ,
6- ParseTypes ,
76 GenericParent ,
87} from 'myst-common' ;
98import { RuleId , fileError , fileWarn } from 'myst-common' ;
109import { selectAll } from 'unist-util-select' ;
1110import type { VFile } from 'vfile' ;
12- import { contentFromNode } from './utils.js' ;
11+ import { contentFromNode , markChildrenAsProcessed } from './utils.js' ;
1312import type { Directive } from 'myst-spec' ;
1413import { parseOptions } from './inlineAttributes.js' ;
1514
1615type MystDirectiveNode = GenericNode & {
1716 name : string ;
17+ processed ?: false ;
1818} ;
1919/**
2020 * Apply directive `run()` methods to build directive ASTs.
@@ -47,12 +47,20 @@ export function applyDirectives(
4747 }
4848 } ) ;
4949 } ) ;
50- // Find all raw directive nodes
50+ // Find all raw directive nodes, these will have a `processed` attribute set to `false`
5151 const nodes = selectAll ( 'mystDirective[processed=false]' , tree ) as MystDirectiveNode [ ] ;
5252 nodes . forEach ( ( node ) => {
53- delete node . processed ; // Indicate that the directive has been processed
5453 const { name } = node ;
5554 const spec = specLookup [ name ] ;
55+ if ( spec && spec . body && spec . body . type !== 'myst' ) {
56+ // Do not process the children of the directive that is not a myst block
57+ // Doing so would raise errors (for example, if the parent directive is a code block)
58+ // See https://github.com/jupyter-book/mystmd/issues/2530
59+ markChildrenAsProcessed ( node ) ;
60+ }
61+ // Re-check if the directive has been processed
62+ if ( node . processed !== false ) return ;
63+ delete node . processed ; // Indicate that the directive has been processed
5664 if ( ! spec ) {
5765 fileError ( vfile , `unknown directive: ${ name } ` , { node, ruleId : RuleId . directiveKnown } ) ;
5866 // We probably want to do something better than just delete the children and
0 commit comments