{"_id":"@plugdash/codeblock","_rev":"4-65bd783a746e0e4d23f65a37ff2bc8e0","name":"@plugdash/codeblock","dist-tags":{"latest":"0.4.0"},"versions":{"0.1.0":{"name":"@plugdash/codeblock","version":"0.1.0","keywords":["emdash","emdash-plugin","codeblock","shiki","syntax-highlighting"],"license":"MIT","_id":"@plugdash/codeblock@0.1.0","maintainers":[{"name":"abhinav061","email":"abhinav061@gmail.com"}],"homepage":"https://github.com/plugdash/plugdash#readme","bugs":{"url":"https://github.com/plugdash/plugdash/issues"},"dist":{"shasum":"339479a06e808a0350834f1704117026832e650c","tarball":"https://registry.npmjs.org/@plugdash/codeblock/-/codeblock-0.1.0.tgz","fileCount":10,"integrity":"sha512-hzWEnnb+lPylZ7oNjHz27FlzngXJAqxwq46p5XcyXr3jPBA/af+Q6+aLbRmVXMdJFKiP/fPAAokX8uyIfB8Tdw==","signatures":[{"sig":"MEQCIDLqkmuA8tvVF6xxuOuFAqEKp/Nn2xGSSuU35YY2VlhdAiAbHo1pgsfiptElY6d/p1gMZqlzZU8qzKGv1BZtGS11Cw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":35363},"main":"./dist/index.mjs","type":"module","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"},"./astro":"./src/astro/index.ts","./CodeBlock.astro":"./src/CodeBlock.astro"},"gitHead":"b25b6667c81891ddea3b04b2ef9a675e4697ddf2","scripts":{"test":"vitest run","build":"tsdown src/index.ts --dts.eager","typecheck":"tsc --noEmit"},"_npmUser":{"name":"abhinav061","email":"abhinav061@gmail.com"},"repository":{"url":"git+https://github.com/plugdash/plugdash.git","type":"git","directory":"packages/codeblock"},"_npmVersion":"12.1.0","description":"Shiki syntax highlighting for EmDash code blocks - rendered server-side, zero client JavaScript","directories":{},"_nodeVersion":"24.21.0","dependencies":{"shiki":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.0.0","@plugdash/types":"workspace:*","@plugdash/testing":"workspace:*"},"peerDependencies":{"emdash":">=0.13.0"},"_npmOperationalInternal":{"tmp":"tmp/codeblock_0.1.0_1790399747356_0.22291319723990055","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@plugdash/codeblock","version":"0.2.0","keywords":["emdash","emdash-plugin","codeblock","shiki","syntax-highlighting"],"license":"MIT","_id":"@plugdash/codeblock@0.2.0","maintainers":[{"name":"abhinav061","email":"abhinav061@gmail.com"}],"homepage":"https://github.com/plugdash/plugdash#readme","bugs":{"url":"https://github.com/plugdash/plugdash/issues"},"dist":{"shasum":"8d0ee561ca76259b65c287c43ad6523745027523","tarball":"https://registry.npmjs.org/@plugdash/codeblock/-/codeblock-0.2.0.tgz","fileCount":11,"integrity":"sha512-4itJuIq8DXAFEi+XL6Bu4mids5ANzPRnKCHxCctyO1zMpwFpwyKXd6ukOGbiaZNzynY7SDMpg04ORUfOPLGy5Q==","signatures":[{"sig":"MEUCIQCmCEJhe3dg4qy/b6drpfl7t82aVCjw9WLGqO9S/4W8iAIgTh0kJ0otgIztzlhvPMIvHaala10b2mGI6kHoevYE5e4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQCyflq1bq7vpvf2EIUXpt3GbO4MJWSURobsF1E49xgQxAIhAOw0ZxuudI/F9tdNaP4wdIB/6W86jPWGXui9wMEbGSqL","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@plugdash%2fcodeblock@0.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":47816},"main":"./dist/index.mjs","type":"module","_from":"file:plugdash-codeblock-0.2.0.tgz","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"},"./astro":"./src/astro/index.ts","./CodeBlock.astro":"./src/CodeBlock.astro"},"scripts":{"test":"vitest run","build":"tsdown src/index.ts --dts.eager","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3e397b9f-c370-4d26-80e9-59c9a9bcae24"}},"_resolved":"/tmp/87d55e22989c2c729fd9525ea666fb82/plugdash-codeblock-0.2.0.tgz","_integrity":"sha512-4itJuIq8DXAFEi+XL6Bu4mids5ANzPRnKCHxCctyO1zMpwFpwyKXd6ukOGbiaZNzynY7SDMpg04ORUfOPLGy5Q==","repository":{"url":"git+https://github.com/plugdash/plugdash.git","type":"git","directory":"packages/codeblock"},"_npmVersion":"11.5.1","description":"Shiki syntax highlighting for EmDash code blocks - rendered server-side, with a copy button","directories":{},"_nodeVersion":"22.23.2","dependencies":{"shiki":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.0.0","@plugdash/types":"0.0.0","@plugdash/testing":"0.0.0"},"peerDependencies":{"emdash":">=0.13.0"},"_npmOperationalInternal":{"tmp":"tmp/codeblock_0.2.0_1790408422248_0.46656336928635334","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@plugdash/codeblock","version":"0.3.0","keywords":["emdash","emdash-plugin","codeblock","shiki","syntax-highlighting"],"license":"MIT","_id":"@plugdash/codeblock@0.3.0","maintainers":[{"name":"abhinav061","email":"abhinav061@gmail.com"}],"homepage":"https://github.com/plugdash/plugdash#readme","bugs":{"url":"https://github.com/plugdash/plugdash/issues"},"dist":{"shasum":"6cc8170d8d9914fc271a912b35811d30dbff2d8a","tarball":"https://registry.npmjs.org/@plugdash/codeblock/-/codeblock-0.3.0.tgz","fileCount":11,"integrity":"sha512-knOp3xF1ZHMFXEZ6qG5QEQSMXC2ohaAsiIP2xnsyLbl9Pu8ZphklP3U6mcHU4HvPl5AtsiRYkdMIXcG9DOTzpw==","signatures":[{"sig":"MEUCIQCvVBr3f9eVUfP+JwpCchBmkO2e0+m5BINvo5W15fKX7AIgNlWPXitoLkwD7DIQkvz2d1xniXEfW3tZvv99gYEzcvI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIEWC6GsXO4VVDT8ta5D5fNCj5S9R+RABm4EFJlH8JvJwAiEAxXEWpZUd495wqgjbIX0lf3BaBZnxLdsiwQAnZhpq/JI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@plugdash%2fcodeblock@0.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":48764},"main":"./dist/index.mjs","type":"module","_from":"file:plugdash-codeblock-0.3.0.tgz","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"},"./astro":"./src/astro/index.ts","./CodeBlock.astro":"./src/CodeBlock.astro"},"scripts":{"test":"vitest run","build":"tsdown src/index.ts --dts.eager","typecheck":"tsc --noEmit"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:3e397b9f-c370-4d26-80e9-59c9a9bcae24"}},"_resolved":"/tmp/313b8f3503525088ba2d850d639249aa/plugdash-codeblock-0.3.0.tgz","_integrity":"sha512-knOp3xF1ZHMFXEZ6qG5QEQSMXC2ohaAsiIP2xnsyLbl9Pu8ZphklP3U6mcHU4HvPl5AtsiRYkdMIXcG9DOTzpw==","repository":{"url":"git+https://github.com/plugdash/plugdash.git","type":"git","directory":"packages/codeblock"},"_npmVersion":"11.5.1","description":"Shiki syntax highlighting for EmDash code blocks - rendered server-side, with a copy button","directories":{},"_nodeVersion":"22.23.2","dependencies":{"shiki":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.0.0","@plugdash/types":"0.0.0","@plugdash/testing":"0.0.0"},"peerDependencies":{"emdash":">=0.13.0"},"_npmOperationalInternal":{"tmp":"tmp/codeblock_0.3.0_1790444223642_0.45971752862907533","host":"s3://npm-registry-packages-npm-production"}},"0.4.0":{"_id":"@plugdash/codeblock@0.4.0","bugs":{"url":"https://github.com/plugdash/plugdash/issues"},"dist":{"shasum":"350cc02534f767af23f020705ef6fb08e6c3c4a8","tarball":"https://registry.npmjs.org/@plugdash/codeblock/-/codeblock-0.4.0.tgz","fileCount":12,"integrity":"sha512-GXJbJYXH65wElmWAssPc2JvBcwjgDvSUHObPI14MT/FsYR01119uuF28dKTGjGvd3TyPyWxDU/ZnyMFT7f030w==","signatures":[{"sig":"MEUCIQCCJq/cRfjYGrjVlp6ZbFq/yFGqR7PBp931dJvizH64hAIgLSUQVxRZ7OuGLcyUrhTUgJk5JfjrVZwswS0kAYjkQ6I=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQC7VhTy+hwQ3w9kaTzudjIQSZLDmoZqlvfJhxNjATPiggIhAJ0hKFoCAoCxjAN7kG4ILCaKBYBS63FgtNmMNsuGYOEK"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@plugdash%2fcodeblock@0.4.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":73908},"main":"./dist/index.mjs","name":"@plugdash/codeblock","type":"module","_from":"file:plugdash-codeblock-0.4.0.tgz","types":"./dist/index.d.mts","exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs"},"./astro":"./src/astro/index.ts","./CodeBlock.astro":"./src/CodeBlock.astro"},"license":"MIT","scripts":{"test":"vitest run","build":"tsdown src/index.ts --dts.eager","typecheck":"tsc --noEmit"},"version":"0.4.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"3e397b9f-c370-4d26-80e9-59c9a9bcae24"}},"homepage":"https://github.com/plugdash/plugdash#readme","keywords":["codeblock","emdash","emdash-plugin","shiki","syntax-highlighting"],"_resolved":"/tmp/36fc48c6fe95a64b277b31370cf09e41/plugdash-codeblock-0.4.0.tgz","_integrity":"sha512-GXJbJYXH65wElmWAssPc2JvBcwjgDvSUHObPI14MT/FsYR01119uuF28dKTGjGvd3TyPyWxDU/ZnyMFT7f030w==","repository":{"url":"git+https://github.com/plugdash/plugdash.git","type":"git","directory":"packages/codeblock"},"_npmVersion":"11.5.1","description":"Shiki syntax highlighting for EmDash code blocks - rendered server-side, with a copy button","directories":{},"maintainers":[{"name":"abhinav061","email":"abhinav061@gmail.com"}],"_nodeVersion":"22.23.3","dependencies":{"shiki":"^4.0.0"},"_hasShrinkwrap":false,"devDependencies":{"vitest":"^2.0.0","@plugdash/types":"0.0.0","@plugdash/testing":"0.0.0"},"peerDependencies":{"emdash":">=0.13.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/codeblock_0.4.0_1790936767194_0.3459273687271218"}}},"time":{"created":"2026-09-26T05:15:47.192Z","modified":"2026-10-02T10:26:07.674Z","0.1.0":"2026-09-26T05:15:47.488Z","0.2.0":"2026-09-26T07:40:22.327Z","0.3.0":"2026-09-26T17:37:03.734Z","0.4.0":"2026-10-02T10:26:07.301Z"},"bugs":{"url":"https://github.com/plugdash/plugdash/issues"},"license":"MIT","homepage":"https://github.com/plugdash/plugdash#readme","keywords":["codeblock","emdash","emdash-plugin","shiki","syntax-highlighting"],"repository":{"url":"git+https://github.com/plugdash/plugdash.git","type":"git","directory":"packages/codeblock"},"description":"Shiki syntax highlighting for EmDash code blocks - rendered server-side, with a copy button","maintainers":[{"name":"abhinav061","email":"abhinav061@gmail.com"}],"readme":"# @plugdash/codeblock\n\nShiki syntax highlighting for EmDash code blocks. Each block is highlighted\nonce, when the post is saved, and the HTML is stored on the block, so a page\nview does no highlighting and never loads Shiki. The only client JavaScript is\none small click listener for the copy button.\nShips `CodeBlock.astro` for site-side rendering and exports `highlightCode`\nfor themes that render code themselves.\n\n## Install\n\n```bash\npnpm add @plugdash/codeblock\n```\n\nEmDash templates set `minimumReleaseAge` in `pnpm-workspace.yaml`, which makes\npnpm skip any release younger than 24 hours and quietly install an older one.\nTo get the latest plugdash release, add it to the exclude list:\n\n```yaml\n# pnpm-workspace.yaml\nminimumReleaseAgeExclude:\n  - \"@plugdash/*\"\n```\n\n## Register\n\n```js\n// astro.config.mjs\nimport { defineConfig } from \"astro/config\";\nimport emdash from \"emdash/astro\";\nimport { codeblockPlugin } from \"@plugdash/codeblock\";\n\nexport default defineConfig({\n\tintegrations: [\n\t\temdash({\n\t\t\tplugins: [codeblockPlugin({ theme: \"github-dark\", lineNumbers: true })], // native - must be in plugins, not sandboxed\n\t\t}),\n\t],\n});\n```\n\nNative plugin - cannot be sandboxed or published to the EmDash marketplace.\nIt needs Shiki, which is a Node dependency.\n\n## How it works\n\n1. An author writes a code block in the editor and sets its language\n2. On save, a `content:beforeSave` hook runs each `code` block through Shiki\n   and stores the result on the block as `pdHighlight: { key, html, ... }`\n3. On the site, `CodeBlock.astro` checks the key and prints the stored HTML\n4. The rendered page contains Shiki's `<pre class=\"shiki ...\">` markup\n\nThe key is a hash of the code, language, theme, light theme, line numbers\nsetting and plugin version. When any of them changes, the stored HTML no\nlonger matches and is ignored: the block is highlighted at render time (and\nShiki loads for that request) until the post is saved again, which stores\nfresh HTML. So after changing the theme, old posts still render correctly in\nthe new theme, and re-saving them makes them fast again.\n\nHighlighting never blocks a save. If Shiki fails or takes longer than 30\nseconds, the post saves without stored HTML and renders the slow way. Blocks\nwhose HTML is over 100,000 characters are not stored, to keep the content row\nsmall; they are highlighted at render time.\n\nThe admin editor drops unknown fields from code blocks when it saves, so the\nstored HTML is rebuilt on every editor save. Unchanged blocks come from an\nin-memory cache, so in practice only edited blocks cost anything.\n\nBlock components are auto-wired into `<PortableText>` - no manual component\nmapping needed. This plugin registers no new block type; it renders the `code`\nblock EmDash already has.\n\nThe highlighter uses Shiki's JavaScript regex engine rather than the default\nWASM one, because the WASM engine does not load inside a Cloudflare Worker.\n\n## Config options\n\n| Option        | Type       | Default       | Description                                                  |\n| ------------- | ---------- | ------------- | ------------------------------------------------------------ |\n| `theme`       | `string`   | `github-dark` | Shiki theme name. Unknown names fall back to the default.    |\n| `lightTheme`  | `string`   | see below     | Second theme for light mode, emitted as CSS variables.       |\n| `langs`       | `string[]` | common set    | Languages loaded up front. Anything else loads on first use. |\n| `lineNumbers` | `boolean`  | `false`       | Render line numbers in the gutter.                           |\n\nPreloaded by default: TypeScript, JavaScript, Python, Go, Rust, Shell, JSON,\nYAML, Markdown, HTML, CSS, SQL.\n\n## Companion component\n\nThe component works in two modes:\n\n### Auto-wired (default - no setup needed)\n\nRegistered via `componentsEntry`, the component automatically renders `code`\nblocks in your site's `<PortableText>` output.\n\n### Direct import\n\nFor manual usage outside of Portable Text:\n\n```astro\n---\nimport CodeBlock from \"@plugdash/codeblock/CodeBlock.astro\"\n---\n\n<CodeBlock code={source} language=\"typescript\" />\n<CodeBlock code={source} language=\"python\" filename=\"app.py\" lineNumbers />\n<CodeBlock code={source} language=\"rust\" theme=\"tokyo-night\" lightTheme=\"catppuccin-latte\" />\n```\n\nProps override the options passed to `codeblockPlugin()`. Leave them out and\nthe component uses the site config.\n\n### Props\n\n| Prop          | Type      | Default     | Description                                      |\n| ------------- | --------- | ----------- | ------------------------------------------------ |\n| `code`        | `string`  | -           | Source to highlight (required to render)         |\n| `language`    | `string`  | -           | Language name. Unknown ones render as plaintext. |\n| `filename`    | `string`  | -           | Shown in the header bar                          |\n| `theme`       | `string`  | site config | Shiki theme name                                 |\n| `lightTheme`  | `string`  | site config | Second theme for light mode                      |\n| `lineNumbers` | `boolean` | site config | Show the line number gutter                      |\n| `class`       | `string`  | -           | Additional CSS class                             |\n| `node`        | `object`  | -           | Block data from PortableText auto-wiring         |\n\nRenders nothing when `code` is missing or empty.\n\n## Using the highlighter directly\n\n```astro\n---\nimport { highlightCode } from \"@plugdash/codeblock\";\nconst html = await highlightCode(block.code, block.language, { theme: \"nord\" });\n---\n<Fragment set:html={html} />\n```\n\n`highlightCode` returns Shiki's `<pre>` HTML. Results are cached in memory,\nkeyed by theme and source, with the hundred most recent kept.\n\n## CSS custom properties\n\nToken and background colours come from the Shiki theme. Everything around the\ncode is overridable:\n\n| Property                              | Default           | Description                  |\n| ------------------------------------- | ----------------- | ---------------------------- |\n| `--plugdash-codeblock-radius`         | `6px`             | Border radius                |\n| `--plugdash-codeblock-padding`        | `1rem`            | Padding around the code      |\n| `--plugdash-codeblock-size`           | `0.875rem`        | Font size                    |\n| `--plugdash-codeblock-line-height`    | `1.6`             | Line height                  |\n| `--plugdash-codeblock-font`           | monospace stack   | Font family                  |\n| `--plugdash-codeblock-header-padding` | `0.5rem 1rem`     | Header bar padding           |\n| `--plugdash-codeblock-header-bg`      | theme bg, tinted  | Header bar background        |\n| `--plugdash-codeblock-header-color`   | theme text, muted | Header bar text              |\n| `--plugdash-codeblock-header-border`  | theme text, faint | Line between header and code |\n| `--plugdash-copy-success-color`       | `#22c55e`         | Copy button after a copy     |\n| `--plugdash-codeblock-gutter-width`   | `2rem`            | Line number column width     |\n| `--plugdash-codeblock-gutter-color`   | theme text, faded | Line number colour           |\n\nThe header and gutter defaults are mixed from the theme's own background and\ntext colours, so they match any theme, light or dark.\n\n## Light and dark mode\n\nWith no config, blocks render `github-dark` and switch to `github-light` in\nlight mode. Setting `theme` turns that off, so a site that picks a dark theme\nstays dark. To switch with your own pair, set both. Any\n[Shiki theme](https://shiki.style/themes) works:\n\n```js\ncodeblockPlugin({ theme: \"tokyo-night\", lightTheme: \"catppuccin-latte\" });\n```\n\nThe light theme is used when the OS prefers light, unless the site forces a\nmode on `<html>` with `data-theme=\"light\"` / `data-theme=\"dark\"` or a\n`.light` / `.dark` class. Both conventions are respected in either direction.\nIf your site is dark by default with no marker on `<html>`, set\n`data-theme=\"dark\"` explicitly, or light-OS visitors get light code blocks.\n\nExample override:\n\n```css\n:root {\n\t--plugdash-codeblock-radius: 0;\n\t--plugdash-codeblock-size: 0.8125rem;\n}\n```\n\n## Edge cases\n\n- Unknown or missing language renders as plaintext instead of throwing\n- `text`, `txt`, `plain`, `plaintext` and `none` all mean plaintext\n- Empty code renders an empty `<pre>` block\n- Code over 10,000 lines is cut off with a trailing truncation notice\n- Unknown theme names fall back to `github-dark`\n\n## What it does not do\n\n- No line highlighting or diff view\n- No client-side highlighting. Light/dark switching is CSS only\n- No new editor block type\n- No migration step. Posts saved before this version render at request time\n  until they are saved again\n- No metadata writes or KV storage. The only thing it writes is\n  `pdHighlight` on each `code` block, which declares `content:write`\n","readmeFilename":"README.md"}