Skip to content

Commit

Permalink
fix shiki css class replace logic in md and mdx integrations (#5837)
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppelt authored Jan 12, 2023
1 parent c53b1fc commit 12f65a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/giant-chefs-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/mdx': patch
'@astrojs/markdown-remark': patch
---

fix shiki css class replace logic
2 changes: 1 addition & 1 deletion packages/integrations/mdx/src/remark-shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
// <span class="line"

// Replace "shiki" class naming with "astro".
html = html.replace('<pre class="shiki"', `<pre class="astro-code"`);
html = html.replace(/<pre class="(.*?)shiki(.*?)"/, `<pre class="$1astro-code$2"`);
// Add "user-select: none;" for "+"/"-" diff symbols
if (node.lang === 'diff') {
html = html.replace(
Expand Down
4 changes: 2 additions & 2 deletions packages/markdown/remark/src/remark-shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const remarkShiki = async (

// Replace "shiki" class naming with "astro" and add "is:raw".
html = html.replace(
'<pre class="shiki"',
`<pre is:raw class="astro-code${scopedClassName ? ' ' + scopedClassName : ''}"`
/<pre class="(.*?)shiki(.*?)"/,
`<pre is:raw class="$1astro-code$2${scopedClassName ? ' ' + scopedClassName : ''}"`
);
// Add "user-select: none;" for "+"/"-" diff symbols
if (node.lang === 'diff') {
Expand Down

0 comments on commit 12f65a4

Please sign in to comment.