Summary Files Commits Branches @commit @diff @stats
path: root / single.awk
diff options
context:
space:
mode:
1 files changed, 20 insertions, 1 deletions
-rw-r--r--single.awk21
diff --git a/single.awk b/single.awk
index 87e6734..47cb391 100644
--- a/single.awk
+++ b/single.awk
@@ -7,8 +7,8 @@
# [x] Headers (atx and setex)
# [x] Blockquotes
# [ ] Lists
-# [ ] Code blocks
# [ ] Horizontal rules
+# [x] Code blocks
# [ ] Span elements
# [ ] Links
# [ ] Inline
@@ -99,6 +99,25 @@ blockquote_level > 0 && empty0 {
}
/^>$/ { $0 = ""; not_paragraph = 1 }
+# Code blocks
+/^ / {
+ if (!inside_codeblock) {
+ P1 = P1 "<pre><code>"
+ inside_codeblock = 1
+ }
+ _next()
+}
+inside_codeblock && ! /^[ \t]*$/ {
+ if (emptyP1) {
+ P2 = P2 ORS "</code></pre>"
+ }
+ else {
+ P1 = P1 ORS "</code></pre>"
+ }
+ inside_codeblock = 0
+ emptyP1 = 1
+}
+
# Line break
/ $/ {
sub(/[ \t]* $/, "</br>")