diff --git a/awk/blockquote.awk b/awk/blockquote.awk new file mode 100644 index 0000000..25f1646 --- /dev/null +++ b/awk/blockquote.awk @@ -0,0 +1,14 @@ +BEGIN { in_bq = 0 } +/^>[[:space:]]?/ { + if (!in_bq) { print "
"; in_bq = 1 } + sub(/^>[[:space:]]?/, "", $0) + print $0 + next +} +{ + if (in_bq) { print "
"; in_bq = 0 } + print +} +END { + if (in_bq) print "" +} diff --git a/awk/blockquote_to_admonition.awk b/awk/blockquote_to_admonition.awk new file mode 100644 index 0000000..36bde00 --- /dev/null +++ b/awk/blockquote_to_admonition.awk @@ -0,0 +1,46 @@ +function cap(s) { return toupper(substr(s, 1, 1)) tolower(substr(s, 2)) } +BEGIN { count = 0 } +{ lines[++count] = $0 } +END { + i = 1 + while (i <= count) { + if (lines[i] == "
") { + j = i + 1 + while (j <= count && lines[j] != "
") j++ + if (j <= count) { + first = "" + first_idx = 0 + for (k = i + 1; k < j; k++) { + if (lines[k] != "") { + first = lines[k] + first_idx = k + break + } + } + if (first ~ /^\[![A-Za-z]+\]$/) { + kind = first + sub(/^\[!/, "", kind) + sub(/\]$/, "", kind) + lkind = tolower(kind) + if (lkind == "note" || lkind == "tip" || lkind == "important" || lkind == "warning" || lkind == "caution") { + print "
" + print "

" cap(lkind) "

" + has_body = 0 + for (k = first_idx + 1; k < j; k++) { + if (lines[k] != "") { + print "

" lines[k] "

" + has_body = 1 + } + } + if (!has_body) print "

" + print "
" + i = j + 1 + continue + } + } + } + } + print lines[i] + i++ + } +} diff --git a/awk/breaks.awk b/awk/breaks.awk new file mode 100644 index 0000000..6e2e137 --- /dev/null +++ b/awk/breaks.awk @@ -0,0 +1,5 @@ +{ + if ($0 == "" && prev == "") print "
" + else print $0 + prev = $0 +} diff --git a/awk/fenced_code.awk b/awk/fenced_code.awk new file mode 100644 index 0000000..eaef47f --- /dev/null +++ b/awk/fenced_code.awk @@ -0,0 +1,27 @@ +BEGIN { in_fence = 0; first_line = 0 } +{ + if (!in_fence && $0 ~ /^```/) { + in_fence = 1 + first_line = 1 + next + } + if (in_fence && $0 ~ /^```[[:space:]]*$/) { + print "" + in_fence = 0 + next + } + if (in_fence) { + if (first_line) { + first_line = 0 + if ($0 == "") next + print "
" $0
+        } else {
+            print
+        }
+    } else {
+        print
+    }
+}
+END {
+    if (in_fence) print "
" +} diff --git a/awk/generate_sidebar.awk b/awk/generate_sidebar.awk index 00296f1..50ab4b3 100644 --- a/awk/generate_sidebar.awk +++ b/awk/generate_sidebar.awk @@ -4,6 +4,34 @@ function title_from_name(name) { return name } +function compare_paths(p1, p2, parts1, parts2, n1, n2, i, name1, name2, lname1, lname2, w1, w2) { + n1 = split(p1, parts1, "/") + n2 = split(p2, parts2, "/") + for (i = 1; i <= n1 && i <= n2; i++) { + name1 = parts1[i] + name2 = parts2[i] + if (i == n1) gsub(/\.md$/, "", name1) + if (i == n2) gsub(/\.md$/, "", name2) + lname1 = tolower(name1) + lname2 = tolower(name2) + + if (lname1 == "index" && i == n1 && lname2 != "index") return -1 + if (lname2 == "index" && i == n2 && lname1 != "index") return 1 + + w1 = (lname1 in custom_order ? custom_order[lname1] : 999999) + w2 = (lname2 in custom_order ? custom_order[lname2] : 999999) + + if (w1 < w2) return -1 + if (w1 > w2) return 1 + + if (lname1 < lname2) return -1 + if (lname1 > lname2) return 1 + } + if (n1 < n2) return -1 + if (n1 > n2) return 1 + return 0 +} + BEGIN { n_dlines = split(dinfo, dlines, "\n") for (i = 1; i <= n_dlines; i++) { @@ -39,33 +67,6 @@ BEGIN { has_index[dir] = 1 } } -function compare_paths(p1, p2, parts1, parts2, n1, n2, i, name1, name2, lname1, lname2, w1, w2) { - n1 = split(p1, parts1, "/") - n2 = split(p2, parts2, "/") - for (i = 1; i <= n1 && i <= n2; i++) { - name1 = parts1[i] - name2 = parts2[i] - if (i == n1) gsub(/\.md$/, "", name1) - if (i == n2) gsub(/\.md$/, "", name2) - lname1 = tolower(name1) - lname2 = tolower(name2) - - if (lname1 == "index" && i == n1 && lname2 != "index") return -1 - if (lname2 == "index" && i == n2 && lname1 != "index") return 1 - - w1 = (lname1 in custom_order ? custom_order[lname1] : 999999) - w2 = (lname2 in custom_order ? custom_order[lname2] : 999999) - - if (w1 < w2) return -1 - if (w1 > w2) return 1 - - if (lname1 < lname2) return -1 - if (lname1 > lname2) return 1 - } - if (n1 < n2) return -1 - if (n1 > n2) return 1 - return 0 -} END { for (i = 0; i < count - 1; i++) { @@ -78,7 +79,6 @@ END { } } - print "