[PATCH PoC] extensions: PoC readme extension for hgweb

Yuya Nishihara yuya at tcha.org
Fri May 25 10:13:04 EDT 2018


On Fri, 25 May 2018 14:12:03 +0200, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6 at dwimlabs.net>
> # Date 1527241096 -7200
> #      Fri May 25 11:38:16 2018 +0200
> # Node ID 8133b5cebe9bcc24d91a0e5dfe2b191a11e4bb44
> # Parent  6f67bfe4b82f1d0f1e11a7092262f961c49fdac9
> extensions: PoC readme extension for hgweb
> 
> Here's a prototype extension that implements a feature that everybody expects
> from a code hosting solution nowadays: rendering README files.
> 
> This extension uses pandoc to convert files from various formats to HTML to
> display on summary page. It wraps only summary web command (so no README while
> browsing files, for example), then it tries to match files using a configurable
> fileset, and provided that's successful, it runs the first found file through
> pandoc. Caching is in place to not require too much calls to subprocess.
> Because pandoc can highlight code using pygments-compatible CSS classes, this
> extension also injects a link to pygments styles when highlight extension is
> loaded.
> 
> A couple of the more obvious problems:
> - Only works on summary page, so no way to go browse around the repo and see
>   the appropriate README from the current subdirectory.
> - Pandoc is primarily built for enabling interactivity (just look at all those
>   HTML5 presentation formats full of JS), but doesn't have any config knob to
>   disable JS entirely. This might be a security problem.
> 
> This extension takes heavy inspiration from highlight extension (in wrapping a
> web command and not requiring code in core Mercurial), but maybe it's not such
> a good idea. I'm thinking about making something like {readme} keyword in core
> that outputs nothing, but is backed by a nice accessible function that
> extensions can override. This way it easily can work on any page in hgweb, if
> needed.

Yeah, how highlight works is horrible. It hooks a filter function to
replace a given content with next(coloriter). The colorize filter is not
a filter at all.

Maybe we can add {readme} keyword in core, and add render filter/function
as the extension point? The core implementation of "render" will do &-escape
and wrap the content with <pre></pre>.


More information about the Mercurial-devel mailing list