all repos — markup @ f9028e34d5cd1e360c83a322ce57eef75cba7a4b

The code we use to render README.your_favorite_markup

Properly generate HTML for RST code blocks

We only look for `<pre>` blocks with a `lang` attribute when performing
syntax highlighting.

With these changes and docutils 0.9.0+ installed, syntax highlighting
for RST code blocks will be enabled on .com
Vicent Marti tanoku@gmail.com
Tue, 17 Jul 2012 02:42:26 +0200
commit

f9028e34d5cd1e360c83a322ce57eef75cba7a4b

parent

a2d25588f63846112ef0548431512747bdad8e00

1 files changed, 17 insertions(+), 2 deletions(-)

jump to
M lib/github/commands/rest2htmllib/github/commands/rest2html

@@ -17,7 +17,7 @@ import sys

import codecs from docutils.core import publish_parts -from docutils.writers.html4css1 import Writer +from docutils.writers.html4css1 import Writer, HTMLTranslator SETTINGS = { 'cloak_email_addresses': True,

@@ -26,8 +26,20 @@ 'raw_enabled': False,

'strip_comments': True, 'doctitle_xform': False, 'report_level': 5, + 'syntax_highlight' : 'none', + 'math_output' : 'latex' } +class GitHubHTMLTranslator(HTMLTranslator): + def visit_literal_block(self, node): + classes = node.attributes['classes'] + if len(classes) >= 2 and classes[0] == 'code': + language = classes[1] + del classes[:] + self.body.append(self.starttag(node, 'pre', lang=language)) + else: + super(self, node) + def main(): """ Parses the given ReST file or the redirected string input and returns the

@@ -43,7 +55,10 @@ return ''

except IndexError: # no filename given text = sys.stdin.read() - parts = publish_parts(text, writer=Writer(), settings_overrides=SETTINGS) + writer = Writer() + writer.translator_class = GitHubHTMLTranslator + + parts = publish_parts(text, writer=writer, settings_overrides=SETTINGS) if 'html_body' in parts: html = parts['html_body'] return html.encode('utf-8')