Skip to content

Code Blocks

A code block in the Atlas editor

A code block in the Atlas editor

Code blocks keep a stretch of text exactly as you wrote it, which makes them the right home for code, commands, configuration, and anything else where spacing matters. Atlas gives them a language badge, syntax highlighting, and code-editor typing, so a snippet reads and behaves like it would in a developer's editor.

Creating a Code Block

There are two ways to start one:

  • Type three backticks on an empty line. The third backtick turns the line into an empty code block and puts the caret on its code line. It only fires at the start of an empty line, so backticks in the middle of a sentence stay as typed.
  • Use the Code Block command. On Mac, choose Code Block from the overflow menu of the floating formatting bar. On iPhone, tap the code button on the formatting keyboard and choose Code Block. On iPad, the keyboard has separate code and code block buttons.

On an empty line, the command makes an empty block. With text selected, it wraps every line the selection touches and keeps your selection in place. Pasted Markdown that already contains fences works too.

Note

Code Block has no item or shortcut in the Markup menu. Inline Code is in the Markup menu without a shortcut.

How a Code Block Looks

The fence lines are always hidden, whatever your Hide Markdown Syntax setting says. A code block sits on a rounded background, with a language badge at the trailing edge of its first line. The badge names the language, such as "JavaScript", or reads "Code" when you haven't chosen one. A long first line wraps short of the badge, so the badge never covers your code.

The caret never rests on a fence line, and the arrow keys skip over them. Click or tap a fence line to select the whole block. Select All inside a block selects the block, and a second press selects the whole document. Press Backspace at the edge of a block and Atlas selects the block first, then deletes it on the second press.

On Mac, the floating formatting bar hides while your selection is inside a code block or inline code.

Choosing a Language

Click (Mac) or tap (iPhone and iPad) the badge to open the language picker. It has a Language search field above a set of chips. Your recent languages come first, then the popular ones. Type to filter by name, identifier, or nickname, so js, ts, py, sh, and yml all find what you expect.

Click a chip, or press Enter to take the best match. If nothing matches, Enter writes what you typed, which lets you name a language Atlas doesn't highlight. Clear the field to remove the language, and press Esc to cancel. Each change is one undo step named Change Language.

Atlas highlights 36 languages: Bash, C, C++, C#, CSS, Diff, Go, GraphQL, HTML and XML, INI, Java, JavaScript, JSON, Kotlin, Less, Lua, Makefile, Markdown, Objective-C, Perl, PHP, PHP Template, Plain Text, Python, Python REPL, R, Ruby, Rust, SCSS, Shell Session, SQL, Swift, TypeScript, Visual Basic .NET, WebAssembly, and YAML.

Typing in Code

Lines inside a code block type like they would in a code editor:

  • Tab adds one indent, as set by Tab Inserts. With several lines selected, it indents every non-empty line in one undo step. Shift-Tab removes up to one indent from each line.
  • Return keeps the current line's leading whitespace. It never continues a list or a blockquote.
  • No substitutions. Smart quotes and automatic text replacement stay out of your code.
  • Spellcheck skips code on Mac. On iPhone and iPad, spelling marks can still appear inside a block.
  • Typing shortcuts such as [[, {{, and $$ don't trigger inside code.

Syntax Highlighting

Atlas colors the parts of each language, such as keywords, strings, and comments, in blocks that name a language the picker knows. Colors catch up a moment after you stop typing. Choose when they appear with Show Code Syntax:

Option What you see
Off No token colors. Blocks use your editor theme's Code Block colors.
On Focus Only the block you're editing is colored. Other blocks use your editor theme's code colors.
Always Every block is colored. Blocks without a language show in the code theme's plain text color.

Code Settings

On Mac, open Settings > Editor and choose the Code tab. On iPhone and iPad, open Settings > Editor Settings and scroll to the Code section.

Setting Options Default
Show Code Syntax Off, On Focus, Always Always
Default Language Last Used, None, or any of the 36 languages Last Used
Tab Inserts Tab, 2 Spaces, 4 Spaces 4 Spaces
Light and Dark code themes One of 20 themes. The Dark picker also offers None Light: GitHub. Dark: None

Default Language sets the language of a new block, whether you create it by typing backticks or with the Code Block command. It also names the language on unlabeled fences in pasted Markdown. A fence that already names a language is left alone. Last Used remembers the language you picked most recently on this device.

These settings apply in every editor, including canvas cards, templates, version history, and the Web Clipper and Share editors, and they sync across your devices. Your recent languages and the Last Used choice stay on each device.

Code Themes

Atlas bundles 20 code themes. Each picker groups them by the appearance they were designed for, and shows a live preview of a Swift sample on the theme's background.

  • Light: Atom One Light, GitHub, Solarized Light, Stack Overflow Light, Tokyo Night Light, Visual Studio, Xcode
  • Dark: Atom One Dark, GitHub Dark, GitHub Dark Dimmed, Gruvbox Dark, Monokai, Night Owl, Nord, Pojoaque, Solarized Dark, Stack Overflow Dark, Tokyo Night, Tomorrow Night, Visual Studio Dark

Any theme can go in either slot. Atlas uses the Light slot in light appearance and the Dark slot in dark appearance. With the Dark picker on None, Atlas uses the Light theme in both, so a fresh install in Dark Mode shows GitHub's light blocks until you choose a dark theme.

Tip

Pick a dark theme for the Dark slot if you write in Dark Mode. Your editor theme and your code theme are separate, so you can mix them freely.

Code Themes and Editor Themes

A code theme is separate from your editor theme. It isn't stored in a theme. The editor theme's Code Block element, and its Monospace font, still style your blocks when Show Code Syntax is Off and on blocks that aren't active under On Focus. With Always, highlighted blocks take their colors from the code theme.

Export and Print

Highlighted code carries into your output. Exports follow Show Code Syntax, so On Focus and Always both highlight and Off doesn't. They always use the Light code theme, never the Dark one, so choose a Light theme that suits your pages. Only blocks that name a language Atlas knows are colored.

Format What happens
HTML and ePub Code is colored with hljs classes, and Atlas adds the code theme's stylesheet. Colored blocks use the theme's background in place of the style's pre background.
PDF Code is colored, and code blocks use the code theme's background.
RTF and RTFD Code is colored, and code blocks use the code theme's background.
Print Code is colored, with no background fill.
Copy as Rich Text Pasted code keeps its colors.
Markdown and plain text Unchanged.

Note

In PDF and RTF exports, the code theme's background replaces your style's codeBackgroundColor for every code block, including blocks with no language, whenever Show Code Syntax isn't Off. Turn it Off if you want a style's own code colors. See the PDF Style Reference for that field.

See Also