md module
[pinopress.git] / modules / md
1 #!/bin/sed -Ef
2
3 ## markdown to html module for pinopress
4 ## based off https://github.com/stamby/md-to-html
5 # input $1 - filepath to html file
6
7 # special html characters
8 s/\&/\&amp\;/g
9 s/</\&lt\;/g
10 s/>/\&gt\;/g
11
12 # inline styles
13 s/(^|[^\\\*])\*{3}([^\*]+)\*{3}([^\*]|$)/\1<strong><em>\2<\/em><\/strong>\3/g
14 s/(^|[^\\_])_{3}([^_]+)_{3}([^_]|$)/\1<strong><em>\2<\/em><\/strong>\3/g
15 s/(^|[^\\\*])\*{2}([^\*]+)\*{2}([^\*]|$)/\1<strong>\2<\/strong>\3/g
16 s/(^|[^\\_])_{2}([^\_]+)_{2}([^_]|$)/\1<strong>\2<\/strong>\3/g
17 s/(^|[^\\\*])\*([^\*]+)\*([^\*]|$)/\1<em>\2<\/em>\3/g
18 s/(^|[^\\_])_([^_]+)_([^_]|$)/\1<em>\2<\/em>\3/g
19 s/(^|[^\\`])`([^`]+)`([^`]|$)/\1<code>\2<\/code>\3/g
20
21 # img
22 s/!\[(.*)\]\((.*)\)/<img src="\2" alt="\1"\/>/g
23
24 # links
25 s/\[(.*)\]\((.*)\)/<a href="\1">\2<\/a>/g
26 s/\[(.*)\]/<a href="\1">\1<\/a>/g
27
28 # headers
29 s/^#{4} (.*)/<h4>\1<\/h4>/
30 s/^#{3} (.*)/<h3>\1<\/h3>/
31 s/^#{2} (.*)/<h2>\1<\/h2>/
32 s/^#} (.*)/<h1>\1<\/h1>/
33
34 # html style comments
35