-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgenerate_images.awk
54 lines (47 loc) · 1.17 KB
/
generate_images.awk
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/awk -f
BEGIN {
in_example = 0
create_image_tag = 0
capturing = 0
}
/!\[.*\]\(.*\)/ {
create_image_tag = 0
}
{
if (create_image_tag) {
print "![" name "](https://raw.githubusercontent.com/Robotechnic/diagraph/main/images/" name "1.png)"
create_image_tag = 0
}
print
}
match($0,/^<!--EXAMPLE\((.*)\)-->$/,group) {
in_example = 1
name = group[1]
next
}
/^````typ$/ {
if (in_example) {
capturing = 1
print "#import \"@preview/diagraph:0.3.1\": *" > "images/" name ".typ"
print "#context{" >> "images/" name ".typ"
print "let render = [" >> "images/" name ".typ"
next
}
}
/^````$/ {
if (capturing) {
capturing = 0
in_example = 0
print "]" >> "images/" name ".typ"
print "let dimensions = measure(render)" >> "images/" name ".typ"
print "set page(width: dimensions.width, height: dimensions.height, margin: 0cm, fill: white)" >> "images/" name ".typ"
print "render" >> "images/" name ".typ"
print "}" >> "images/" name ".typ"
system("typst compile -f png \"images/" name ".typ\" \"images/" name "{n}.png\"")
create_image_tag = 1
next
}
}
capturing {
print >> "images/" name ".typ"
}