Blame

76d856 Ralph Thesen 2023-11-29 21:45:06 1
# Syntax Highlighting
2
3
On this page you can find examples on how An Otter Wiki highlights code block with a given syntax.
4
5
A code block is fenced with three backticks `` ``` `` on the line before and after the code block. To add syntax highlighting specify the language next to the backticks of the first line, e.g.
6
7a2860 Ralph Thesen 2024-03-21 01:29:55 7
A fenced code block with language yaml, like
76d856 Ralph Thesen 2023-11-29 21:45:06 8
9
```yaml
10
version: '3'
11
services:
12
otterwiki:
1df4a0 Ralph Thesen 2024-02-28 11:36:01 13
image: redimp/otterwiki:2
76d856 Ralph Thesen 2023-11-29 21:45:06 14
ports:
15
- 8080:80
16
```
17
18
will be rendered as
19
20
```yaml
21
version: '3'
22
services:
23
otterwiki:
1df4a0 Ralph Thesen 2024-02-28 11:36:01 24
image: redimp/otterwiki:2
76d856 Ralph Thesen 2023-11-29 21:45:06 25
ports:
26
- 8080:80
27
```
28
29
Examples for multiple other languages can be found below. All the examples implementing the Fibonacci sequence (and more examples in more languages) can be found on [rosettacode.org](https://rosettacode.org/wiki/Fibonacci_sequence).
30
31
---
32
33
### bash
34
35
```bash
36
fib()
37
{
38
if [ $1 -le 0 ]
39
then
40
echo 0
41
return 0
42
fi
43
if [ $1 -le 2 ]
44
then
45
echo 1
46
else
47
a=$(fib $[$1-1])
48
b=$(fib $[$1-2])
49
echo $(($a+$b))
50
fi
51
}
52
```
53
54
### C
55
56
```c
57
long long int fibb(int n) {
58
int fnow = 0, fnext = 1, tempf;
59
while(--n>0){
60
tempf = fnow + fnext;
61
fnow = fnext;
62
fnext = tempf;
63
}
7a2860 Ralph Thesen 2024-03-21 01:29:55 64
return fnext;
76d856 Ralph Thesen 2023-11-29 21:45:06 65
}
66
```
67
68
### C++
69
70
```cpp
71
#include <numeric>
72
#include <vector>
73
#include <functional>
74
#include <iostream>
75
76
unsigned int fibonacci(unsigned int n) {
77
if (n == 0) return 0;
78
std::vector<int> v(n, 1);
79
adjacent_difference(v.begin(), v.end()-1, v.begin()+1, std::plus<int>());
80
// "array" now contains the Fibonacci sequence from 1 up
81
return v[n-1];
82
}
83
```
84
85
### Dockerfile
86
87
```Dockerfile
88
FROM alpine:3.18.0
89
MAINTAINER mail@example.com
90
91
RUN set -ex \
92
&& apk update && apk upgrade \
93
&& apk add --no-cache \
94
bash curl dhcping iftop httpie netcat-openbsd py3-pip \
95
py3-setuptools vim git
96
97
USER root
98
WORKDIR /root
99
ENV HOSTNAME toolkit
100
101
CMD ["bash"]
102
```
103
104
### Go
105
106
```go
107
import (
108
"math/big"
109
)
110
111
func fib(n uint64) *big.Int {
112
if n < 2 {
113
return big.NewInt(int64(n))
114
}
115
a, b := big.NewInt(0), big.NewInt(1)
116
for n--; n > 0; n-- {
117
a.Add(a, b)
118
a, b = b, a
119
}
120
return b
121
}
122
```
123
124
### Haskell
125
126
```haskell
127
fib x =
128
if x < 1
129
then 0
130
else if x == 1
131
then 1
132
else fibs !! (x - 1) + fibs !! (x - 2)
133
where
134
fibs = map fib [0 ..]
135
```
136
137
### html
138
139
```html
140
<!DOCTYPE html>
141
<html>
142
<head>
143
<meta charset="UTF-8">
144
<title>The title goes here</title>
145
</head>
146
<body>
147
<!-- a comment -->
148
The content goes here.
149
</body>
150
</html>
151
```
152
153
### json
154
155
```json
156
{
157
"mixed list": [
158
"string",
159
42
160
],
161
"object": {
162
"key": "value",
163
"array": [
164
{
165
"null_value": null
166
},
167
{
168
"boolean": true
169
},
170
{
171
"float": 1.2
172
}
173
]
174
},
175
"content": "Some lines\nwith line breaks"
176
}
177
```
178
179
### nginx
180
181
```nginx
182
user www www;
183
worker_processes 2;
184
pid /var/run/nginx.pid;
185
error_log /var/log/nginx.error_log debug | info | notice | warn | error | crit;
186
187
events {
188
connections 2000;
189
use kqueue | rtsig | epoll | /dev/poll | select | poll;
190
}
191
192
http {
193
log_format main '$remote_addr - $remote_user [$time_local] '
194
'"$request" $status $bytes_sent '
195
'"$http_referer" "$http_user_agent" '
196
'"$gzip_ratio"';
197
send_timeout 3m;
198
client_header_buffer_size 1k;
199
...
200
```
201
202
### python
203
204
```python
205
def fibMemo():
206
pad = {0:0, 1:1}
207
def func(n):
208
if n not in pad:
209
pad[n] = func(n-1) + func(n-2)
210
return pad[n]
211
return func
212
213
fm = fibMemo()
214
for i in range(1,31):
215
print fm(i),
216
```
217
218
### php
219
220
```php
221
<?php
222
function fibIter($n) {
223
if ($n < 2) {
224
return $n;
225
}
226
$fibPrev = 0;
227
$fib = 1;
228
foreach (range(1, $n-1) as $i) {
229
list($fibPrev, $fib) = array($fib, $fib + $fibPrev);
230
}
231
return $fib;
232
}
233
?>
234
```
235
236
### rust
237
238
```rust
239
use std::mem;
240
fn main() {
241
fibonacci(0,1);
242
}
243
244
fn fibonacci(mut prev: usize, mut curr: usize) {
245
mem::swap(&mut prev, &mut curr);
246
if let Some(n) = curr.checked_add(prev) {
247
println!("{}", n);
248
fibonacci(prev, n);
249
}
250
}
251
```
252
253
### yaml
254
255
```yaml
256
---
257
mixed list:
258
- string
259
- 42
260
object:
261
key: value
262
array:
263
- null_value:
264
- boolean: true
265
- float: 1.2
266
content: |-
267
Some lines
268
with line breaks
269
```
270
271
### xml
272
273
```xml
274
<?xml version="1.0" encoding="UTF-8" ?>
275
<root>
276
<mixed_list>string</mixed_list>
277
<mixed_list>42</mixed_list>
278
<object>
279
<key>value</key>
280
<array>
281
<null_value />
282
</array>
283
<array>
284
<boolean>true</boolean>
285
</array>
286
<array>
287
<float>1.2</float>
288
</array>
289
</object>
290
<content>Some lines
291
with line breaks</content>
292
</root>
293
```
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9