Skip to content

Commit 436a103

Browse files
committed
✅ Add test for heading opt-in
1 parent 3e4cfe9 commit 436a103

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

test/__snapshots__/options.test.ts.snap

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,28 @@ exports[`File extensions > works when passed the default extension 1`] = `
4949
<article><h1>This is some basic Markdoc</h1><p>With a paragraph.</p><p>Some text <strong>in bold</strong> and <em>in italic</em>.</p><p>And a <a href="https://example.com">link</a>.</p><h2>More fancy stuff</h2><p>Some <code>&lt;p&gt;</code> inline code.</p><p>And a code block:</p><pre data-language="javascript"><code>&lcub;&lcub;% test %&rcub;&rcub;</code></pre><p>And even a table with a nested list:</p><table><thead><tr><th>Table header 1</th><th>Table header 2</th></tr></thead><tbody><tr><td><ul><li>Row 1 Cell 1 Item 1</li><li>Row 1 Cell 1 Item 2</li></ul></td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 cell 2</td></tr></tbody></table></article>"
5050
`;
5151

52+
exports[`Headings > adds IDs and exports headings when passed as an option 1`] = `
53+
"<script module>
54+
export const slug = "test";
55+
export const headings = [{"level":1,"title":"This is some basic Markdoc","id":"this-is-some-basic-markdoc"},{"level":2,"title":"More fancy stuff","id":"more-fancy-stuff"}];
56+
</script>
57+
<article><h1 id="this-is-some-basic-markdoc">This is some basic Markdoc</h1><p>With a paragraph.</p><p>Some text <strong>in bold</strong> and <em>in italic</em>.</p><p>And a <a href="https://example.com">link</a>.</p><h2 id="more-fancy-stuff">More fancy stuff</h2><p>Some <code>&lt;p&gt;</code> inline code.</p><p>And a code block:</p><pre data-language="javascript"><code>&lcub;&lcub;% test %&rcub;&rcub;</code></pre><p>And even a table with a nested list:</p><table><thead><tr><th>Table header 1</th><th>Table header 2</th></tr></thead><tbody><tr><td><ul><li>Row 1 Cell 1 Item 1</li><li>Row 1 Cell 1 Item 2</li></ul></td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 cell 2</td></tr></tbody></table></article>"
58+
`;
59+
60+
exports[`Headings > doesn't add IDs or export headings by default 1`] = `
61+
"<script module>
62+
export const slug = "test";
63+
</script>
64+
<article><h1>This is some basic Markdoc</h1><p>With a paragraph.</p><p>Some text <strong>in bold</strong> and <em>in italic</em>.</p><p>And a <a href="https://example.com">link</a>.</p><h2>More fancy stuff</h2><p>Some <code>&lt;p&gt;</code> inline code.</p><p>And a code block:</p><pre data-language="javascript"><code>&lcub;&lcub;% test %&rcub;&rcub;</code></pre><p>And even a table with a nested list:</p><table><thead><tr><th>Table header 1</th><th>Table header 2</th></tr></thead><tbody><tr><td><ul><li>Row 1 Cell 1 Item 1</li><li>Row 1 Cell 1 Item 2</li></ul></td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 cell 2</td></tr></tbody></table></article>"
65+
`;
66+
67+
exports[`Headings > doesn't add IDs or export headings when passed false 1`] = `
68+
"<script module>
69+
export const slug = "test";
70+
</script>
71+
<article><h1>This is some basic Markdoc</h1><p>With a paragraph.</p><p>Some text <strong>in bold</strong> and <em>in italic</em>.</p><p>And a <a href="https://example.com">link</a>.</p><h2>More fancy stuff</h2><p>Some <code>&lt;p&gt;</code> inline code.</p><p>And a code block:</p><pre data-language="javascript"><code>&lcub;&lcub;% test %&rcub;&rcub;</code></pre><p>And even a table with a nested list:</p><table><thead><tr><th>Table header 1</th><th>Table header 2</th></tr></thead><tbody><tr><td><ul><li>Row 1 Cell 1 Item 1</li><li>Row 1 Cell 1 Item 2</li></ul></td><td>Row 1 Cell 2</td></tr><tr><td>Row 2 Cell 1</td><td>Row 2 cell 2</td></tr></tbody></table></article>"
72+
`;
73+
5274
exports[`Layout > properly puts the parsed file in a layout when passed as an option 1`] = `
5375
"<script module>
5476
export const slug = "test";

test/options.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,39 @@ describe("File extensions", () => {
119119
});
120120
});
121121

122+
describe("Headings", () => {
123+
it("doesn't add IDs or export headings by default", async () => {
124+
const result = (await markdocPreprocess().markup!({
125+
content: basicMarkdoc,
126+
filename: "test.md",
127+
})) as Processed;
128+
129+
expect(result.code).toMatchSnapshot();
130+
});
131+
132+
it("adds IDs and exports headings when passed as an option", async () => {
133+
const result = (await markdocPreprocess({
134+
headingIds: true,
135+
} as Options).markup!({
136+
content: basicMarkdoc,
137+
filename: "test.md",
138+
})) as Processed;
139+
140+
expect(result.code).toMatchSnapshot();
141+
});
142+
143+
it("doesn't add IDs or export headings when passed false", async () => {
144+
const result = (await markdocPreprocess({
145+
headingIds: false,
146+
} as Options).markup!({
147+
content: basicMarkdoc,
148+
filename: "test.md",
149+
})) as Processed;
150+
151+
expect(result.code).toMatchSnapshot();
152+
});
153+
});
154+
122155
describe("Layout", () => {
123156
it("properly puts the parsed file in a layout when passed as an option", async () => {
124157
const layoutOptions = {

0 commit comments

Comments
 (0)