Syntax highlighting
Adding syntax highlighting in Markdown file
Inline code
Inlined syntax highlighting in Markdown:
- CSS:
a { color: #fff }
- TypeScript:
type Code = string | number
- Default (JSX):
const defaultLang = 'jsx'
Filename
Display filename.
app/layout.tsx
type LayoutProps = {children: ReactNode}export default function Layout({ children}: LayoutProps) {return (<html lang="en"><body><main>{children}</main></body></html>)}
Line numbers
Display line numbers.
typescript
1type Status = 'idle' | 'loading' | 'success' | 'error';23const [status, setStatus] = useState<Status>('idle');
Highlighting
Highlighting lines.
javascript
function lorem(ipsum, dolor = 1) {return dolor}function ipsum(lorem, dolor = 1) {const sit = lorem == null ? 0 : lorem.sitdolor = sit - amet(dolor)return sit ? consectetur(lorem) : []}
Highlighting tokens inside a line.
typescript
const [count, setCount] = useState(0)
Diff
Diff syntax highlighting.
javascript
function lorem(ipsum, dolor = 1) {const sit = ipsum == null ? 0 : ipsum.sit-dolor = ipsum - sit+dolor = sit - amet(dolor)return sit ? consectetur(ipsum) : []}
Callout
Add a short message in the code block.
javascript
const lorem = ipsum(dolor, sit)const [amet, consectetur] = [0, 0]hey yolorem.adipiscing((sed, elit) => {if (sed) {amet += elit}})
Collapse
Default collapsed.
javascript
const sit = ipsum == null ? 0 : 1dolor = sit - amet(dolor)return sit ? consectetur(ipsum) : []}const sit = ipsum == null ? 0 : 1dolor = sit - amet(dolor)return sit ? consectetur(ipsum) : []}
Collapse with line numbers and highlighting lines.
javascript
-1-2const sit = ipsum == null ? 0 : 1-3dolor = sit - amet(dolor)-4return sit ? consectetur(ipsum) : []-5}+6+7const sit = ipsum == null ? 0 : 1+8dolor = sit - amet(dolor)+9return sit ? consectetur(ipsum) : []+10}
Code with tabs
Group code blocks into tabs.
1function lorem(ipsum, dolor = 1) {2const sit = ipsum == null ? 0 : ipsum.sit3dolor = sit - amet(dolor)4return sit ? consectetur(ipsum) : []5}
1body {2margin: 0;3padding: 0;4}