Adding Code Blocks to Doks

Writing documentation in markdown can be complicated when you want to add code blocks. Luckily, Doks developers have added formatting possibilities for code blocks in Doks 1.2; however, the documentation available for code blocks was complex for me to parse, so I simplified the information and decided to share it with you all.

Traditional Backtick Method

```js
# Adding two numbers
sum = num1 + num2
 
# printing values
print("Sum of", num1, "and", num2 , "is", sum)
```

outputs:

# Adding two numbers
sum = num1 + num2
 
# printing values
print("Sum of", num1, "and", num2 , "is", sum)

File Name Tab

```js {title="count.js"}
# Adding two numbers
sum = num1 + num2
 
# printing values
print("Sum of", num1, "and", num2 , "is", sum)
```

Output:

count.js
# Adding two numbers
sum = num1 + num2
 
# printing values
print("Sum of", num1, "and", num2 , "is", sum)

Terminal Window

```bash
print("Sum of", num1, "and", num2 , "is", sum)
```

Output:

print("Sum of", num1, "and", num2 , "is", sum)

With a Title

```bash {title="adding numbers…"}
print("Sum of", num1, "and", num2 , "is", sum)
```

Output:

adding numbers…
print("Sum of", num1, "and", num2 , "is", sum)

Line Numbers

```js {lineNos=true lineNoStart=1}
# Adding two numbers
sum = num1 + num2
 
# printing values
print("Sum of", num1, "and", num2 , "is", sum)
```
1# Adding two numbers
2sum = num1 + num2
3 
4# printing values
5print("Sum of", num1, "and", num2 , "is", sum)

Highlight

```js {hl_lines=4}
# Adding two numbers
sum = num1 + num2
 
# printing values
print("Sum of", num1, "and", num2 , "is", sum)
```
# Adding two numbers
sum = num1 + num2
 
# printing values
print("Sum of", num1, "and", num2 , "is", sum)

Highlight With Line Numbers:

```go {linenos=true,hl_lines=[1,"2-4"],linenostart=1}
# Adding two numbers
sum = num1 + num2
 
# printing values
print("Sum of", num1, "and", num2 , "is", sum)
```
1# Adding two numbers
2sum = num1 + num2
3 
4# printing values
5print("Sum of", num1, "and", num2 , "is", sum)
6print("I needed one more line for my example.")