Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/github/commands/rest2html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import codecs

from docutils import nodes
from docutils.parsers.rst import directives, roles
from docutils.parsers.rst.directives.body import CodeBlock
from docutils.parsers.rst.directives.body import CodeBlock, Directive
from docutils.core import publish_parts
from docutils.writers.html4css1 import Writer, HTMLTranslator

Expand All @@ -64,6 +64,18 @@ SETTINGS = {
'field_name_limit': 50,
}

default_highlight_language = None

class HighlightDirective(Directive):
required_arguments = 1
optional_arguments = 1
option_spec = {}
def run(self):
"""Track the default syntax highlighting language
"""
global default_highlight_language
default_highlight_language = self.arguments[0]
return []

class DoctestDirective(CodeBlock):
"""Render Sphinx 'doctest:: [group]' blocks as 'code:: python'
Expand Down Expand Up @@ -102,6 +114,8 @@ class GitHubHTMLTranslator(HTMLTranslator):
language = classes[1]
del classes[:]
self.body.append(self.starttag(node, 'pre', lang=language))
elif default_highlight_language is not None:
self.body.append(self.starttag(node, 'pre', lang=default_highlight_language))
else:
self.body.append(self.starttag(node, 'pre'))

Expand Down Expand Up @@ -172,6 +186,9 @@ def main():
# Render source code in Sphinx doctest blocks
directives.register_directive('doctest', DoctestDirective)

# Set default highlight language
directives.register_directive('highlight', HighlightDirective)

parts = publish_parts(text, writer=writer, settings_overrides=SETTINGS)
if 'html_body' in parts:
html = parts['html_body']
Expand Down