Skip to content

Commit

Permalink
fix(#4246): fix Prism indentation and class (#4251)
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
natemoo-re and natemoo-re authored Aug 11, 2022
1 parent 51847a2 commit 1f0dd31
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .changeset/old-pears-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astrojs/prism': patch
---

Fix `<Prism />` component indentation

Prefer `class="language-plaintext"` to `class="language-undefined"`
6 changes: 1 addition & 5 deletions packages/astro-prism/Prism.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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>
4 changes: 1 addition & 3 deletions packages/astro-prism/src/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 1f0dd31

Please sign in to comment.