Skip to content

Text, code and math

Format text, show code with highlights and diffs, document a shell session, write math, and add margin notes.

3 min read

Updated

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.

Start a block with three backticks and a language. Add a title and options after it, in any order:

server.js
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.

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.

config.js
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.

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.

Terminal
npm install specly-example
added 1 package in 2s
npm run build \
-- --verbose

Copy takes the commands only.

Write LaTeX between dollar signs, and it’s typeset when the site is built: $E = mc^2$ gives E=mc2E = mc^2 inline. A block between $$ lines is shown on its own:

∫01x2 dx=13\int_0^1 x^2 \, dx = \frac{1}{3}

A dollar sign before a number is a price, not math: a plan costs $5 a month, or $50 a year.

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:

MDX
:::margin
Notes 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.

Was this page helpful?

Report a problem

What’s the problem?

The docs team sees this. Other readers don’t.