diff --git a/site/source/apps/techblog/functions.py b/site/source/apps/techblog/functions.py
index ed1cb05..9cb6e3d 100644
--- a/site/source/apps/techblog/functions.py
+++ b/site/source/apps/techblog/functions.py
@@ -7,14 +7,20 @@
from pygments.lexers import get_lexer_by_name
from pygments.styles import get_style_by_name
from pygments.formatters import HtmlFormatter
+from pygments.util import ClassNotFound
def html_parser(value):
value = re.sub('(?is)(]*>|/]*/?>)', '', value).strip() # cleaning
if value:
formatter = HtmlFormatter(nowrap=True, lineseparator='
', style=get_style_by_name('native'))
def render_raw(match):
- lexer = get_lexer_by_name(match.groups()[0])
- return '%s
' % highlight(match.groups()[1], lexer, formatter)
+ syntax, data = match.groups()
+ try:
+ lexer = get_lexer_by_name(syntax)
+ return '%s
' % highlight(data, lexer, formatter)
+ except ClassNotFound:
+ return '%s
' % data
+
value = re.sub('(?is)]*language="(\w+)"[^>]*>(.*?)
]*>', render_raw, value)
return value