Skip to content

Code Syntax Highlighter

Rendering effect display

This article provides a simple demo of code block effects and syntax highlighting using the Expressive Code. For more detailed features, please refer to Expressive Code

Code

#include <stdio.h>
int main(void){
printf("Hello, World!\n");
return 0;
}

In Markdown:

```c
#include <stdio.h>
int main(void){
printf("Hello, World!\n");
return 0;
}
```

Title

main.c
#include <stdio.h>
int main(void){
printf("Hello, World!\n");
return 0;
}

In Markdown:

```c
// file: main.c
#include <stdio.h>
int main(void){
printf("Hello, World!\n");
return 0;
}
```

or

```c
// main.c
#include <stdio.h>
int main(void){
printf("Hello, World!\n");
return 0;
}
```

or

```c title="main.c"
#include <stdio.h>
int main(void){
printf("Hello, World!\n");
return 0;
}
```

Markers

void do_something() {
int* data = malloc(SIZE *sizeof(int));
if (data) {
parse(data);
}
free(data);
}
void parse(int* data) {
// ... ...
}

In Markdown:

```c {3-5, 9}
void do_something() {
int* data = malloc(SIZE *sizeof(int));
if (data) {
parse(data);
}
free(data);
}
void parse(int* data) {
// ... ...
}
```

#include <stdio.h>
int main(void){
printf("Hello, World!\n");
printf("Hello, Gopher!\n");
return 0;
}

In Markdown:

```c del={4} ins={5}
#include <stdio.h>
int main(void){
printf("Hello, World!\n");
printf("Hello, Gopher!\n");
return 0;
}
```

float cal_bmi(float mass, float height) {
if (mass <= 0 || height <= 0) {
return -1.0;
}
return mass / (height * height);
}

In Markdown:

```c "return -1.0;"
float cal_bmi(float mass, float height) {
if (mass <= 0 || height <= 0) {
return -1.0;
}
return mass / (height * height);
}
```

Line Numbers

void do_something() {
int* data = malloc(SIZE *sizeof(int));
if (data) {
parse(data);
}
free(data);
}
void parse(int* data) {
// ... ...
}

In Markdown:

```c showLineNumbers
void do_something() {
int* data = malloc(SIZE *sizeof(int));
if (data) {
parse(data);
}
free(data);
}
void parse(int* data) {
// ... ...
}
```

Terminal

# Clone a repo
git clone https://github.com/ziteh/astro-paper-s.git

In Markdown:

```bash
# Clone a repo
git clone https://github.com/ziteh/astro-paper-s.git
```

Frame

The comments in the terminal frame will not be copied by the Copy Button.

Terminal window
# Clone a repo
git clone https://github.com/ziteh/astro-paper-s.git

In Markdown:

```bash frame="terminal"
# Clone a repo
git clone https://github.com/ziteh/astro-paper-s.git
```

Getting Started
# Clone a repo
git clone https://github.com/ziteh/astro-paper-s.git

In Markdown:

```bash frame="terminal" title="Getting Started"
# Clone a repo
git clone https://github.com/ziteh/astro-paper-s.git
```

Markers

pnpm install --frozen-lockfile

In Markdown:

```bash "--frozen-lockfile"
pnpm install --frozen-lockfile
```

More Languages

list of all language identifiers

// C
#include <stdio.h>
int main(void) {
printf("Hello, World!\n");
return 0;
}
# Python
def main():
print("Hello, World!")
// TypeScript
const message: string = "Hello, World!";
console.log(message);
// Go
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
// Rust
fn main() {
println!("Hello, World!");
}
# YAML
app:
name: AstroPaper-S
version: "1.0.0"
debug: true
# TOML
[app]
name = "AstroPaper-S"
version = "1.0.0"
debug = true
/* JSON */
{
"app": {
"name": "AstroPaper-S",
"version": "1.0.0",
"debug": true
}
}
# txt
nam: Hello World!
version: 1.0.0
debug: true
# no identifier
nam: Hello World!
version: 1.0.0
debug: true

中文文章
Markdown Syntax