Fixes: Shiki syntax highlighting adds is:raw attribute to the HTML output (#8715)

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
Chris 2023-10-04 12:23:58 +02:00 committed by GitHub
parent 71618f4074
commit 21f4826576
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/markdown-remark': patch
---
Remove `is:raw` from remark Shiki plugin

View file

@ -76,8 +76,8 @@ export function remarkShiki({
// It would become this before hitting our regexes: // It would become this before hitting our regexes:
// &lt;span class=&quot;line&quot; // &lt;span class=&quot;line&quot;
// Replace "shiki" class naming with "astro" and add "is:raw". // Replace "shiki" class naming with "astro".
html = html.replace(/<pre class="(.*?)shiki(.*?)"/, `<pre is:raw class="$1astro-code$2"`); html = html.replace(/<pre class="(.*?)shiki(.*?)"/, `<pre class="$1astro-code$2"`);
// Add "user-select: none;" for "+"/"-" diff symbols // Add "user-select: none;" for "+"/"-" diff symbols
if (node.lang === 'diff') { if (node.lang === 'diff') {
html = html.replace( html = html.replace(

View file

@ -0,0 +1,16 @@
import { createMarkdownProcessor } from '../dist/index.js';
import chai from 'chai';
describe('shiki syntax highlighting', async () => {
const processor = await createMarkdownProcessor();
it('does not add is:raw to the output', async () => {
const {
code,
} = await processor.render('```\ntest\n```');
chai
.expect(code)
.not.to.contain("is:raw");
});
});