Mercurial > hg
changeset 26678:613d850cce53
highlight: consolidate duplicate code
I'm adding some logic in a future patch and this will make it so I only
have to add it once.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 14 Oct 2015 17:42:07 -0700 |
parents | e9b3d523f2e6 |
children | 0d93df4d1e44 |
files | hgext/highlight/__init__.py |
diffstat | 1 files changed, 10 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/highlight/__init__.py Tue Oct 13 14:06:51 2015 -0700 +++ b/hgext/highlight/__init__.py Wed Oct 14 17:42:07 2015 -0700 @@ -35,6 +35,12 @@ mctx = fileset.matchctx(ctx, subset=[fctx.path()], status=None) return fctx.path() in fileset.getset(mctx, tree) +def pygmentize(web, field, fctx, tmpl): + style = web.config('web', 'pygments_style', 'colorful') + expr = web.config('web', 'highlightfiles', "size('<5M')") + if checkfctx(fctx, expr): + highlight.pygmentize(field, fctx, style, tmpl) + def filerevision_highlight(orig, web, req, tmpl, fctx): mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) # only pygmentize for mimetype containing 'html' so we both match @@ -45,20 +51,16 @@ # can't clash with the file's content-type here in case we # pygmentize a html file if 'html' in mt: - style = web.config('web', 'pygments_style', 'colorful') - expr = web.config('web', 'highlightfiles', "size('<5M')") - if checkfctx(fctx, expr): - highlight.pygmentize('fileline', fctx, style, tmpl) + pygmentize(web, 'fileline', fctx, tmpl) + return orig(web, req, tmpl, fctx) def annotate_highlight(orig, web, req, tmpl): mt = ''.join(tmpl('mimetype', encoding=encoding.encoding)) if 'html' in mt: fctx = webutil.filectx(web.repo, req) - style = web.config('web', 'pygments_style', 'colorful') - expr = web.config('web', 'highlightfiles', "size('<5M')") - if checkfctx(fctx, expr): - highlight.pygmentize('annotateline', fctx, style, tmpl) + pygmentize(web, 'annotateline', fctx, tmpl) + return orig(web, req, tmpl) def generate_css(web, req, tmpl):