aboutsummaryrefslogtreecommitdiff
path: root/cgit/filters
diff options
context:
space:
mode:
Diffstat (limited to 'cgit/filters')
-rwxr-xr-xcgit/filters/about.sh22
-rwxr-xr-xcgit/filters/html-transform.py18
2 files changed, 30 insertions, 10 deletions
diff --git a/cgit/filters/about.sh b/cgit/filters/about.sh
index e8554b0..9455ce7 100755
--- a/cgit/filters/about.sh
+++ b/cgit/filters/about.sh
@@ -1,5 +1,25 @@
#!/usr/bin/env sh
# About content filter
-/usr/lib/cgit/filters/about-formatting.sh "$@" | /usr/lib/cgit/filters/ediblemonad/html-transform.py
+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)
diff --git a/cgit/filters/html-transform.py b/cgit/filters/html-transform.py
index 9fc7aec..e12ffda 100755
--- a/cgit/filters/html-transform.py
+++ b/cgit/filters/html-transform.py
@@ -16,12 +16,12 @@ def is_relative_path(url):
if not url: return False
return not url.startswith("/") and not is_absolute_url(url)
-def linkify(text, make_link):
- url_pattern = r'(?<!\S)(https?://\S+?)([.,!?;:]?(?=\s|$))'
- def replace(m):
- url, trail = m.group(1), m.group(2)
- return make_link(url) + trail
- return re.sub(url_pattern, replace, text)
+# def linkify(text, make_link):
+# url_pattern = r'(?<!\S)(https?://\S+?)([.,!?;:]?(?=\s|$))'
+# def replace(m):
+# url, trail = m.group(1), m.group(2)
+# return make_link(url) + trail
+# return re.sub(url_pattern, replace, text)
class LinkRewriter(HTMLParser):
def __init__(self):
@@ -62,9 +62,9 @@ class LinkRewriter(HTMLParser):
self.output.append(f"</{tag}>")
def handle_data(self, data):
- data_with_links = linkify(data,
- lambda url: self._build_tag("a", [('href', url)]) + html.escape(url) + "</a>")
- self.output.append(data_with_links)
+ # data_with_links = linkify(data,
+ # lambda url: self._build_tag("a", [('href', url)]) + html.escape(url) + "</a>")
+ self.output.append(data)
def handle_entityref(self, name):
self.output.append(f"&{name};")