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
| Method | What happens |
|---|---|
| Slash menu → Code block | Inserts an empty fenced block at the cursor |
Type ``` at the start of a line | Markdown shortcut: converts the line into a fenced block |
| Paste a fenced block from elsewhere | Paste recognized as a code block |
| Paste from the VS Code-style snippet bar | Detected 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:
- It travels with the doc through export (
.md,.docx,.pdf) - It’s preserved when you copy the block to GitHub, Notion, or any other Markdown tool that does highlight
- It’s structurally correct GFM
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
| Aspect | Behavior |
|---|---|
| Font | The theme’s monospace stack (var(--font-mono)) |
| Background | The theme’s subtle surface (var(--bg-subtle)) |
| Border | 1px solid the theme’s border color, 8px radius |
| Padding | 1rem on all sides |
| Overflow | Horizontal scroll for long lines (no word wrap) |
| Size | 0.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
| Action | What you can do |
|---|---|
| Type / delete / select | Normal text editing |
| Tab | Inserts a real tab character (no auto-indent) |
| Enter | New line within the block |
| Enter twice in a row at the bottom | Exits the code block back to a paragraph |
| Selection inside the block | The bubble toolbar does not appear — code blocks don’t take inline marks |
| Comments | You 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:
- Paste a fenced block from GitHub, Stack Overflow, ChatGPT, anywhere — comes in as a real code block (the Markdown paste extension handles this).
- Copy out of sweetdocs: the rendered block copies as plain text, the source as Markdown.
- Export to Markdown: the fenced block survives exactly, including the language hint.
- Export to DOCX / PDF: the code renders in a monospace style (no highlighting, no language label).
- Public link viewer: the same
marked+ DOMPurify pipeline as Preview mode, with the same monospace styling.
What’s not in v1
| Missing | Notes |
|---|---|
| Syntax highlighting | No highlighter is loaded (no Prism, no highlight.js, no lowlight) |
| Copy-to-clipboard button on the block | Use the system copy (select + ⌘C) |
| Line numbers | Not rendered |
| Code folding | Not available |
| Diff highlighting | Not supported |
| Embedded Monaco editor inside the doc | Not in v1 — only the SVG editor uses Monaco (see Image layout) |
| Language auto-detection from content | You add the hint yourself |