- Documentation
- Write content
- Text, code and math
Text, code and math
Format text, show code with highlights and diffs, document a shell session, write math, and add margin notes.
Pages are Markdown with MDX on top, so everything in CommonMark works: headings, lists,
tables, links, inline code, bold and italic. This page covers what Specly adds for code, math and notes.
Code blocks
Section titled “Code blocks”Start a block with three backticks and a language. Add a title and options after it, in any order:
import http from 'node:http';const port = 3000;
http.createServer((req, res) => { res.end('ok');}).listen(port);That block’s first line is ```js server.js {2,4-5} lines.
| Option | What it does |
|---|---|
server.js |
A bare word or a quoted string is the block’s title. title="server.js" works too. A title that looks like a file name shows as one. |
{2,4-5} |
Highlights those lines. highlight={2} does the same. |
lines |
Shows line numbers. showLineNumbers does the same. |
wrap |
Wraps long lines. Readers can also switch wrapping on with the Wrap lines button when a line is cut off. |
focus={2-3} |
Dims every line except the ones listed. |
Every block has a Copy button. Specly also knows run and norun, which are for runnable code.
Mark lines in the code
Section titled “Mark lines in the code”To mark a line from inside the code, end it with a comment. Use // [!code ++] to show an added line,
// [!code --] for a removed one, // [!code highlight] to highlight it and // [!code focus] to focus it. Add a
count, as in // [!code focus:3], to mark that many lines from the line down. Use the comment syntax of the language, for
example # [!code ++] in Python or YAML.
export default { retries: 3, retries: 5, timeout: 30,};The markers are removed from the page. Copy takes the code as it ends up, without the removed lines.
Shell sessions
Section titled “Shell sessions”Start the commands in a bash or shell block with $ . The prompt is drawn for you and isn’t copied, and every other
line is output. A command that ends in \ continues on the next line.
npm install specly-exampleadded 1 package in 2snpm run build \ -- --verboseCopy takes the commands only.
Write LaTeX between dollar signs, and it’s typeset when the site is built: $E = mc^2$ gives inline. A
block between $$ lines is shown on its own:
A dollar sign before a number is a price, not math: a plan costs $5 a month, or $50 a year.
Margin notes
Section titled “Margin notes”A margin note is an aside that sits in the right column beside the text it belongs to. On a narrow screen, it moves into
the text. Write one with :::margin:
:::marginNotes can hold `code` and [links](/write/pages).:::Margin notes are for side remarks. Anything the reader needs belongs in the text.
Margin notes work in .md pages. In an .mdx page, :::margin isn’t read, so the note doesn’t show.