Home · Docs · Editor · Code blocks

Code blocks

Fenced code blocks with optional language hints, monospace rendering, and the same Markdown source on disk that GitHub and every other tool uses.

Code blocks in sweetdocs are plain GFM fenced blocks — three backticks, optional language hint, your code in the middle. They’re stored exactly that way in the Markdown source, so round-tripping into and out of any other Markdown tool is lossless.

The greeter is small enough to inline:

javascriptconst greet = (name) => `Hello, ${name}!`

console.log(greet('Kyoto'))
console.log(greet('Osaka'))
// → "Hello, Kyoto!"
// → "Hello, Osaka!"

Inserting a code block

MethodWhat happens
Slash menu → Code blockInserts an empty fenced block at the cursor
Type ``` at the start of a lineMarkdown shortcut: converts the line into a fenced block
Paste a fenced block from elsewherePaste recognized as a code block
Paste from the VS Code-style snippet barDetected as code, becomes a real block (see Markdown paste extension)

Once you’re inside a code block, all Markdown formatting is disabled — backticks, asterisks, and underscores all render as literal text. Only plain typing and newlines.

Language hints

Add a language tag after the opening fence:

```javascript
const greet = name => `Hello, ${name}!`
```

The language is preserved in the source but there is no syntax highlighting in v1 — code renders as plain monospace with a subtle background and a soft border. The hint matters because:

Any string is accepted as a language hint — python, bash, tsx, mermaid, nginx, whatever. No allowlist.

If you don’t add a hint, the block is still a code block — it just has no language-… class on the rendered <code> element.

Styling

AspectBehavior
FontThe theme’s monospace stack (var(--font-mono))
BackgroundThe theme’s subtle surface (var(--bg-subtle))
Border1px solid the theme’s border color, 8px radius
Padding1rem on all sides
OverflowHorizontal scroll for long lines (no word wrap)
Size0.875rem (14px equivalent at default root)

The styling is identical in Edit mode and Preview mode — you’re looking at the same CSS in both places.

Inline code

Inline code uses single backticks: `like this` — small monospace, subtle pill background, accent text color, rounded edge. Same syntax everywhere:

Use the `useEffect` hook for side effects.

This is a separate Markdown construct from a fenced block. Use inline code for short identifiers and short snippets inside prose; use fenced blocks for anything that needs its own lines.

Editing inside a block

ActionWhat you can do
Type / delete / selectNormal text editing
TabInserts a real tab character (no auto-indent)
EnterNew line within the block
Enter twice in a row at the bottomExits the code block back to a paragraph
Selection inside the blockThe bubble toolbar does not appear — code blocks don’t take inline marks
CommentsYou can still attach comments to a code block via the Comments panel

There’s no language selector dropdown, no copy button, no line numbers, no folding, and no inline Monaco editor in v1. The block is intentionally simple — what you write is what gets saved.

Round-trip behavior

Because the on-disk shape is plain GFM:

What’s not in v1

MissingNotes
Syntax highlightingNo highlighter is loaded (no Prism, no highlight.js, no lowlight)
Copy-to-clipboard button on the blockUse the system copy (select + ⌘C)
Line numbersNot rendered
Code foldingNot available
Diff highlightingNot supported
Embedded Monaco editor inside the docNot in v1 — only the SVG editor uses Monaco (see Image layout)
Language auto-detection from contentYou add the hint yourself