diff --git a/docs/index.rst b/docs/index.rst index 31fa423..c5b9543 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -66,19 +66,22 @@ used to escape the HTML): import houdini as h import misaka as m from pygments import highlight - from pygments.formatters import HtmlFormatter + from pygments.formatters import HtmlFormatter, ClassNotFound from pygments.lexers import get_lexer_by_name class HighlighterRenderer(m.HtmlRenderer): def blockcode(self, text, lang): - if not lang: - return '\n
{}
\n'.format( - h.escape_html(text.strip())) - - lexer = get_lexer_by_name(lang, stripall=True) - formatter = HtmlFormatter() - - return highlight(text, lexer, formatter) + try: + lexer = get_lexer_by_name(lang, stripall=True) + except ClassNotFound: + lexer = None + + if lexer: + formatter = HtmlFormatter() + return highlight(text, lexer, formatter) + # default + return '\n
{}
\n'.format( + h.escape_html(text.strip())) renderer = HighlighterRenderer() md = m.Markdown(renderer, extensions=('fenced-code',))