summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2022-08-11 10:59:48 -0500
committerGravatar GitHub <noreply@github.com> 2022-08-11 10:59:48 -0500
commit1f0dd31d9239b5e3dca99c88d021e7a9a3e2054d (patch)
tree0ee49181a2bf3f328b47ea8a9191929f37d875e0
parent51847a276f0fc0de60546eab5a4cb2afb1dc9ddc (diff)
downloadastro-1f0dd31d9239b5e3dca99c88d021e7a9a3e2054d.tar.gz
astro-1f0dd31d9239b5e3dca99c88d021e7a9a3e2054d.tar.zst
astro-1f0dd31d9239b5e3dca99c88d021e7a9a3e2054d.zip
fix(#4246): fix Prism indentation and class (#4251)
Co-authored-by: Nate Moore <nate@astro.build>
-rw-r--r--.changeset/old-pears-design.md7
-rw-r--r--packages/astro-prism/Prism.astro6
-rw-r--r--packages/astro-prism/src/highlighter.ts4
3 files changed, 9 insertions, 8 deletions
diff --git a/.changeset/old-pears-design.md b/.changeset/old-pears-design.md
new file mode 100644
index 000000000..e31be82ac
--- /dev/null
+++ b/.changeset/old-pears-design.md
@@ -0,0 +1,7 @@
+---
+'@astrojs/prism': patch
+---
+
+Fix `<Prism />` component indentation
+
+Prefer `class="language-plaintext"` to `class="language-undefined"`
diff --git a/packages/astro-prism/Prism.astro b/packages/astro-prism/Prism.astro
index 44cf4748a..fab9dafe2 100644
--- a/packages/astro-prism/Prism.astro
+++ b/packages/astro-prism/Prism.astro
@@ -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>
diff --git a/packages/astro-prism/src/highlighter.ts b/packages/astro-prism/src/highlighter.ts
index 3dffefae9..c0e58054e 100644
--- a/packages/astro-prism/src/highlighter.ts
+++ b/packages/astro-prism/src/highlighter.ts
@@ -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]);