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