grim/hgwebplus

37c96b2be81d
Parents 36b6003e8b84
Children f2ce0e4ea6ac
Move to mistune 2.0.0a4 and enable a bunch of plugins
  • +1 -1
    setup.py
  • +23 -6
    src/hgwebplus.py
  • --- a/setup.py Sun May 17 03:09:49 2020 -0500
    +++ b/setup.py Sun May 17 04:27:45 2020 -0500
    @@ -15,7 +15,7 @@
    },
    package_data={'mercurial.templates': ['static/*']},
    install_requires=[
    - 'mistune',
    + 'mistune==2.0.0a4',
    # skip mercurial because it might be installed on the system
    # 'mercurial',
    ],
    --- a/src/hgwebplus.py Sun May 17 03:09:49 2020 -0500
    +++ b/src/hgwebplus.py Sun May 17 04:27:45 2020 -0500
    @@ -33,6 +33,9 @@
    import mistune
    +from mistune.directives import DirectiveToc
    +
    +
    filters = {}
    templatefilter = registrar.templatefilter(filters)
    @@ -249,11 +252,11 @@
    ctx = context.resource(mapping, b'ctx')
    - class Renderer(mistune.Renderer):
    - def image(self, src, title, alt_text):
    - real_src = 'rawfile/%s/%s' % (ctx.rev(), src)
    - real_title = title or ''
    - return '<img src="%s" alt="%s">%s</img>' % (real_src, alt_text, real_title)
    + class Renderer(mistune.HTMLRenderer):
    + def image(self, src, alt, title):
    + src = 'rawfile/%s/%s' % (ctx.rev(), src)
    +
    + return super().image(src, alt, title)
    # we iterate the files instead of a fileset, because we want to
    # deterministically render readmes in the same order if there are more
    @@ -264,7 +267,21 @@
    lower = filename.lower()
    if lower in [b'readme.txt', b'readme', b'readme.md']:
    raw_utf8 = ctx[filename].data().decode('utf-8')
    - return mistune.markdown(raw_utf8, renderer=Renderer()).encode('utf-8')
    +
    + plugins = [
    + DirectiveToc(),
    + 'footnotes',
    + 'strikethrough',
    + 'table',
    + 'url',
    + ]
    +
    + markdown = mistune.create_markdown(
    + renderer=Renderer(),
    + plugins=plugins,
    + )
    +
    + return markdown(raw_utf8).encode('utf-8')
    return ""