|
1 | 1 | import assert from 'node:assert/strict'; |
2 | 2 | import { describe, it } from 'node:test'; |
3 | 3 | import type { HastPluginDefinition, MdastPluginDefinition } from 'satteri'; |
4 | | -import { createSatteriMarkdownProcessor, satteriHeadingIdsPlugin } from '../dist/index.js'; |
| 4 | +import { createSatteriMarkdownProcessor, satteri, satteriHeadingIdsPlugin } from '../dist/index.js'; |
5 | 5 |
|
6 | 6 | describe('satteri markdown', () => { |
7 | 7 | it('renders basic markdown', async () => { |
@@ -136,4 +136,25 @@ describe('satteri markdown', () => { |
136 | 136 | assert.equal(metadata.frontmatter.title, 'hello'); |
137 | 137 | assert.equal(metadata.frontmatter.injected, 'HELLO'); |
138 | 138 | }); |
| 139 | + |
| 140 | + it('accepts conditional plugin factories', async () => { |
| 141 | + const mdUppercasePlugin: MdastPluginDefinition = { |
| 142 | + name: 'mdx-uppercase', |
| 143 | + text(node, ctx) { |
| 144 | + ctx.setProperty(node, 'value', node.value.toUpperCase()); |
| 145 | + }, |
| 146 | + }; |
| 147 | + |
| 148 | + const satteriProcessor = satteri({ |
| 149 | + mdastPlugins: [(ctx) => (ctx.sourceFormat === 'markdown' ? [mdUppercasePlugin] : null)], |
| 150 | + }); |
| 151 | + |
| 152 | + const processor = await createSatteriMarkdownProcessor({ |
| 153 | + mdastPlugins: satteriProcessor.options.mdastPlugins, |
| 154 | + }); |
| 155 | + |
| 156 | + const { code } = await processor.render('Hello'); |
| 157 | + |
| 158 | + assert.match(code, /<p>HELLO<\/p>/); |
| 159 | + }); |
139 | 160 | }); |
0 commit comments