From 2a4a42853af17c478260e6220e10831f32c86cce Mon Sep 17 00:00:00 2001 From: atomiks Date: Tue, 19 Dec 2023 19:45:12 +1100 Subject: [PATCH 1/2] fix: ignore default highlighting for no lang --- src/index.ts | 2 + test/fixtures.test.js | 5 +++ test/fixtures/no-highlighting.md | 3 ++ test/results/defaultLang.inline=js.html | 10 +---- test/results/no-highlighting.html | 55 +++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 test/fixtures/no-highlighting.md create mode 100644 test/results/no-highlighting.html diff --git a/src/index.ts b/src/index.ts index d691ec5..0d79484 100644 --- a/src/index.ts +++ b/src/index.ts @@ -345,6 +345,8 @@ export default function rehypePrettyCode( defaultCodeBlockLang, ); + if (!lang) return; + const lineNumbers: number[] = []; if (meta) { const matches = meta.matchAll(/\{(.*?)\}/g); diff --git a/test/fixtures.test.js b/test/fixtures.test.js index 713fa27..5647112 100644 --- a/test/fixtures.test.js +++ b/test/fixtures.test.js @@ -44,6 +44,11 @@ const runFixture = async (fixture, fixtureName, getHighlighter) => { const html = await getHTML(code, { keepBackground: !resultHTMLName.includes('keepBackground'), defaultLang: (() => { + if (testName === 'no-highlighting') { + console.log('return'); + return undefined; + } + const lang = testName.split('.')[1]; if (!lang) { return undefined; diff --git a/test/fixtures/no-highlighting.md b/test/fixtures/no-highlighting.md new file mode 100644 index 0000000..59f076b --- /dev/null +++ b/test/fixtures/no-highlighting.md @@ -0,0 +1,3 @@ +``` +test +``` diff --git a/test/results/defaultLang.inline=js.html b/test/results/defaultLang.inline=js.html index a77fd54..8748e17 100644 --- a/test/results/defaultLang.inline=js.html +++ b/test/results/defaultLang.inline=js.html @@ -53,14 +53,8 @@

Default language

{ inline: 'js' }

-
-
const x = true;
-
+
const x = true;
+

+ html { + font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif; + } + body { + margin: 30px auto; + max-width: 800px; + } + pre { + padding: 16px; + } + span > code { + background: black; + padding: 4px; + } + [data-highlighted-line], [data-highlighted-chars] { + background-color: rgba(255, 255, 255, 0.25); + } + code[data-line-numbers] { + counter-reset: line; + } + code[data-line-numbers]>[data-line]::before { + counter-increment: line; + content: counter(line); + display: inline-block; + width: 1rem; + margin-right: 2rem; + text-align: right; + color: gray; + } + + [data-rehype-pretty-code-figure] code[data-theme*=' '], + [data-rehype-pretty-code-figure] code[data-theme*=' '] span { + color: var(--shiki-light) !important; + background-color: var(--shiki-light-bg) !important; + } + + @media (prefers-color-scheme: dark) { + [data-rehype-pretty-code-figure] code[data-theme*=' '], + [data-rehype-pretty-code-figure] code[data-theme*=' '] span { + color: var(--shiki-dark) !important; + background-color: var(--shiki-dark-bg) !important; + } + } + + .diff.add { + background-color: rgba(0, 255, 100, 0.25); + } + .diff.remove { + background-color: rgba(255, 100, 200, 0.35); + } + +

test
+
From 5f6a102b0e054b3afbb0845896347a8556a51e6a Mon Sep 17 00:00:00 2001 From: atomiks Date: Tue, 19 Dec 2023 19:46:06 +1100 Subject: [PATCH 2/2] fix: remove log --- test/fixtures.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fixtures.test.js b/test/fixtures.test.js index 5647112..96d5f60 100644 --- a/test/fixtures.test.js +++ b/test/fixtures.test.js @@ -45,7 +45,6 @@ const runFixture = async (fixture, fixtureName, getHighlighter) => { keepBackground: !resultHTMLName.includes('keepBackground'), defaultLang: (() => { if (testName === 'no-highlighting') { - console.log('return'); return undefined; }