def block_code(self, text, lang): inject = False if lang and lang.endswith('+'): lang = lang[:-1] if lang in ('javascript', 'js', 'css', 'html'): inject = True if lang: lexer = get_lexer_by_name(lang, stripall=True) else: return '\n<pre><code>%s</code></pre>\n' % escape(text.strip()) if inject: tpl = '\n%s\n' if lang == 'javascript' or lang == 'js': tpl = '\n<script>\n%s</script>\n' elif lang == 'css': tpl = '\n<style>\n%s</style>\n' html = tpl % text else: html = '' formatter = HtmlFormatter( noclasses=settings.get('highlight_inline', False), linenos=settings.get('highlight_linenos', False), ) html += highlight(text, lexer, formatter) return html
def block_code(self, text, lang): if lang: lexer = get_lexer_by_name(lang, stripall=True) else: return "\n<pre><code>%s</code></pre>\n" % escape(text.strip()) formatter = HtmlFormatter( noclasses=settings.get("highlight_inline", False), linenos=settings.get("highlight_linenos", False) ) return highlight(text, lexer, formatter)
key = self._plain_text(keyNode) key = key.lower().rstrip(':') valueNode = node.lastChild tag = valueNode.firstChild.nodeName if 'ul' == tag or 'ol' == tag: value = [] for node in valueNode.getElementsByTagName('li'): value.append(self._plain_text(node)) else: value = self._plain_text(valueNode) return key, value INLINESTYLES = settings.get('highlight_inline', False) DEFAULT = HtmlFormatter(noclasses=INLINESTYLES) VARIANTS = { 'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True), } class Pygments(Directive): """ Source code syntax hightlighting. """ required_arguments = 1 optional_arguments = 0 final_argument_whitespace = True option_spec = dict([(key, directives.flag) for key in VARIANTS]) has_content = True
key = self._plain_text(keyNode) key = key.lower().rstrip(":") valueNode = node.lastChild tag = valueNode.firstChild.nodeName if "ul" == tag or "ol" == tag: value = [] for node in valueNode.getElementsByTagName("li"): value.append(self._plain_text(node)) else: value = self._plain_text(valueNode) return key, value INLINESTYLES = settings.get("highlight_inline", False) DEFAULT = HtmlFormatter(noclasses=INLINESTYLES) VARIANTS = {"linenos": HtmlFormatter(noclasses=INLINESTYLES, linenos=True)} class Pygments(Directive): """ Source code syntax hightlighting. """ required_arguments = 1 optional_arguments = 0 final_argument_whitespace = True option_spec = dict([(key, directives.flag) for key in VARIANTS]) has_content = True def run(self):