From e3b44ebc654f3b00d625f0835a9dfbb18f141842 Mon Sep 17 00:00:00 2001 From: MiniPear Date: Sun, 3 Mar 2024 15:54:47 +0800 Subject: [PATCH] feat(vitepress): support hide codeblock --- .../__tests__/markdown-extensions.md | 12 ++++++++++++ packages/genji-theme-vitepress/src/render.js | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/genji-theme-vitepress/__tests__/markdown-extensions.md b/packages/genji-theme-vitepress/__tests__/markdown-extensions.md index 240d680..efdbc20 100644 --- a/packages/genji-theme-vitepress/__tests__/markdown-extensions.md +++ b/packages/genji-theme-vitepress/__tests__/markdown-extensions.md @@ -38,6 +38,18 @@ It should render with `| dom` markup with `javascript`. block("orange"); ``` +## Hide Code + +```js | dom "code: false" +display(() => { + const div = document.createElement("div"); + div.style.width = "100px"; + div.style.height = "100px"; + div.style.background = "steelblue"; + return div; +}); +``` + ## Dispose Block ```js | dom diff --git a/packages/genji-theme-vitepress/src/render.js b/packages/genji-theme-vitepress/src/render.js index bed78b6..9cf34bd 100644 --- a/packages/genji-theme-vitepress/src/render.js +++ b/packages/genji-theme-vitepress/src/render.js @@ -177,12 +177,13 @@ function render(module, { isDark }) { for (let i = 0; i < blocks.length; i++) { const block = blocks[i]; const { dataset } = block; - const { lang, parser } = dataset; + const { lang, parser, code: showCode } = dataset; const P = [parsers[lang], window[parser]].filter(Boolean); if (P.length) { const pre = block.getElementsByClassName("shiki")[0]; const code = pre.textContent; + if (showCode === "false") block.style.display = "none"; const observable = new Observable((observer) => { let normalized;