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