Skip to content

Commit f3540ac

Browse files
committed
Allow no-display code fence attribute to omit code fence block
1 parent e13e9c9 commit f3540ac

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/preprocessReadme.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export function preprocessReadme(opts: Partial<PreprocessReadmeOptions>): Pick<P
4444
highlight(source, lang, attrs) {
4545
if (lang === "svelte") {
4646
const noEval = /no-eval/.test(attrs);
47+
const noDisplay = /no-display/.test(attrs);
4748
const { instance } = parse(source);
4849

4950
if (instance !== undefined && !noEval) {
@@ -66,7 +67,7 @@ export function preprocessReadme(opts: Partial<PreprocessReadmeOptions>): Pick<P
6667
});
6768
const svelteCode = Prism.highlight(formattedCode, Prism.languages.svelte, "svelte");
6869
return `<pre class="language-${lang}" ${
69-
noEval ? "" : `data-svelte="${modifiedSource}"`
70+
noEval || noDisplay ? "" : `data-svelte="${modifiedSource}"`
7071
}>{@html \`${svelteCode}\`}</pre>`;
7172
}
7273

test/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ Second script block:
7070
<script>
7171
import Button from "my-svelte-component";
7272
73-
7473
let toggled; /** comment */
7574
</script>
7675
@@ -92,7 +91,7 @@ Second script block:
9291
import { onMount } from "svelte";
9392
9493
onMount(() => {
95-
console.log('eval')
94+
console.log("eval");
9695
});
9796
</script>
9897
@@ -103,7 +102,18 @@ Second script block:
103102
import { onMount } from "svelte";
104103
105104
onMount(() => {
106-
document.title = 'title';
105+
document.title = "title";
106+
});
107+
</script>
108+
109+
```
110+
111+
```svelte no-display
112+
<script>
113+
import { onMount } from "svelte";
114+
115+
onMount(() => {
116+
console.log("eval no display");
107117
});
108118
</script>
109119

0 commit comments

Comments
 (0)