X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;ds=inline;f=modules%2Fmd;h=0decfa6888a4f98014ab62b8a2a1f9fec4a0d794;hb=refs%2Fheads%2Fmaster;hp=b2bc03869c59c48a4b4bc2a1c21d8f718fd92d72;hpb=0edc18c28ae23dd6e5af18bbcf8725848f7b7963;p=pinopress.git diff --git a/modules/md b/modules/md index b2bc038..0decfa6 100755 --- a/modules/md +++ b/modules/md @@ -2,13 +2,62 @@ ## 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 +## matches block of -- at top of file +1,/^([^-]|-[^-]|^$)/ { + /^([^-]|-[^-]|^$)/ !{ + /^-- ?/d + } +} + +# html style comments (this will also work inside code blocks - unintended) +//d # special html characters 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*$/
/
+
# inline styles
s/(^|[^\\\*])\*{3}([^\*]+)\*{3}([^\*]|$)/\1\2<\/em><\/strong>\3/g
s/(^|[^\\_])_{3}([^_]+)_{3}([^_]|$)/\1\2<\/em><\/strong>\3/g
@@ -17,19 +66,34 @@ s/(^|[^\\_])_{2}([^\_]+)_{2}([^_]|$)/\1\2<\/strong>\3/g
s/(^|[^\\\*])\*([^\*]+)\*([^\*]|$)/\1\2<\/em>\3/g
s/(^|[^\\_])_([^_]+)_([^_]|$)/\1\2<\/em>\3/g
s/(^|[^\\`])`([^`]+)`([^`]|$)/\1\2<\/code>\3/g
+s/(^|[^\\~])~{2}([^~]+)~{2}([^~]|$)/\1\2<\/del>\3/g
-# img
+# images
s/!\[(.*)\]\((.*)\)//g
# links
-s/\[(.*)\]\((.*)\)/\2<\/a>/g
+s/\[(.*)\]\((.*)\)/\1<\/a>/g
s/\[(.*)\]/\1<\/a>/g
# headers
+s/^#{6} (.*)/\1<\/h6>/
+s/^#{5} (.*)/\1<\/h5>/
s/^#{4} (.*)/\1<\/h4>/
s/^#{3} (.*)/\1<\/h3>/
s/^#{2} (.*)/\1<\/h2>/
-s/^#} (.*)/\1<\/h1>/
+s/^# (.*)/\1<\/h1>/
+
+# lists
+
-# html style comments
+# paragraphs (blocks of text separated by one or more blank lines)
+/./ {
+ H
+ $!d
+}
+x
+/^\s*$/ !{
+ s/^/\n
/
+ s/$/\n<\/p>/
+}