Skip to content

Commit

Permalink
feat(vitepress): support hide codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Mar 3, 2024
1 parent 951436a commit e3b44eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/genji-theme-vitepress/__tests__/markdown-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion packages/genji-theme-vitepress/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e3b44eb

Please sign in to comment.