3 ## markdown to html module for pinopress
4 ## based off https://github.com/stamby/md-to-html
9 ## matches block of -- at top of file
10 1,/^([^-]|-[^-]|^$)/ {
16 # html style comments (this will also work inside code blocks - unintended)
19 # special html characters
27 # check if hold space contains READING
28 # this is to see if this is the first ``` we read or no
30 # if it is the first one, add READING to hold space
33 # write opening tag (also concat with next line)
35 s/.*\n(.*)/<pre><code>\1/
38 # if its the second ```, we are done
42 # then write closing tag
47 # if we aren't reading ```, but hold space has READING in it
48 # that means we are currently processing a block, just ignore and
59 s/^\s*-{3,}\s*$/<hr\/>/
62 s/(^|[^\\\*])\*{3}([^\*]+)\*{3}([^\*]|$)/\1<strong><em>\2<\/em><\/strong>\3/g
63 s/(^|[^\\_])_{3}([^_]+)_{3}([^_]|$)/\1<strong><em>\2<\/em><\/strong>\3/g
64 s/(^|[^\\\*])\*{2}([^\*]+)\*{2}([^\*]|$)/\1<strong>\2<\/strong>\3/g
65 s/(^|[^\\_])_{2}([^\_]+)_{2}([^_]|$)/\1<strong>\2<\/strong>\3/g
66 s/(^|[^\\\*])\*([^\*]+)\*([^\*]|$)/\1<em>\2<\/em>\3/g
67 s/(^|[^\\_])_([^_]+)_([^_]|$)/\1<em>\2<\/em>\3/g
68 s/(^|[^\\`])`([^`]+)`([^`]|$)/\1<code>\2<\/code>\3/g
69 s/(^|[^\\~])~{2}([^~]+)~{2}([^~]|$)/\1<del>\2<\/del>\3/g
72 s/!\[(.*)\]\((.*)\)/<img src="\2" alt="\1"\/>/g
75 s/\[(.*)\]\((.*)\)/<a href="\2">\1<\/a>/g
76 s/\[(.*)\]/<a href="\1">\1<\/a>/g
79 s/^#{6} (.*)/<h6>\1<\/h6>/
80 s/^#{5} (.*)/<h5>\1<\/h5>/
81 s/^#{4} (.*)/<h4>\1<\/h4>/
82 s/^#{3} (.*)/<h3>\1<\/h3>/
83 s/^#{2} (.*)/<h2>\1<\/h2>/
84 s/^# (.*)/<h1>\1<\/h1>/
89 # paragraphs (blocks of text separated by one or more blank lines)