Code blocks
Wrap code in triple backticks to create a code block.Syntax highlighting
Add a language identifier after the opening fence to enable syntax highlighting. Retype uses PrismJS and supports all Prism languages.Title
Add a title by placing text after the language identifier, separated by a space.Line numbers
Add# after the language identifier to enable line numbers.
snippets config, use !#:
snippets config in retype.yml:
Enable line numbering for js and json blocks site-wide
Line highlighting
Highlight specific lines by adding a# followed by a line number or range after the opening fence.
| Scenario | Syntax | Description |
|---|---|---|
| Single line | #2 | Highlight line 2 |
| Line range | #2-5 | Highlight lines 2 to 5 |
| Multiple ranges | #2-3,5-7 | Highlight lines 2–3 and 5–7 |
| No line numbers | !#2-3,5-7 | Highlight without showing line numbers |
highlight attribute syntax:
Custom attributes
Apply a customid or CSS class to a code block using the {#id .class} syntax.
Search index
By default, code block content is included in the site search index. To exclude all code blocks from search results, setexcludeCode in your retype.yml:
retype.yml
Code groups
Group multiple code blocks into a tabbed interface using the+++ Tab component. Each block becomes a separate tab.
Code snippets
A code snippet includes the content of an external file (or a portion of it) directly into a code block. This is useful for keeping documentation in sync with actual source code.Source
Thesource attribute is the path to the file, relative to the current document. The file must be accessible when Retype builds the project.
Range
Include only specific lines using therange attribute. Accepts individual line numbers, dash-separated ranges, or comma-separated combinations.
Title
An optional title can be displayed above the code block.Language
Retype automatically detects the language from the file extension. You can override it with thelanguage attribute.
Region (C# only)
For.cs files, use the region attribute to include only the lines between a named #region / #endregion pair.
Mermaid diagrams
Mermaid diagrams are created using a fenced code block with themermaid language specifier.
Directives
Mermaid directives can be applied using the%%{init: { }}%% syntax as the first line of the block.
Syntax highlighting only
To display Mermaid source code with syntax highlighting instead of rendering it as a diagram, use themermaid-js specifier.
Supported diagram types
| Type | Specifier |
|---|---|
| Flowchart | graph LR / graph TD |
| Sequence diagram | sequenceDiagram |
| Gantt chart | gantt |
| Class diagram | classDiagram |
| Entity relationship | erDiagram |
| User journey | journey |
| Kanban | kanban |
| Sankey | sankey-beta |
| Architecture | architecture-beta |
| XY chart | xychart-beta |
Math formulas
Retype renders LaTeX math expressions using KaTeX. All KaTeX syntax is supported.Inline formulas
Wrap an expression in single$ characters to render it inline with surrounding text.
Inline formula example
Block formulas
Wrap an expression in double$$ characters to render it as a centered display block.
Block formula example
LaTeX syntax highlighting
Add thelatex language specifier to a regular fenced code block to display LaTeX source with syntax highlighting (without rendering it as a formula).
