Skip to content
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
6 changes: 6 additions & 0 deletions .changeset/grumpy-bats-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/mdx': patch
'@astrojs/markdown-satteri': patch
---

Fixes Sätteri processor option types to accept all plugin entries supported by Sätteri v0.10.3.
9 changes: 4 additions & 5 deletions packages/integrations/mdx/src/satteri/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
mdxToJs,
type HastNode,
type HastPluginDefinition,
type HastPluginEntry,
type MdastPluginDefinition,
type MdastPluginEntry,
type MdxCompileOptions,
} from 'satteri';
import { ASTRO_IMAGE_IMPORT, USES_ASTRO_IMAGE_FLAG } from '../image-constants.js';
Expand Down Expand Up @@ -90,12 +92,9 @@ export function createMdxProcessor(
typeof syntaxHighlight === 'object' ? syntaxHighlight.excludeLangs : undefined;

// Collect last so image-URL rewrites by user plugins are captured.
const allMdastPlugins: MdastPluginDefinition[] = [
...satteriOptions.mdastPlugins,
collectImages,
];
const allMdastPlugins: MdastPluginEntry[] = [...satteriOptions.mdastPlugins, collectImages];

const hastPlugins: HastPluginDefinition[] = [];
const hastPlugins: HastPluginEntry[] = [];
if (highlightFn) {
hastPlugins.push(satteriHighlightPlugin(highlightFn, excludeLangs));
}
Expand Down
16 changes: 11 additions & 5 deletions packages/markdown/satteri/src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import type { MarkdownProcessor } from '@astrojs/internal-helpers/markdown';
import type { Features, HastPluginDefinition, MdastPluginDefinition } from 'satteri';
import type {
Features,
HastPluginEntry,
HastPluginList,
MdastPluginEntry,
MdastPluginList,
} from 'satteri';
import { createSatteriMarkdownProcessor } from './satteri-processor.js';

export interface SatteriProcessorOptions {
mdastPlugins?: MdastPluginDefinition[];
hastPlugins?: HastPluginDefinition[];
mdastPlugins?: MdastPluginList;
hastPlugins?: HastPluginList;
features?: Features;
}

Expand All @@ -13,8 +19,8 @@ export interface SatteriProcessorOptions {
* (the factory normalises absent inputs into defaults).
*/
export interface SatteriResolvedOptions {
mdastPlugins: MdastPluginDefinition[];
hastPlugins: HastPluginDefinition[];
mdastPlugins: MdastPluginEntry[];
hastPlugins: HastPluginEntry[];
features: Features;
}

Expand Down
19 changes: 14 additions & 5 deletions packages/markdown/satteri/src/satteri-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ import {
syntaxHighlightDefaults,
} from '@astrojs/internal-helpers/markdown';
import Slugger from 'github-slugger';
import type { Features, HastNode, HastPluginDefinition, MdastPluginDefinition } from 'satteri';
import type {
Features,
HastNode,
HastPluginDefinition,
HastPluginEntry,
HastPluginList,
MdastPluginDefinition,
MdastPluginEntry,
MdastPluginList,
} from 'satteri';
import { createShikiHighlighter } from '@astrojs/internal-helpers/shiki';
import type {
AstroMarkdownOptions,
Expand Down Expand Up @@ -206,8 +215,8 @@ export function createHighlightPlugin(
}

export interface SatteriMarkdownProcessorOptions extends AstroMarkdownOptions {
mdastPlugins?: MdastPluginDefinition[];
hastPlugins?: HastPluginDefinition[];
mdastPlugins?: MdastPluginList;
hastPlugins?: HastPluginList;
features?: Features;
}

Expand Down Expand Up @@ -291,12 +300,12 @@ export async function createSatteriMarkdownProcessor(
};

// Collect last so image-URL rewrites by user plugins are captured.
const allMdastPlugins: MdastPluginDefinition[] = [
const allMdastPlugins: MdastPluginEntry[] = [
...userMdastPlugins,
createCollectImagesPlugin(opts?.image),
];

const hastPlugins: HastPluginDefinition[] = [];
const hastPlugins: HastPluginEntry[] = [];
if (highlightFn) {
hastPlugins.push(createHighlightPlugin(highlightFn, syntaxHighlightExcludeLangs));
}
Expand Down
23 changes: 22 additions & 1 deletion packages/markdown/satteri/test/markdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import type { HastPluginDefinition, MdastPluginDefinition } from 'satteri';
import { createSatteriMarkdownProcessor, satteriHeadingIdsPlugin } from '../dist/index.js';
import { createSatteriMarkdownProcessor, satteri, satteriHeadingIdsPlugin } from '../dist/index.js';

describe('satteri markdown', () => {
it('renders basic markdown', async () => {
Expand Down Expand Up @@ -136,4 +136,25 @@ describe('satteri markdown', () => {
assert.equal(metadata.frontmatter.title, 'hello');
assert.equal(metadata.frontmatter.injected, 'HELLO');
});

it('accepts conditional plugin factories', async () => {
const mdUppercasePlugin: MdastPluginDefinition = {
name: 'mdx-uppercase',
text(node, ctx) {
ctx.setProperty(node, 'value', node.value.toUpperCase());
},
};

const satteriProcessor = satteri({
mdastPlugins: [(ctx) => (ctx.sourceFormat === 'markdown' ? [mdUppercasePlugin] : null)],
});

const processor = await createSatteriMarkdownProcessor({
mdastPlugins: satteriProcessor.options.mdastPlugins,
});

const { code } = await processor.render('Hello');

assert.match(code, /<p>HELLO<\/p>/);
});
});
Loading