Code Blocks & Syntax Highlighting
Inline Code
For code within a sentence, wrap with single backticks.
Use the `console.log()` function for debugging.
Inline code is perfect for variable names, functions, or short commands.
Code Blocks
For multiple lines of code, use three backticks (```) on separate lines.
```
function hello() {
console.log("Hello!");
}
```
Everything between the backticks is rendered as code.
Syntax Highlighting
Add the language name after the opening backticks for colored syntax highlighting.
```javascript
function hello() {
console.log("Hello!");
}
```
The language name enables proper color coding.
Supported Languages
MD2PDF supports 100+ languages through highlight.js. Common ones include:
If the language isn't recognized, code will still display but without colors.
- Web: javascript, typescript, html, css, json
- Backend: python, java, php, ruby, go, rust
- Systems: c, cpp, csharp, swift, kotlin
- Data: sql, r, julia
- Shell: bash, powershell, dockerfile
- Config: yaml, toml, ini, xml
Quick Code Insertion
In MD2PDF, click the ``` button in Quick Tags to insert a code block template.
Mermaid Diagrams
Create flowcharts, sequence diagrams, and more with Mermaid syntax. Diagrams are rendered automatically in the preview.
```mermaid
flowchart TD
A[Start] --> B{Decision}
B -->|Yes| C[Action]
B -->|No| D[End]
```
Use the MER button in Quick Tags to insert a template.
- Flowcharts: flowchart TD, flowchart LR
- Sequence: sequenceDiagram
- Class: classDiagram
- State: stateDiagram-v2
- Gantt: gantt
- Pie: pie
YAML Blocks
YAML content is rendered with structured formatting - keys in bold, values in normal weight. Perfect for configuration files and metadata.
```yaml
name: My Project
version: 1.0.0
config:
debug: true
features:
- auth
- logging
```
Use the YML button in Quick Tags to insert a template.