Code
Inline Code
Wrap the code within a single backquote `
. Use the syntax for inserting short code snippets in the text, such as variable names, function names, or brief code statements.
print("Hello, World!")
Code:
`print("Hello, World!")`
Code Blocks
Wrap the code within three backquotes ```
. Use this to display longer code snippets, such as function definitions, algorithm implementations, etc. It helps to clearly show the format and structure of the code.
Example
def say_hello(name):
print(f"Hello, {name}!")
say_hello("World")
Code:
```
def say_hello(name):
print(f"Hello, {name}!")
say_hello("World")
```
Specifying a Language
Specify the programming language after the three backquotes ```
. This will apply syntax highlighting according to the programming language. If not specified, it will still display as a code block but without syntax highlighting.
This is a code block without a specified language.
System.out.println("Hello, World!");
Code:
```
This is a code block without a specified language.
System.out.println("Hello, World!");
```
This is a code block with the specified Java language.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Code:
```java
This is a code block with the specified Java language.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
```
This is a code block with the specified Python language.
def hello_world():
print("Hello, World!")
hello_world()
Code:
```python
This is a code block with the specified Python language.
def hello_world():
print("Hello, World!")
hello_world()
```
Last modified: 5 months ago