aboutsummaryrefslogtreecommitdiff
path: root/cgit/filters/about.sh
blob: 9455ce74d2197e1144876825180e85181c4816ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env sh
# About content filter

set -eu

# TODO: Add toc links for headers in markdown
md_to_html() {
  echo '<div class="markdown">'
  md2html \
    --fpermissive-url-autolinks --fpermissive-www-autolinks \
    --flatex-math --ftasklists --ftables --funderline \
    --github -
  echo '</div>'
}

to_html() {
  case "$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')" in
    *.markdown|*.mdown|*.md|*.mkd) md_to_html ;;
    *.htm|*.html) exec cat ;;
    *) /usr/lib/cgit/filters/about-formatting.sh "$@" ;;
  esac
}

(to_html "$@" | /usr/lib/cgit/filters/ediblemonad/html-transform.py) || \
  (echo "<pre>Error rendering markdown</pre>" && cat)