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..96d5f60 100644 --- a/test/fixtures.test.js +++ b/test/fixtures.test.js @@ -44,6 +44,10 @@ const runFixture = async (fixture, fixtureName, getHighlighter) => { const html = await getHTML(code, { keepBackground: !resultHTMLName.includes('keepBackground'), defaultLang: (() => { + if (testName === 'no-highlighting') { + 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 @@
{ 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
+