If you publish your git repositories via cgit
, you might want to link to Markdown files like you did on GitHub. By default this doesn’t work, though: the Markdown filter only applies to the About section. All the other Markdown files are simply highlighted but not rendered.
This is what we want:
But this is the default:
This page hacks the two solutions together and will make your code eyes cry. I’m sorry.
Your /etc/cgitrc
gets a line like the following:
source-filter=/usr/lib/cgit/filters/syntax-highlighting-or-markdown.py
And the content of this file:
#!/usr/bin/env python3 # This script uses Pygments and Python3. You must have both installed # for this to work. # # http://pygments.org/ # http://python.org/ # # It may be used with the source-filter or repo.source-filter settings # in cgitrc. # # The following environment variables can be used to retrieve the # configuration of the repository for which this script is called: # CGIT_REPO_URL ( = repo.url setting ) # CGIT_REPO_NAME ( = repo.name setting ) # CGIT_REPO_PATH ( = repo.path setting ) # CGIT_REPO_OWNER ( = repo.owner setting ) # CGIT_REPO_DEFBRANCH ( = repo.defbranch setting ) # CGIT_REPO_SECTION ( = section setting ) # CGIT_REPO_CLONE_URL ( = repo.clone-url setting ) import sys import io import types import markdown from pygments import highlight from pygments.util import ClassNotFound from pygments.lexers import TextLexer from pygments.lexers import MarkdownLexer from pygments.lexers import guess_lexer from pygments.lexers import guess_lexer_for_filename from pygments.formatters import HtmlFormatter sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') data = sys.stdin.read() filename = sys.argv[1] formatter = HtmlFormatter(style='pastie') try: lexer = guess_lexer_for_filename(filename, data) except ClassNotFound: # check if there is any shebang if data[0:2] == '#!': try: lexer = guess_lexer(data) except ClassNotFound: lexer = TextLexer() else: lexer = TextLexer() except TypeError: lexer = TextLexer() if isinstance(lexer, MarkdownLexer): # based on html-converters/md2html sys.stdout.write('''''') sys.stdout.write("
#cgit #Git #Markdown #Programming Comments(Please contact me if you want to remove your comment.) ⁂ I might yet get to replace all the links in Gridmapper! => Gridmapper – Alex Schroeder 2018-06-11 21:02 UTC I also added the TOC extension to markdown.markdownFromFile( output_format="html5", extensions=[ "markdown.extensions.fenced_code", "markdown.extensions.codehilite", "markdown.extensions.tables", "markdown.extensions.toc"], extension_configs={"markdown.extensions.codehilite":{"css_class":"highlight"}}) – Alex Schroeder 2018-06-13 07:05 UTC Thank you very much! – satmd 2019-01-28 10:57 UTC
=> legit This content has been proxied by September (3851b). |