Summary Files Commits Branches @commit @diff @stats
path: root / md-parser.awk
diff options
context:
space:
mode:
Commit43164aa75f8180afdeacf47bc0166ff26195991f (patch)
Author
 Syndamia <kamen@syndamia.com>
2025-01-01 20:51:24 +0200
Committer
 Syndamia <kamen@syndamia.com>
2025-01-01 20:51:24 +0200
Files3b193d47e30231527bfade3770ae9472e246d9d4 /md-parser.awk
csg-43164aa75f8180afdeacf47bc0166ff26195991f.tar
csg-43164aa75f8180afdeacf47bc0166ff26195991f.tar.gz
csg-43164aa75f8180afdeacf47bc0166ff26195991f.zip
Parent61b4f2e68becc3d0a2d40d1e98b34d1a1646fd2b (diff)
feat(parser): Implement definition lists
1 files changed, 41 insertions, 3 deletions
-rw-r--r--md-parser.awk44
diff --git a/md-parser.awk b/md-parser.awk
index b25c8b2..c063b4e 100644
--- a/md-parser.awk
+++ b/md-parser.awk
@@ -12,9 +12,9 @@
# [x] Subscript ~...~
# [ ] Footnote [^...] (with user customizations)
# [x] Task list - [ ] (readonly)
-# [ ] Definition lists
-# [ ] Single line
-# [ ] Multi-line
+# [x] Definition lists
+# [x] Single line
+# [x] Multi-line
# [x] Fenced code blocks ```lang ```
# [ ] Tables
# [x] Links
@@ -282,6 +282,40 @@ list_started && /^\[[x ]\][ \t]/ {
_next()
}
+# Definition lists
+inside_definition_list == 2 && !emptyP1 && ! /^: / {
+ inside_definition_list = 0
+ P2 = P2 "</dl>"
+}
+inside_definition_list == 1 {
+ ## If empty, get ready to close dl
+ if ($0 !~ /[^ \t]/) {
+ ++inside_definition_list
+ }
+
+ ## If nonempty, we're continuing the dd
+ if (!empty0) {
+ not_paragraph = 1
+ }
+ else {
+ PNappnd("</dd>")
+ }
+}
+/^: / && !emptyP1 {
+ sub(/^<p>/, "", P1)
+ $0 = substr($0, 3)
+
+ P1 = "<dt>" P1 "</dt>"
+ if (!inside_definition_list) {
+ P1 = "<dl>" P1
+ }
+ $0 = "<dd>" $0
+
+ inside_definition_list = 1
+ not_paragraph = 1
+ not_paragraph_p1 = 1
+}
+
# Automatic links
/<[^ \t<>]+>/ {
## URL: <uri_scheme:...>
@@ -480,6 +514,10 @@ function __buffered_print() {
}
END {
+ if (inside_definition_list) {
+ PNappnd("</dl>")
+ }
+
print P2
while (P1_repeats > 0) {
print ""