Last active
August 17, 2023 15:54
-
-
Save amartos/fbfa82af4ff33823c90acbf23f7a3f0e to your computer and use it in GitHub Desktop.
Render both about page and tree's text blobs in cgit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# @file blob-formatting.sh | |
# @brief Format text blobs for CGit. | |
# @author Alexandre Martos | |
# @email contact@amartos.fr | |
# @year 2023 | |
# @copyright GPLv3 | |
# | |
# This script is designed to be used for both `about-filter` and | |
# `source-filter` in the CGit config file (see `cgitrc(5)`). | |
# | |
# The `about` tab behavior is the same as the `about-formatting.sh` filter | |
# script (part of this script is copied from it, other parts from the | |
# `syntax-highlighting.sh` script). | |
# For text blobs in the `tree` tab, the rendering is done as for the `about` | |
# tab, instead of displaying synctactically highlighted raw text. | |
# | |
# One caveat is that, in order to easily display text blobs without huge | |
# modifications of neither the CSS nor the source code, the blob table | |
# usually used to display the code is prematurely terminated. | |
# For both tabs, this means that *there will be* some dangling closing tags, | |
# either before or after the rendered HTML. As browsers should properly | |
# handle those (ie. not show them), this should not be a huge issue. | |
# | |
# The dependencies are the same as the `about-formatting.sh` and | |
# `syntax-highlighting.sh` scripts, plus those of org2html if you use it. | |
BASENAME="$1" | |
EXTENSION="${BASENAME##*.}" | |
NOTCODE="</code></pre></td></tr></tbody></table><style>table.blob{display:none}</style>" | |
[ -z "$EXTENSION" -o "$BASENAME" = "$EXTENSION" ] && EXTENSION=txt | |
[ "${BASENAME%%.*}" = "Makefile" ] && EXTENSION=mk | |
case "$EXTENSION" in | |
org|markdown|mdown|md|mkd|rst|htm|html|txt|[1-9]) echo "$NOTCODE"; ;; | |
*);; | |
esac | |
cd "$(dirname $0)/html-converters/" | |
case "$EXTENSION" in | |
# see https://github.com/amartos/cgit-org2html for Org conversion support. | |
#org) exec ./org2html "$1"; ;; # $1 for not overwriting cached files | |
markdown|mdown|md|mkd) exec ./md2html; ;; | |
rst) exec ./rst2html; ;; | |
[1-9]) exec ./man2html; ;; | |
html|html) exec cat; ;; | |
txt) exec ./txt2html; ;; | |
#*) exec highlight --force -f -I -X -S "$EXTENSION" 2>/dev/null; ;; #v2 | |
*) exec highlight --force -f -I -O xhtml -S "$EXTENSION" 2>/dev/null; ;; #v3 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment