11
2- import type { Parent , Node , Yaml , ListItem , Text , Heading } from 'mdast' ;
2+ import type { Parent , Node , Yaml , ListItem , Text , Heading , Code } from 'mdast' ;
33import type { TagMap , Task , Worklog , ParseContext , ParseFileContext } from './types.js' ;
44
55import { readdir , readFile , stat } from 'node:fs/promises' ;
@@ -90,6 +90,16 @@ const parseYamlNode = (node: Yaml, ctx: ParseFileContext, item: Task | Worklog |
9090 }
9191} ;
9292
93+ const parseCodeNode = ( node : Code , ctx : ParseFileContext , item : Task | Worklog | null ) => {
94+ if ( node . lang === 'taskparser' && ctx . heading ) {
95+ try {
96+ extractTagsFromYaml ( node . value , ctx . heading . tags ) ;
97+ } catch ( err ) {
98+ throw new Error ( `could not parse YAML code block in file ${ ctx . file } : ${ ( err as Error ) . message } ` ) ;
99+ }
100+ }
101+ } ;
102+
93103const parseNode = ( node : Node , ctx : ParseFileContext , item : Task | Worklog | null ) => {
94104 switch ( node . type ) {
95105 case 'yaml' :
@@ -101,6 +111,9 @@ const parseNode = (node: Node, ctx: ParseFileContext, item: Task | Worklog | nul
101111 case 'heading' :
102112 parseHeadingNode ( node as Heading , ctx , item ) ;
103113 break ;
114+ case 'code' :
115+ parseCodeNode ( node as Code , ctx , item ) ;
116+ break ;
104117 default :
105118 if ( 'children' in node ) {
106119 parseParentNode ( node as Parent , ctx , item ) ;
0 commit comments