grim/hgwebplus

Parents f3c0a1e7bf41
Children 36b6003e8b84
Switch to the mistune markdown renderer to fix images. Fixes HGWEBPLUS-1
  • +4 -0
    ChangeLog
  • +2 -2
    setup.py
  • +8 -2
    src/hgwebplus.py
  • --- a/ChangeLog Sun May 17 02:32:02 2020 -0500
    +++ b/ChangeLog Sun May 17 02:41:51 2020 -0500
    @@ -1,3 +1,7 @@
    +0.5.0:
    + * Switched to mistune for markdown rendering to fix images. Fixes
    + HGWEBPLUS-1.
    +
    0.4.0: (2020-05-04)
    * Added a ChangeLog.
    * Always make the line numbers available in the diff template.
    --- a/setup.py Sun May 17 02:32:02 2020 -0500
    +++ b/setup.py Sun May 17 02:41:51 2020 -0500
    @@ -3,7 +3,7 @@
    setup(
    name='hgwebplus',
    - version='0.4.0',
    + version='0.5.0',
    author='Gary Kramlich',
    author_email='grim@reaperworld.com',
    url='https://keep.imfreedom.org/grim/hgwebplus',
    @@ -15,7 +15,7 @@
    },
    package_data={'mercurial.templates': ['static/*']},
    install_requires=[
    - 'cmarkgfm',
    + 'mistune',
    # skip mercurial because it might be installed on the system
    # 'mercurial',
    ],
    --- a/src/hgwebplus.py Sun May 17 02:32:02 2020 -0500
    +++ b/src/hgwebplus.py Sun May 17 02:41:51 2020 -0500
    @@ -31,7 +31,7 @@
    from mercurial.hgweb import webutil, hgweb_mod
    from mercurial.hgweb.common import paritygen
    -import cmarkgfm
    +import mistune
    filters = {}
    templatefilter = registrar.templatefilter(filters)
    @@ -249,6 +249,12 @@
    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)
    +
    # 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
    @@ -258,7 +264,7 @@
    lower = filename.lower()
    if lower in [b'readme.txt', b'readme', b'readme.md']:
    raw_utf8 = ctx[filename].data().decode('utf-8')
    - return cmarkgfm.markdown_to_html(raw_utf8).encode('utf-8')
    + return mistune.markdown(raw_utf8, renderer=Renderer()).encode('utf-8')
    return ""