--- a/hgkeeper.py Tue Apr 07 23:40:02 2020 -0500
+++ b/hgkeeper.py Wed Apr 08 02:41:19 2020 -0500
@@ -12,9 +12,11 @@
-from mercurial.hgweb import webutil
+from mercurial.hgweb import webutil, hgweb_mod from mercurial.hgweb.common import paritygen
templatefilter = registrar.templatefilter(filters)
@@ -200,6 +202,39 @@
+def repo_custom_templater(orig, self, req): + templater = orig(self, req) + templatekeyword = registrar.templatekeyword(templater._proc._defaults) + @templatekeyword(b'readme', requires={b'ctx', b'repo'}) + def readme(context, mapping): + ctx = context.resource(mapping, b'ctx') + # we iterate the files instead of a fileset, because we want to + # deterministically render readmes in the same order if there are more + # than one in a repository. With the fileset, we'd have to run through + # the generator and call .lower on each item again, and then we'd lose + # the ability to fallback if the prioritized one failed to render. + lower = filename.lower() + if lower == b'readme.md': + raw_utf8 = ctx[filename].data().decode('utf-8') + return cmarkgfm.markdown_to_html(raw_utf8).encode('utf-8') + if lower in [b'readme.txt', b'readme', b'readme.md']: + return ctx[filename].data().replace(b'\n', b'<br/>\n') - extensions.wrapfunction(webutil, "_diffstattmplgen", _diffstattmplgen)
- extensions.wrapfunction(webutil, "_diffsgen", _diffsgen)
+ extensions.wrapfunction(webutil, '_diffstattmplgen', _diffstattmplgen) + extensions.wrapfunction(webutil, '_diffsgen', _diffsgen) + # this nasty but amazingly working hack is from av6 + extensions.wrapfunction( + hgweb_mod.requestcontext,