]> git.plutz.net Git - shellwiki/blob - themes/simplemde.sh
Merge commit '6bc502434737d7f08379e79b94fc6fda424ef779'
[shellwiki] / themes / simplemde.sh
1 #!/bin/sh
2
3 # Copyright 2023 Paul Hänsch
4
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8
9 # THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15 # IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17 . "$_EXEC/themes/default.sh"
18
19 theme_page(){
20   local page="$1" title="$2" editor="false"
21   [ "${title#Editor: }" != "$title" ] && editor="true"
22   title="$(HTML "${title:-"${PAGE_TITLE:-"${page}"}"}")"
23
24   # Important! Web Server response including newline
25   printf "%s\r\n" "Content-Type: text/html; charset=utf-8" ""
26
27   cat <<-EOF
28         <!DOCTYPE HTML>
29         <html${LANGUAGE:+ lang=\"${LANGUAGE}\"}><head>
30           $(theme_head
31             $editor \
32             && printf '<link rel="stylesheet" type="text/css" href="%s">' \
33                       "$_BASE/%5B.%5D/themes/simplemde/simplemde.css" \
34                       "$_BASE/%5B.%5D/themes/simplemde/fakeawesome.css" \
35             && printf '<script src="%s"></script>' \
36                       "$_BASE/%5B.%5D/themes/simplemde/simplemde.js"
37           )
38           <title>${title}</title>
39         </head><body id="$(HTML "${PATH_INFO}")">
40           $(theme_header)
41           <main>
42             $(theme_pagemenu)
43             $(if [ "$page" = '-' ]; then
44                 cat
45               else
46                 printf '<article>'
47                 wiki "$page"
48                 printf '</article>'
49             fi)
50           </main>
51           $($editor \
52             && printf %s '<script>var simplemde = new SimpleMDE({
53                           autoDownloadFontAwesome: false,
54                           spellChecker: false,
55                           forceSync: true, 
56                           tabSize: 8,
57                           hideIcons: ["heading", "side-by-side", "fullscreen", "guide"],
58                           showIcons: ["bold", "italic", "strikethrough", "heading-1", "heading-2", "heading-3",
59                                       "code", "unordered-list", "ordered-list", "table"],
60                           insertTexts: {
61                             horizontalRule: ["", "\n-----\n"],
62                             image: ["![alt-text](", ".jpg)"],
63                             link: ["[", "](/)"],
64                             table: ["", "\n| Col 1 | Col 2 | Col 3 |\n|------:|:-----:|:------|\n| Text  | Text  | Text  |\n"]
65                           }
66                         });</script>'
67             theme_footer
68           )
69         </body></html>
70         EOF
71 }