Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support slots #31

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 76 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ async function load(source) {
dir, // Root directory from Next.js (contains next.config.js)
mode = 'static',
schemaPath = DEFAULT_SCHEMA_PATH,
tokenizerOptions = {allowComments: true},
tokenizerOptions: {slots = false, ...tokenizerOptions} = {
allowComments: true,
},
} = this.getOptions() || {};

const tokenizer = new Markdoc.Tokenizer(tokenizerOptions);

const schemaDir = path.resolve(dir, schemaPath || DEFAULT_SCHEMA_PATH);
const tokens = tokenizer.tokenize(source);
const ast = Markdoc.parse(tokens);
const ast = Markdoc.parse(tokens, {slots});

// Grabs the path of the file relative to the `/pages` directory
// to pass into the app props later.
Expand Down Expand Up @@ -140,7 +142,7 @@ const tokenizer = new Markdoc.Tokenizer(${
const source = ${JSON.stringify(source)};
const filepath = ${JSON.stringify(filepath)};
const tokens = tokenizer.tokenize(source);
const ast = Markdoc.parse(tokens);
const ast = Markdoc.parse(tokens, {slots: ${JSON.stringify(slots)}});

/**
* Like the AST, frontmatter won't change at runtime, so it is loaded at file root.
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const tokenizer = new Markdoc.Tokenizer({\\"allowComments\\":true});
const source = \\"---\\\\ntitle: Custom title\\\\n---\\\\n\\\\n# {% $markdoc.frontmatter.title %}\\\\n\\\\n{% tag /%}\\\\n\\";
const filepath = \\"/test/index.md\\";
const tokens = tokenizer.tokenize(source);
const ast = Markdoc.parse(tokens);
const ast = Markdoc.parse(tokens, {slots: false});

/**
* Like the AST, frontmatter won't change at runtime, so it is loaded at file root.
Expand Down Expand Up @@ -111,7 +111,7 @@ const tokenizer = new Markdoc.Tokenizer({\\"allowComments\\":true});
const source = \\"---\\\\ntitle: Custom title\\\\n---\\\\n\\\\n# {% $markdoc.frontmatter.title %}\\\\n\\\\n{% tag /%}\\\\n\\";
const filepath = \\"/test/index.md\\";
const tokens = tokenizer.tokenize(source);
const ast = Markdoc.parse(tokens);
const ast = Markdoc.parse(tokens, {slots: false});

/**
* Like the AST, frontmatter won't change at runtime, so it is loaded at file root.
Expand Down
Loading