fix(#4246): fix Prism indentation and class (#4251)

Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
Nate Moore 2022-08-11 10:59:48 -05:00 committed by GitHub
parent 51847a276f
commit 1f0dd31d92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View file

@ -0,0 +1,7 @@
---
'@astrojs/prism': patch
---
Fix `<Prism />` component indentation
Prefer `class="language-plaintext"` to `class="language-undefined"`

View file

@ -11,8 +11,4 @@ const { class: className, lang, code } = Astro.props as Props;
const { classLanguage, html } = runHighlighterWithAstro(lang, code);
---
<pre
class={[className, classLanguage].join(
' '
)}> <code class={classLanguage}><Fragment set:html={html} /></code>
</pre>
<pre class={[className, classLanguage].filter(Boolean).join(' ')}><code class={classLanguage} set:html={html} /></pre>

View file

@ -5,12 +5,10 @@ import { addAstro } from './plugin.js';
const languageMap = new Map([['ts', 'typescript']]);
export function runHighlighterWithAstro(lang: string | undefined, code: string) {
let classLanguage = `language-${lang}`;
if (!lang) {
lang = 'plaintext';
}
let classLanguage = `language-${lang}`;
const ensureLoaded = (language: string) => {
if (language && !Prism.languages[language]) {
loadLanguages([language]);