Use inline code for short identifiers and a fenced Markdown block for multi-line examples. Render the draft to rich text before pasting, trim long lines and irrelevant output, then test the final Substack email on a phone.
StackDraft runs locally in your browser. No account or upload required.
Choose inline code or a code block
Substack’s editors expose code formatting, but the most portable source is still semantic Markdown. Backticks describe the role of the text without carrying an IDE theme, font, or background into the publishing workflow.
| Format | Good use | Example |
|---|---|---|
| Inline code | A command, function, flag, filename, or small value inside prose | npm run build |
| Code block | A multi-line program, config, command sequence, or focused output sample | A complete function or shell session |
| Linked source | A long file, generated output, repository, or example readers may copy | GitHub file or runnable sandbox |
Write a portable fenced code block
Put three backticks on their own lines and add a recognized language label immediately after the opening fence. The label helps a Markdown renderer choose syntax highlighting; it is not part of the code readers copy.
```ts
export function canonicalUrl(pathname: string) {
return new URL(pathname, "https://www.stackdraft.app").toString()
}
```Move Markdown code into Substack
- 01
Reduce the example
Delete setup and output that do not support the article’s point. Prefer one focused example over a full production file.
- 02
Wrap long expressions intentionally
Break chains, arrays, commands, and object literals at meaningful boundaries. Email readers should not need to discover the important token by scrolling sideways.
- 03
Render the Markdown
Load the draft in StackDraft and confirm the code appears as a distinct preformatted block. Long blocks trigger a publishing warning.
- 04
Copy the prepared body
Paste the rich-text result into the desktop Substack editor and confirm the code remains grouped as one block.
- 05
Test copy and mobile behavior
Open the test email on a phone, follow the explanation around the code, and copy a representative line if copying is part of the reader task.
Edit code for readers, not for the repository
- Introduce what the example proves before showing it.
- Keep lines near a narrow reading width when the language permits it.
- Use comments to explain intent or omitted context, not obvious syntax.
- Replace long generated IDs and payloads with clearly marked placeholders.
- Show relevant error lines instead of an entire stack trace.
- Put installation commands and application code in separate blocks.
- Link to the tested full source when exact reproduction matters.
Avoid screenshots for code readers need to use
A code screenshot can preserve a visual theme, but it prevents selection, makes zooming necessary, and is difficult for assistive technology. Use real code text for instructions and examples. Reserve images for explaining a visual editor state or annotating a UI where pixels are the actual subject.
If you include a code image for visual emphasis, provide the meaningful snippet as text or link to an accessible source. Alt text is useful context, but it is not a practical replacement for a long runnable program.
Pre-publish code checklist
- Every code block has a purpose stated in nearby prose.
- The language label matches the syntax.
- No secret, personal path, or internal hostname remains.
- Long lines and large output samples have been reduced.
- Placeholders are unmistakably placeholders.
- The final Substack preview preserves whitespace and grouping.
- The test email is readable without rotating or zooming the phone.
- The complete tested source is linked when omissions matter.
Frequently asked questions
Does Substack support code formatting?
Yes. Substack’s editor includes code formatting options. For a complete Markdown draft, render fenced code to rich text before pasting and verify the final block in a test email.
Should I use syntax highlighting in a newsletter?
Light syntax highlighting can improve scanning, but structure and contrast matter more than an elaborate theme. The example should remain understandable if destination styling changes.
How do I stop code from overflowing on mobile?
Shorten the example, break long expressions at logical points, remove huge values, and test the actual email. A link to the complete file is better than forcing a full desktop-width program into the post.
Should code be an image in Substack?
Not when readers need to select, copy, search, translate, or inspect it. Use text code blocks and reserve screenshots for genuinely visual editor or interface states.
Sources and further reading
Turn the Markdown draft into clean Substack copy.
Preview the post, catch fragile blocks, and copy the title and body separately.
Open StackDraft free