-
Notifications
You must be signed in to change notification settings - Fork 4
/
render_md.awk
executable file
·50 lines (40 loc) · 1 KB
/
render_md.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
#!/usr/bin/awk -f
# this file processes ptml files to include and render markdown files in them.
BEGIN {
# Need to set the folder of markdown files
markdown_path = ENVIRON["MARKDOWN_DIR"]
RENDER = "python3 ./utils/render_md.py "
}
/<!-- *include/ {
file = $2
# file has a forward slash in it, leave it alone:
if(!match($2, /\//)) {
# if file is a markdown
if (match(file, ".*\.md$")){
is_markdown = 1
if(markdown_path != ""){
file = markdown_path "/" $2
}
}
}
i = 0
# if it's a markdown file
if(is_markdown==1){
# render markdown first
cmd = RENDER file
while((cmd | getline) >0 ){
print $0
i++
}
close(cmd)
if(i == 0){
s = "<p>We attempted to render markdown file from " file " but failed.</p>"
print s > "/dev/stderr"
print s
}
}else{
print $0
}
next
}
{ print }