-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhugo.nim
40 lines (36 loc) · 1.48 KB
/
hugo.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# custom stuff for my slides
template nimibCodeAnimate*(lines: varargs[seq[HSlice[int, int]]], body: untyped) =
## Shows code and its output just like nbCode, but highlights different lines of the code in the order specified in `lines`.
## lines: Specify which lines to highlight and in which order. (Must be specified as a seq[HSlice])
## Ex:
## ```nim
## animateCode(@[1..1], @[3..4, 6..6]): body
## ```
## This will first highlight line 1, then lines 3, 4 and 6.
body
nbRawHtml: "<hr/>"
fragmentFadeIn:
newNbCodeBlock("nimibCodeAnimate", body):
var linesString: string
if lines.len > 0:
linesString &= "|"
for lineBundle in lines:
for line in lineBundle:
linesString &= $line.a & "-" & $line.b & ","
linesString &= "|"
if lines.len > 0:
linesString = linesString[0 .. ^3]
nb.blk.context["highlightLines"] = linesString
template nimibCodeAnimate*(lines: varargs[HSlice[int, int], toHSlice], body: untyped) =
## Shows code and its output just like nbCode, but highlights different lines of the code in the order specified in `lines`.
## lines: Specify which lines to highlight and in which order. (Must be specified as a HSlice)
## Ex:
## ```nim
## animateCode(1..1, 2..3, 5..5, 4..4): body
## ```
## This will first highlight line 1, then lines 2 and 3, then line 5 and last line 4.
var s: seq[seq[HSlice[int, int]]]
for line in lines:
s.add @[line]
nimibCodeAnimate(s):
body