Skip to content

Commit ee3e6e3

Browse files
authored
support slots (#31)
1 parent 4a27eb1 commit ee3e6e3

File tree

3 files changed

+83
-13
lines changed

3 files changed

+83
-13
lines changed

package-lock.json

Lines changed: 76 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/loader.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ async function load(source) {
5252
dir, // Root directory from Next.js (contains next.config.js)
5353
mode = 'static',
5454
schemaPath = DEFAULT_SCHEMA_PATH,
55-
tokenizerOptions = {allowComments: true},
55+
tokenizerOptions: {slots = false, ...tokenizerOptions} = {
56+
allowComments: true,
57+
},
5658
} = this.getOptions() || {};
5759

5860
const tokenizer = new Markdoc.Tokenizer(tokenizerOptions);
5961

6062
const schemaDir = path.resolve(dir, schemaPath || DEFAULT_SCHEMA_PATH);
6163
const tokens = tokenizer.tokenize(source);
62-
const ast = Markdoc.parse(tokens);
64+
const ast = Markdoc.parse(tokens, {slots});
6365

6466
// Grabs the path of the file relative to the `/pages` directory
6567
// to pass into the app props later.
@@ -140,7 +142,7 @@ const tokenizer = new Markdoc.Tokenizer(${
140142
const source = ${JSON.stringify(source)};
141143
const filepath = ${JSON.stringify(filepath)};
142144
const tokens = tokenizer.tokenize(source);
143-
const ast = Markdoc.parse(tokens);
145+
const ast = Markdoc.parse(tokens, {slots: ${JSON.stringify(slots)}});
144146
145147
/**
146148
* Like the AST, frontmatter won't change at runtime, so it is loaded at file root.

tests/__snapshots__/index.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const tokenizer = new Markdoc.Tokenizer({\\"allowComments\\":true});
2121
const source = \\"---\\\\ntitle: Custom title\\\\n---\\\\n\\\\n# {% $markdoc.frontmatter.title %}\\\\n\\\\n{% tag /%}\\\\n\\";
2222
const filepath = \\"/test/index.md\\";
2323
const tokens = tokenizer.tokenize(source);
24-
const ast = Markdoc.parse(tokens);
24+
const ast = Markdoc.parse(tokens, {slots: false});
2525
2626
/**
2727
* Like the AST, frontmatter won't change at runtime, so it is loaded at file root.
@@ -111,7 +111,7 @@ const tokenizer = new Markdoc.Tokenizer({\\"allowComments\\":true});
111111
const source = \\"---\\\\ntitle: Custom title\\\\n---\\\\n\\\\n# {% $markdoc.frontmatter.title %}\\\\n\\\\n{% tag /%}\\\\n\\";
112112
const filepath = \\"/test/index.md\\";
113113
const tokens = tokenizer.tokenize(source);
114-
const ast = Markdoc.parse(tokens);
114+
const ast = Markdoc.parse(tokens, {slots: false});
115115
116116
/**
117117
* Like the AST, frontmatter won't change at runtime, so it is loaded at file root.

0 commit comments

Comments
 (0)