Browse files

Fix syntax highlighter to get rid of the last <br/> tag that threw of…

…f line numbering.
  • Loading branch information...
1 parent 59b0c82 commit f89a8f6d715764d31626817acbad79fa7fd18ad7 @EnigmaCurry committed Mar 8, 2011
Showing with 3 additions and 1 deletion.
  1. +3 −1 blogofile/site_init/blog_filters/_filters/
@@ -98,8 +98,10 @@ def highlight_code(code, language, formatter):
lexer = pygments.lexers.get_lexer_by_name("text")
#Highlight with pygments
highlighted = pygments.highlight(code, lexer, formatter)
- #Replace newlines with breaks - markdown freaks out otherwise.
+ #Convert line endings to <br> tags:
highlighted = highlighted.replace("\n","<br/>")
+ #But get rid of the last <br> which throws off line numbers:
+ highlighted = "</pre></div>".join(highlighted.rsplit("</pre></div><br/>"))
#Surround the text with newlines so markdown etc parse properly:
highlighted = "\n\n{0}\n\n".format(highlighted)
return highlighted

0 comments on commit f89a8f6

Please sign in to comment.