From a3327ffbe6373228339824684eaa6f340a20a32e Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Wed, 12 Mar 2025 21:58:33 +0800 Subject: feat(markdown): add `excludeLangs` configuration to syntax highlighting (#13311) * demonstrative implementation of excludeLangs * add tests * add changset * clean up exclude languages into a const * update changeset to include astro minor * update jsdoc * first cut in moving the config into markdown settings * format code * update test * update changset * remove old incorrect doc change * make test stronger yet simplifying it * refactor tests * refactor logic for readability * add syntax highlight defaults * improve changset doc * add more documentation * add more defaults to each part of schema * attempt to fix js doc parsing * attempt to fix test * Extremely draft syntax of what docs should look like! * Update .changeset/large-dolphins-roll.md Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> * one pass on the documentation * remove unused import * gentle change * use different approach --------- Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com> Co-authored-by: Emanuele Stoppa --- packages/integrations/mdx/src/plugins.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'packages/integrations') diff --git a/packages/integrations/mdx/src/plugins.ts b/packages/integrations/mdx/src/plugins.ts index 77c76243c..e1640238f 100644 --- a/packages/integrations/mdx/src/plugins.ts +++ b/packages/integrations/mdx/src/plugins.ts @@ -65,12 +65,17 @@ function getRehypePlugins(mdxOptions: MdxOptions): PluggableList { [rehypeRaw, { passThrough: nodeTypes }], ]; - if (!isPerformanceBenchmark) { + const syntaxHighlight = mdxOptions.syntaxHighlight; + if (syntaxHighlight && !isPerformanceBenchmark) { + const syntaxHighlightType = + typeof syntaxHighlight === 'string' ? syntaxHighlight : syntaxHighlight?.type; + const excludeLangs = + typeof syntaxHighlight === 'object' ? syntaxHighlight?.excludeLangs : undefined; // Apply syntax highlighters after user plugins to match `markdown/remark` behavior - if (mdxOptions.syntaxHighlight === 'shiki') { - rehypePlugins.push([rehypeShiki, mdxOptions.shikiConfig]); - } else if (mdxOptions.syntaxHighlight === 'prism') { - rehypePlugins.push(rehypePrism); + if (syntaxHighlightType === 'shiki') { + rehypePlugins.push([rehypeShiki, mdxOptions.shikiConfig, excludeLangs]); + } else if (syntaxHighlightType === 'prism') { + rehypePlugins.push([rehypePrism, excludeLangs]); } } -- cgit v1.2.3