basic building
[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 # remove document meta
8 /^-- \w+: .+$/d
9
10 # html style comments
11 /<!--(.*)-->/d
12
13 # special html characters
14 s/\&/\&amp\;/g
15 s/</\&lt\;/g
16 s/>/\&gt\;/g
17
18 # horizontal rule
19 s/^\s*-{3,}\s*$/<hr\/>/
20
21 # inline styles
22 s/(^|[^\\\*])\*{3}([^\*]+)\*{3}([^\*]|$)/\1<strong><em>\2<\/em><\/strong>\3/g
23 s/(^|[^\\_])_{3}([^_]+)_{3}([^_]|$)/\1<strong><em>\2<\/em><\/strong>\3/g
24 s/(^|[^\\\*])\*{2}([^\*]+)\*{2}([^\*]|$)/\1<strong>\2<\/strong>\3/g
25 s/(^|[^\\_])_{2}([^\_]+)_{2}([^_]|$)/\1<strong>\2<\/strong>\3/g
26 s/(^|[^\\\*])\*([^\*]+)\*([^\*]|$)/\1<em>\2<\/em>\3/g
27 s/(^|[^\\_])_([^_]+)_([^_]|$)/\1<em>\2<\/em>\3/g
28 s/(^|[^\\`])`([^`]+)`([^`]|$)/\1<code>\2<\/code>\3/g
29 s/(^|[^\\~])~{2}([^~]+)~{2}([^~]|$)/\1<del>\2<\/del>\3/g
30
31 # images
32 s/!\[(.*)\]\((.*)\)/<img src="\2" alt="\1"\/>/g
33
34 # links
35 s/\[(.*)\]\((.*)\)/<a href="\1">\2<\/a>/g
36 s/\[(.*)\]/<a href="\1">\1<\/a>/g
37
38 # headers
39 s/^#{6} (.*)/<h6>\1<\/h6>/
40 s/^#{5} (.*)/<h5>\1<\/h5>/
41 s/^#{4} (.*)/<h4>\1<\/h4>/
42 s/^#{3} (.*)/<h3>\1<\/h3>/
43 s/^#{2} (.*)/<h2>\1<\/h2>/
44 s/^#} (.*)/<h1>\1<\/h1>/
45
46 # code block
47
48 # paragraphs
49
50 # /./{H;$!d} ; x ; s/^/\n<p>/ ; s/$/\n<\/p>/
51
52
53