chore: changed data-astro-raw
to is:raw
(#2706)
* chore: changed `data-astro-raw` to `is:raw` * changesets
This commit is contained in:
parent
519a5d84d1
commit
b2c37385f9
5 changed files with 12 additions and 6 deletions
6
.changeset/thirty-lobsters-ring.md
Normal file
6
.changeset/thirty-lobsters-ring.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
'@astrojs/markdown-remark': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Changed `data-astro-raw` to `is:raw` internally
|
|
@ -36,8 +36,8 @@ const { code, lang = 'plaintext', theme = 'github-dark', wrap = false } = Astro.
|
||||||
|
|
||||||
/** Replace the shiki class name with a custom astro class name. */
|
/** Replace the shiki class name with a custom astro class name. */
|
||||||
function repairShikiTheme(html: string): string {
|
function repairShikiTheme(html: string): string {
|
||||||
// Replace "shiki" class naming with "astro" and add "data-astro-raw".
|
// Replace "shiki" class naming with "astro" and add "is:raw".
|
||||||
html = html.replace('<pre class="shiki"', '<pre data-astro-raw class="astro-code"');
|
html = html.replace('<pre class="shiki"', '<pre is:raw class="astro-code"');
|
||||||
// Replace "shiki" css variable naming with "astro".
|
// Replace "shiki" css variable naming with "astro".
|
||||||
html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
|
html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
|
||||||
// Handle code wrapping
|
// Handle code wrapping
|
||||||
|
|
|
@ -4,7 +4,7 @@ export default function rehypeEscape(): any {
|
||||||
return function (node: any): any {
|
return function (node: any): any {
|
||||||
return visit(node, 'element', (el) => {
|
return visit(node, 'element', (el) => {
|
||||||
if (el.tagName === 'code' || el.tagName === 'pre') {
|
if (el.tagName === 'code' || el.tagName === 'pre') {
|
||||||
el.properties['data-astro-raw'] = true;
|
el.properties['is:raw'] = true;
|
||||||
}
|
}
|
||||||
return el;
|
return el;
|
||||||
});
|
});
|
||||||
|
|
|
@ -56,7 +56,7 @@ function transformer(className: MaybeString) {
|
||||||
if (className) {
|
if (className) {
|
||||||
classes.push(className);
|
classes.push(className);
|
||||||
}
|
}
|
||||||
node.value = `<pre class="${classes.join(' ')}"><code data-astro-raw class="${classLanguage}">${html}</code></pre>`;
|
node.value = `<pre class="${classes.join(' ')}"><code is:raw class="${classLanguage}">${html}</code></pre>`;
|
||||||
return node;
|
return node;
|
||||||
};
|
};
|
||||||
return visit(tree, 'code', visitor);
|
return visit(tree, 'code', visitor);
|
||||||
|
|
|
@ -50,8 +50,8 @@ const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }:
|
||||||
visit(tree, 'code', (node) => {
|
visit(tree, 'code', (node) => {
|
||||||
let html = highlighter!.codeToHtml(node.value, { lang: node.lang ?? 'plaintext' });
|
let html = highlighter!.codeToHtml(node.value, { lang: node.lang ?? 'plaintext' });
|
||||||
|
|
||||||
// Replace "shiki" class naming with "astro" and add "data-astro-raw".
|
// Replace "shiki" class naming with "astro" and add "is:raw".
|
||||||
html = html.replace('<pre class="shiki"', '<pre data-astro-raw class="astro-code"');
|
html = html.replace('<pre class="shiki"', '<pre is:raw class="astro-code"');
|
||||||
// Replace "shiki" css variable naming with "astro".
|
// Replace "shiki" css variable naming with "astro".
|
||||||
html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
|
html = html.replace(/style="(background-)?color: var\(--shiki-/g, 'style="$1color: var(--astro-code-');
|
||||||
// Handle code wrapping
|
// Handle code wrapping
|
||||||
|
|
Loading…
Reference in a new issue