summaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorHorst Gutmann <zerok@zerokspot.com>2008-06-18 21:21:45 +0200
committerHorst Gutmann <zerok@zerokspot.com>2008-06-18 21:21:45 +0200
commit452f2b7a72d857e25edee36a5131284281d1c828 (patch)
tree7bbac614363c7b37dda0d863b1309c3dc1b9fb19 /external
parent925010b94230ff6d1cbf5cf974402682162579a6 (diff)
downloadpygments-452f2b7a72d857e25edee36a5131284281d1c828.tar.gz
Some fixes to the markdown-processor
Updated most of the information to Markdown 1.7 and moved the code up the preprocessor chain to become a TextPreprocessor in order to avoid unnecessary paragraphs in the final HTML output. The extra '\n' -> '<br />' replacement is necessary to also allow newlines in the sourcecode without splitting the output HTML into multiple code segments.
Diffstat (limited to 'external')
-rw-r--r--external/markdown-processor.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/external/markdown-processor.py b/external/markdown-processor.py
index 94d02576..e7c8d6f9 100644
--- a/external/markdown-processor.py
+++ b/external/markdown-processor.py
@@ -9,8 +9,8 @@
from markdown import Markdown
md = Markdown()
- md.preprocessors.insert(0, CodeBlockPreprocessor())
- markdown = md.__str__
+ md.textPreprocessors.insert(0, CodeBlockPreprocessor())
+ html = md.convert(someText)
markdown is then a callable that can be passed to the context of
a template and used in that template, for example.
@@ -40,14 +40,14 @@ INLINESTYLES = False
import re
-from markdown import Preprocessor
+from markdown import TextPreprocessor
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name, TextLexer
-class CodeBlockPreprocessor(Preprocessor):
+class CodeBlockPreprocessor(TextPreprocessor):
pattern = re.compile(
r'\[sourcecode:(.+?)\](.+?)\[/sourcecode\]', re.S)
@@ -60,8 +60,8 @@ class CodeBlockPreprocessor(Preprocessor):
lexer = get_lexer_by_name(m.group(1))
except ValueError:
lexer = TextLexer()
- code = highlight(m.group(2), lexer, formatter)
- code = code.replace('\n\n', '\n&nbsp;\n')
+ code = highlight(m.group(2), lexer, self.formatter)
+ code = code.replace('\n\n', '\n&nbsp;\n').replace('\n', '<br />')
return '\n\n<div class="code">%s</div>\n\n' % code
return self.pattern.sub(
- repl, '\n'.join(lines)).split('\n')
+ repl, lines) \ No newline at end of file