@plugdash/codeblock

The EmDash alternative to SyntaxHighlighter Evolved

Highlighted code, rendered on the server.

320 words·2min read

Runs the code blocks EmDash already stores through Shiki at render time, so the page ships coloured HTML with no client JavaScript and no runtime theme switching. Nothing is rewritten on save - change the theme and every existing post picks it up on the next render. Ships CodeBlock.astro, auto-wired into PortableText.

npm install @plugdash/codeblock
alphaGitHub
src/lib/posts.tstypescript
import { getEmDashCollection } from "emdash"

export async function latestPosts(limit = 5) {
  const { entries } = await getEmDashCollection("posts")
  return entries
    .filter((p) => p.data.status === "published")
    .slice(0, limit)
}
python
def reading_time(words: int, wpm: int = 238) -> int:
    return max(1, round(words / wpm))
made-up-lang
no grammar for this one, so it falls back to plaintext

This is the default. No configuration.

Setup

  1. Install and register

    bash
    npm install @plugdash/codeblock
    js
    import { codeblockPlugin } from "@plugdash/codeblock"
    // in emdash plugins array:
    codeblockPlugin({ theme: "github-dark", lineNumbers: true })
  2. Add to your layout

    astro
    import CodeBlock from "@plugdash/codeblock/CodeBlock.astro"
    
    <CodeBlock code={source} language="typescript" />

After this, every existing code block in your posts renders highlighted - no editor changes, no migration. Auto-wired into PortableText, so there's nothing else to add unless you want direct control outside Portable Text.

It looks right. But it's yours to change.

Props

proptypedefaultdescription
codestringSource to highlight - required to render
languagestringLanguage name. Unknown ones render as plaintext.
filenamestringShown in the header bar
themestring"github-dark"Shiki theme name
lightThemestringSecond theme for light mode
lineNumbersbooleanfalseShow the line number gutter
classstringAdditional CSS class
nodeobjectBlock data from PortableText auto-wiring

CSS custom properties

tokendescription
--plugdash-codeblock-radiusBorder radius (default 6px)
--plugdash-codeblock-paddingPadding around the code (default 1rem)
--plugdash-codeblock-sizeFont size (default 0.875rem)
--plugdash-codeblock-line-heightLine height (default 1.6)
--plugdash-codeblock-fontFont family (default monospace stack)
--plugdash-codeblock-header-paddingHeader bar padding (default 0.5rem 1rem)
--plugdash-codeblock-header-bgHeader bar background (default #1a1a1a)
--plugdash-codeblock-header-colorHeader bar text (default #9ca3af)
--plugdash-codeblock-gutter-widthLine number column width (default 2rem)
--plugdash-codeblock-gutter-colorLine number colour (default #6b7280)

Components are intentionally simple. Copy src/CodeBlock.astrointo your theme and modify freely - no upstream coupling.

Pairs well with

callouts and code blocks are the two blocks every technical writer reaches for.

beta

The block every technical writer reaches for that almost no theme ships.

npm install @plugdash/callout
beta

Long posts deserve navigation. Your readers will find what they came for.

npm install @plugdash/tocgen
built with plugdash.dev