akkadian-lang/src/scripts/tab-md2md.awk

107 lines
1.5 KiB
Awk
Executable File

#!/usr/bin/gawk -f
BEGIN {
f="/dev/stdout"
x_col_width["default"] = 15;
x_col_width[1] = 6;
x_col_width[2] = 7;
in_block = 0;
block_end = "^```\\s*$";
block_start = "^```verb-tab\\y\\s*$";
}
function col_width(i) {
if (i in x_col_width) {
return x_col_width[i];
}
return x_col_width["default"];
}
function convert_word(a) {
gsub(/--/, "-\\-", a)
gsub(/v/, "$v_k$", a);
gsub(/w/, "$v'_k$", a);
gsub(/x/, "---", a);
gsub(/v̅/, "$\\overbar{v_k}$", a);
return a;
}
#(in_block == 1) && $0 ~ /^```\y\s*/ {
# in_block = 0;
# print "Bye";
# next;
#}
#(in_block == 0) && $0 ~ /^```verb-tab\y\s*/ {
# new_head = 1;
# in_block = 1;
# print "Hello";
# next;
#}
/^```verb-tab\y\s*/, /^```\s*$/ {
if ($0 ~ /^```/) {
new_head = 1;
# print $0;
next;
}
if ($0 ~ /^.+$/) {
split($0,l,/\t+/);
col_num = length(l);
for (i = 1; i <= length(l); ++i) {
if (new_head) {
z = l[i];
} else {
z = convert_word(l[i]);
}
if (i == 1) {
printf(" ");
}
printf("%-" col_width(i) "s", z);
if (i < length(l)) {
printf(" | ");
}
}
printf("\n");
if (new_head == 1) {
new_head = 0;
head_done = 1;
} else {
next;
}
}
if (head_done == 1) {
head_done = 0;
for( i = 1; i <= col_num; ++i) {
if (i > 1) {
printf("|");
}
printf(":");
for (j = 0; j < col_width(i); ++j) {
printf("-");
}
if (i == 2) {
printf(":");
} else {
printf("-");
}
}
printf("\n");
next;
}
}
{
print;
}