Klaus Demo klaus / fd0ee00
Some minor fixes Jonas Haag 3 years ago
5 changed file(s) with 10 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
5959 ('patch', '/<repo>/commit/<rev>.diff'),
6060 ('patch', '/<repo>/commit/<rev>.patch'),
6161 ('index', '/<repo>/'),
62 ('history', '/<repo>/history'),
6362 ('history', '/<repo>/tree/<rev>/'),
6463 ('history', '/<repo>/tree/<rev>/<path:path>'),
6564 ('download', '/<repo>/tarball/<rev>/'),
7373 )
7474
7575
76 def pygmentize(code, filename, render_markup, ctags=None, ctags_baseurl=None):
76 def highlight_or_render(code, filename, render_markup=True, ctags=None, ctags_baseurl=None):
7777 """Render code using Pygments, markup (markdown, rst, ...) using the
7878 corresponding renderer, if available.
7979
1616 {{ rendered_code }}
1717 {% endif %}
1818 {% endautoescape %}
19 <hr>
1920 {% endif %}
2021
2122 {% include 'history.inc.html' %}
237237 """
238238 git_dir = os.path.join(os.path.dirname(__file__), '..', '.git')
239239 try:
240 return check_output(
240 return force_unicode(check_output(
241241 ['git', 'log', '--format=%h', '-n', '1'],
242242 cwd=git_dir
243 ).strip()
243 ).strip())
244244 except OSError:
245245 # Either the git executable couldn't be found in the OS's PATH
246246 # or no ".git" directory exists, i.e. this is no "bleeding-edge" installation.
1818 CTAGS_CACHE = ctagscache.CTagsCache()
1919
2020 from klaus import markup
21 from klaus.highlighting import pygmentize
21 from klaus.highlighting import highlight_or_render
2222 from klaus.utils import parent_directory, subpaths, force_unicode, guess_is_binary, \
2323 guess_is_image, replace_dupes
2424
231231 else:
232232 self.context.update({
233233 'is_markup': markup.can_render(readme_filename),
234 'rendered_code': markup.render(readme_filename, readme_data),
234 'rendered_code': highlight_or_render(
235 force_unicode(readme_data),
236 force_unicode(readme_filename),
237 ),
235238 })
236239
237240
268271 else:
269272 ctags_args = {}
270273
271 return pygmentize(
274 return highlight_or_render(
272275 force_unicode(self.context['blob_or_tree'].data),
273276 self.context['filename'],
274277 render_markup,