-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess_src2gift_3.awk
78 lines (75 loc) · 1.8 KB
/
process_src2gift_3.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# This file is part of: gift-for-html
# Author: S. Kramm, 2020
# Home: https://github.com/skramm/gift-for-html
# Step 3: replace inside gift answer blocks of code delimited by `{` and `}`
# and escape reserved Moodle/gift characters
{
if( $1=="{" ) # opening an answer block
{
ablock=1;
print $0;
# print "ANSWER BLOCK OPEN"
}
else
{
if( $1=="}" ) # closing an answer block
{
ablock=0;
print $0;
# print "ANSWER BLOCK CLOSE"
}
else # not closing nor opening an answer block
{
printLine=1;
if( ablock==0 ) # if not an answer block, process all `:`
{
# print "NOT ANSWER BLOCK"
if( !($0 ~ /^[$].+/) ) # if '$' is NOT the first char of line ("category" line)
{
if( $0 !~ /[:]{2}/ ) # if line does NOT hold `::` (question title)
{
{
gsub(":","\\:"); # THEN escape reserved characters
gsub("{","\\{");
gsub("}","\\}");
gsub("#","\\#");
gsub("=","\\=");
gsub("~","\\~");
}
}
}
print $0;
}
else
{ # if answer block, escape reserved characters
# print "ANSWER BLOCK"
gsub("{","\\{");
gsub("}","\\}");
gsub("#","\\#");
gsub(":","\\:");
# This part will process answer lines, that MUST start with '=' (good answer) or '~' (bad answer)
if( $0 ~ /^[=].+/ ) # if '=' is first char of line
{
line=substr($0,2) # fetch all but first char
gsub("=","\\=",line); # replace
gsub("~","\\~",line);
print "=" line
printLine=0;
}
else
{
if( $0 ~ /^[~].+/ ) # if '~' is first char of line
{
line=substr($0,2)
gsub("=","\\=",line);
gsub("~","\\~",line);
print "~" line
printLine=0;
}
}
if( printLine )
print $0;
}
}
}
}