Summary Files Commits Branches @commit @diff @stats
path: root / single.awk
diff options
context:
space:
mode:
Commit573da3af1d9eaec45dad88622458950a94bf9ed9 (patch)
Author
 Syndamia <kamen@syndamia.com>
2024-12-31 11:05:52 +0200
Committer
 Syndamia <kamen@syndamia.com>
2024-12-31 11:23:19 +0200
Files13b461e45f60043248cb46d62f58942828d91e53 /single.awk
csg-573da3af1d9eaec45dad88622458950a94bf9ed9.tar
csg-573da3af1d9eaec45dad88622458950a94bf9ed9.tar.gz
csg-573da3af1d9eaec45dad88622458950a94bf9ed9.zip
Parenta132e1ba8480edd7f4efc80b02b5f91064b572a5 (diff)
fix(single): Make checkbox lists actual lists
1 files changed, 14 insertions, 4 deletions
-rw-r--r--single.awk18
diff --git a/single.awk b/single.awk
index 00f9e2e..b60535f 100644
--- a/single.awk
+++ b/single.awk
@@ -196,12 +196,16 @@ function autoinsert(arrname, isbefore) {
/^( |\t)[ \t]*/ {
}
-# Check boxes
+# Check boxes Part 1/2
/^[ \t]*- \[[ x]\][ \t]/ {
+ if (checkbox_level <= 0) {
+ println("<ul class=\"checkboxed\">")
+ checkbox_level = 1
+ }
match($0, /- \[[ x]\][ \t]/)
if (substr($0, RSTART + 3, 1) == "x") checked = " checked=\"checked\""
else checked = ""
- $0 = "<input type=\"checkbox\" disabled=\"disabled\"" checked ">" substr($0, RSTART + RLENGTH) "</br>"
+ $0 = "<li><input type=\"checkbox\" disabled=\"disabled\"" checked "><label>" substr($0, RSTART + RLENGTH) "</label></li>"
}
# Unordered lists
@@ -250,8 +254,8 @@ function abs(x) { return ((x < 0) ? -x : x) }
}
# Paragraphs
-prev_blankline && !blankline && lengthStack("bq-level") == 0 && lengthStack("list-level") == 0 { $0 = "<p>" $0 }
-!prev_blankline && blankline && lengthStack("bq-level") == 0 && lengthStack("list-level") == 0 { prev = prev "</p>" }
+prev_blankline && !blankline && lengthStack("bq-level") == 0 && lengthStack("list-level") == 0 && checkbox_level == 0 { $0 = "<p>" $0 }
+!prev_blankline && blankline && lengthStack("bq-level") == 0 && lengthStack("list-level") == 0 && checkbox_level == 0 { prev = prev "</p>" }
# Blockquote Part 2/2
blankline {
@@ -262,6 +266,12 @@ blankline {
}
}
+# Check boxes Part 2/2
+checkbox_level > 0 && ! /^<li><input type="checkbox" disabled="disabled"/ {
+ println("</ul>")
+ checkbox_level = 0
+}
+
# Links
/!?\[[^\]]*\] ?[(\[][^)\]]*[\])]/ {
isimg = 0