From 5b8eef7d05a6e34f50aa30a9fe05789d5d042142 Mon Sep 17 00:00:00 2001 From: wuyingren Date: Fri, 13 Oct 2017 22:27:07 +0800 Subject: [PATCH] modify for python3 (cherry picked from commit 04b37d3313fbc31f22cf26534257b43e2840bdc4) --- directives.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/directives.py b/directives.py index ac59d06..ef5c4db 100644 --- a/directives.py +++ b/directives.py @@ -1,7 +1,7 @@ -# Define a new directive `code-block` (aliased as `sourcecode`) that uses the -# `pygments` source highlighter to render code in color. +# Define a new directive `code-block` (aliased as `sourcecode`) that uses the +# `pygments` source highlighter to render code in color. # -# Incorporates code from the `Pygments`_ documentation for `Using Pygments in +# Incorporates code from the `Pygments`_ documentation for `Using Pygments in # ReST documents`_ and `Octopress`_. # # .. _Pygments: http://pygments.org/ @@ -51,8 +51,8 @@ class Pygments(Directive): # Construct cache filename cache_file = None - content_text = u'\n'.join(self.content) - cache_file_name = '%s-%s.html' % (lexer_name, hashlib.md5(content_text).hexdigest()) + content_text = u'\n'.join(self.content).encode('utf-8') + cache_file_name = u'%s-%s.html' % (lexer_name, hashlib.md5(content_text).hexdigest()) cached_path = os.path.join(PYGMENTS_CACHE_DIR, cache_file_name) # Look for cached version, otherwise parse @@ -94,4 +94,4 @@ class Pygments(Directive): return [nodes.raw('', code, format='html')] directives.register_directive('code-block', Pygments) -directives.register_directive('sourcecode', Pygments) \ No newline at end of file +directives.register_directive('sourcecode', Pygments)