slightly shady paragraphs
[pinopress.git] / modules / md
index 3ce8979..7831638 100755 (executable)
@@ -13,6 +13,9 @@
     }
 }
 
+# html style comments (this will also work inside code blocks - unintended)
+/<!--(.*)-->/d
+
 # special html characters
 s/\&/\&amp\;/g
 s/</\&lt\;/g
@@ -27,8 +30,9 @@ s/>/\&gt\;/g
         # if it is the first one, add READING to hold space
         s/.*/READING/
         x
-        # write opening tag
-        s/.*/<code>/
+        # write opening tag (also concat with next line)
+        N
+        s/.*\n(.*)/<pre><code>\1/
         b
     }
     # if its the second ```, we are done
@@ -36,7 +40,8 @@ s/>/\&gt\;/g
     s/.*//
     x
     # then write closing tag
-    s/.*/<\\code>/
+    s/.*/<\/code><\/pre>/
+    b
 }
 
 # if we aren't reading ```, but hold space has READING in it
@@ -50,9 +55,6 @@ x
 x
 
 
-# html style comments
-/<!--(.*)-->/d
-
 # horizontal rule
 s/^\s*-{3,}\s*$/<hr\/>/
 
@@ -70,7 +72,7 @@ s/(^|[^\\~])~{2}([^~]+)~{2}([^~]|$)/\1<del>\2<\/del>\3/g
 s/!\[(.*)\]\((.*)\)/<img src="\2" alt="\1"\/>/g
 
 # links
-s/\[(.*)\]\((.*)\)/<a href="\1">\2<\/a>/g
+s/\[(.*)\]\((.*)\)/<a href="\2">\1<\/a>/g
 s/\[(.*)\]/<a href="\1">\1<\/a>/g
 
 # headers
@@ -79,11 +81,19 @@ s/^#{5} (.*)/<h5>\1<\/h5>/
 s/^#{4} (.*)/<h4>\1<\/h4>/
 s/^#{3} (.*)/<h3>\1<\/h3>/
 s/^#{2} (.*)/<h2>\1<\/h2>/
-s/^#} (.*)/<h1>\1<\/h1>/
+s/^# (.*)/<h1>\1<\/h1>/
 
-# paragraphs
-
-# /./{H;$!d} ; x ; s/^/\n<p>/ ; s/$/\n<\/p>/
+# lists
 
 
+# paragraphs (blocks of text separated by one or more blank lines)
+/./ {
+    H
+    $!d
+}
+x
+/(^$|^\s+$)/ !{
+    s/^/\n<p>/
+    s/$/\n<\/p>/
+}