@@ -8,7 +8,7 @@ function normalize(s) {
8
8
return s . replace ( / \\ / g, path . win32 . sep . repeat ( 2 ) ) ;
9
9
}
10
10
11
- async function gatherPartials ( ast , schemaDir , tokenizer ) {
11
+ async function gatherPartials ( ast , schemaDir , tokenizer , parseOptions ) {
12
12
let partials = { } ;
13
13
14
14
for ( const node of ast . walk ( ) ) {
@@ -26,11 +26,17 @@ async function gatherPartials(ast, schemaDir, tokenizer) {
26
26
27
27
if ( content ) {
28
28
const tokens = tokenizer . tokenize ( content ) ;
29
- const ast = Markdoc . parse ( tokens ) ;
29
+ const ast = Markdoc . parse ( tokens , parseOptions ) ;
30
30
partials = {
31
31
...partials ,
32
32
[ file ] : content ,
33
- ...( await gatherPartials . call ( this , ast , schemaDir , tokenizer ) ) ,
33
+ ...( await gatherPartials . call (
34
+ this ,
35
+ ast ,
36
+ schemaDir ,
37
+ tokenizer ,
38
+ parseOptions
39
+ ) ) ,
34
40
} ;
35
41
}
36
42
}
@@ -59,10 +65,11 @@ async function load(source) {
59
65
} = this . getOptions ( ) || { } ;
60
66
61
67
const tokenizer = new Markdoc . Tokenizer ( options ) ;
68
+ const parseOptions = { slots} ;
62
69
63
70
const schemaDir = path . resolve ( dir , schemaPath || DEFAULT_SCHEMA_PATH ) ;
64
71
const tokens = tokenizer . tokenize ( source ) ;
65
- const ast = Markdoc . parse ( tokens , { slots } ) ;
72
+ const ast = Markdoc . parse ( tokens , parseOptions ) ;
66
73
67
74
// Grabs the path of the file relative to the `/{app,pages}` directory
68
75
// to pass into the app props later.
@@ -75,7 +82,8 @@ async function load(source) {
75
82
this ,
76
83
ast ,
77
84
path . resolve ( schemaDir , 'partials' ) ,
78
- tokenizer
85
+ tokenizer ,
86
+ parseOptions
79
87
) ;
80
88
81
89
// IDEA: consider making this an option per-page
@@ -120,13 +128,10 @@ async function load(source) {
120
128
121
129
this . addContextDependency ( schemaDir ) ;
122
130
123
- const nextjsExports = [
124
- 'metadata' ,
125
- 'revalidate' ,
126
- ]
131
+ const nextjsExports = [ 'metadata' , 'revalidate' ] ;
127
132
const nextjsExportsCode = nextjsExports
128
133
. map ( ( name ) => `export const ${ name } = frontmatter.nextjs?.${ name } ;` )
129
- . join ( '\n' )
134
+ . join ( '\n' ) ;
130
135
131
136
const result = `import React from 'react';
132
137
import yaml from 'js-yaml';
@@ -152,7 +157,8 @@ const tokenizer = new Markdoc.Tokenizer(${
152
157
const source = ${ JSON . stringify ( source ) } ;
153
158
const filepath = ${ JSON . stringify ( filepath ) } ;
154
159
const tokens = tokenizer.tokenize(source);
155
- const ast = Markdoc.parse(tokens, {slots: ${ JSON . stringify ( slots ) } });
160
+ const parseOptions = ${ JSON . stringify ( parseOptions ) } ;
161
+ const ast = Markdoc.parse(tokens, parseOptions);
156
162
157
163
/**
158
164
* Like the AST, frontmatter won't change at runtime, so it is loaded at file root.
@@ -170,7 +176,7 @@ async function getMarkdocData(context = {}) {
170
176
// Ensure Node.transformChildren is available
171
177
Object.keys(partials).forEach((key) => {
172
178
const tokens = tokenizer.tokenize(partials[key]);
173
- partials[key] = Markdoc.parse(tokens);
179
+ partials[key] = Markdoc.parse(tokens, parseOptions );
174
180
});
175
181
176
182
const cfg = {
0 commit comments