X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=modules%2Fmd;h=7831638685af3a2037fd1fb724e5beb5a1324d49;hb=394bc43d24de087865fa4eed1920411c1a6d7ebd;hp=717e395896036b651e82775b8f2a6254550c42aa;hpb=65d70f73b4e67c4c5768a15bb85d1dcfb1a66351;p=pinopress.git diff --git a/modules/md b/modules/md index 717e395..7831638 100755 --- a/modules/md +++ b/modules/md @@ -2,12 +2,18 @@ ## markdown to html module for pinopress ## based off https://github.com/stamby/md-to-html -# input $1 - filepath to html file +## usage: +## md [md_filepath] # remove document meta -/^-- \w+: .+$/d +## matches block of -- at top of file +1,/^([^-]|-[^-]|^$)/ { + /^([^-]|-[^-]|^$)/ !{ + /^-- ?/d + } +} -# html style comments +# html style comments (this will also work inside code blocks - unintended) //d # special html characters @@ -15,6 +21,40 @@ s/\&/\&\;/g s/\<\;/g s/>/\>\;/g +# code blocks +/^ *```/ { + x + # check if hold space contains READING + # this is to see if this is the first ``` we read or no + /^ *READING/ !{ + # if it is the first one, add READING to hold space + s/.*/READING/ + x + # write opening tag (also concat with next line) + N + s/.*\n(.*)/
\1/
+ b
+ }
+ # if its the second ```, we are done
+ # first clear hold
+ s/.*//
+ x
+ # then write closing tag
+ s/.*/<\/code><\/pre>/
+ b
+}
+
+# if we aren't reading ```, but hold space has READING in it
+# that means we are currently processing a block, just ignore and
+# keep going
+x
+/^ *READING/ {
+ x
+ b
+}
+x
+
+
# horizontal rule
s/^\s*-{3,}\s*$/
/
@@ -32,7 +72,7 @@ s/(^|[^\\~])~{2}([^~]+)~{2}([^~]|$)/\1\2<\/del>\3/g
s/!\[(.*)\]\((.*)\)//g
# links
-s/\[(.*)\]\((.*)\)/\2<\/a>/g
+s/\[(.*)\]\((.*)\)/\1<\/a>/g
s/\[(.*)\]/\1<\/a>/g
# headers
@@ -41,13 +81,19 @@ s/^#{5} (.*)/\1<\/h5>/
s/^#{4} (.*)/\1<\/h4>/
s/^#{3} (.*)/\1<\/h3>/
s/^#{2} (.*)/\1<\/h2>/
-s/^#} (.*)/\1<\/h1>/
-
-# code block
-
-# paragraphs
+s/^# (.*)/\1<\/h1>/
-# /./{H;$!d} ; x ; s/^/\n
/ ; s/$/\n<\/p>/
+# lists
+# paragraphs (blocks of text separated by one or more blank lines)
+/./ {
+ H
+ $!d
+}
+x
+/(^$|^\s+$)/ !{
+ s/^/\n
/
+ s/$/\n<\/p>/
+}