Syntax Highlighting

in Code Blocks

Share code snippets with syntax highlighting
January 13, 2024
Share
print("hello world!")

Need to share a code snippet? Eggspress integrates highlight.js, a library that applies syntax highlighting to your code blocks.

Code blocks are highlighted in different themes depending on whether dark mode is toggled.

In light mode, Eggspress uses stackoverflow-light. In dark mode, github-dark.

How to create a code block

You can create code blocks in your Markdown content. To do so, wrap any number of lines of code in between a set of three backticks (the "`" character).

To apply syntax highlighting, you must specify the language used inside of the code block. This can be done by appending the name of the language immediately following the first set of backticks.

Here are some examples of how you might write code blocks in your content.

```python
def greet(name):
    print(f"Hello, {name}!")

person = "World"
greet(person)
```
```java
public class Greeting {
    public static void greet(String name) {
        System.out.println("Hello, " + name + "!");
    }

    public static void main(String[] args) {
        String person = "World";
        greet(person);
    }
}
```

You may also use an alias to specify your language. In the example below, we specify our language as "js" instead of "javascript."

```js
function greet(name) {
  console.log("Hello, " + name + "!");
}

let person = "World";
greet(person);
```

Which languages are supported?

Eggspress supports all 192 languages available through highlight.js. For a complete list of languages, see Supported Languages.

Hello, World!

The following are "Hello, world!" code snippets in various languages. These demonstrate how your code blocks may appear with syntax highlighting.

C++

#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Python

print("Hello, world!")

JavaScript

console.log('Hello, world!');

TypeScript

let message: string = 'Hello, World!';
console.log(message);

HTML

<!DOCTYPE html>
<html>
  <head>
    <title>Hello, World!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>  
  </body>
</html>

Kotlin

fun main() {
   println("Hello World!")
}

SQL

 CREATE TABLE message (text char(15));
 INSERT INTO message (text) VALUES ('Hello, world!');
 SELECT text FROM message;
 DROP TABLE message;

Rust

fn main() {
    println!("Hello, world!");
}

Go

package main

import "fmt"

func main() {
  fmt.Println("Hello, world!")
}

Fortran

PROGRAM HelloWorld
  WRITE(*, *) 'Hello, world!'
END PROGRAM HelloWorld

Excel

="Hello, world!"

Stata

 capture program drop hello /*Define Hello, world! program*/
 program define hello   
      di "Hello, world!"
 end
 
 hello  /*run Hello, world! program*/

x86 Assembly

; FASM example of writing 16-bit DOS .COM program
; Compile: "FASM HELLO.ASM HELLO.COM" 
  org  $100
  use16    
  mov  ah,9
  mov  dx,xhello
  int  $21    ; DOS call: text output
  mov  ah,$4C
  int  $21    ; Return to DOS
xhello db 'Hello world !!!$'
Share this post
relation icon
Related Posts
Editing Eggspress Content
November 23, 2023
In this fifth and final part of our Getting Started Guide, we'll walk you through how to edit files in your workspace and customize their appearance to get the results you want.
Read more
logo