summaryrefslogtreecommitdiff
path: root/external
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-01-09 17:28:59 +0100
committerGeorg Brandl <georg@python.org>2014-01-09 17:28:59 +0100
commit5e18204f68d92d3926ea43b85bccc49dc3ab57d1 (patch)
treee8c9b843259df6eaab51647012a32f3d9a3140dc /external
parentf18a03187c7ddaec0330ece20bbfef1b116f31ac (diff)
parente6aa1888047f589f1f57e417702ed01683869214 (diff)
downloadpygments-5e18204f68d92d3926ea43b85bccc49dc3ab57d1.tar.gz
Merged in thomasvandoren/pygments-main (pull request #256)
Diffstat (limited to 'external')
-rwxr-xr-xexternal/autopygmentize9
-rw-r--r--external/markdown-processor.py28
2 files changed, 19 insertions, 18 deletions
diff --git a/external/autopygmentize b/external/autopygmentize
index 85c8dfd2..2df6d469 100755
--- a/external/autopygmentize
+++ b/external/autopygmentize
@@ -9,9 +9,8 @@
# This program can be used as a .lessfilter for the less pager to auto-color less's output
lexer=`pygmentize -N "$1"`
+file_common_opts="--brief --dereference --uncompress"
if [ "$lexer" = "text" ]; then
- file_common_opts="--brief --dereference --uncompress"
-
unset lexer
case `file --mime-type $file_common_opts "$1"` in
application/xml|image/svg+xml) lexer=xml;;
@@ -40,11 +39,13 @@ if [ "$lexer" = "text" ]; then
text/x-tcl) lexer=tcl;;
text/x-tex|text/x-texinfo) lexer=latex;; # FIXME: texinfo really needs its own lexer
- # Types that file outputs which pygmentize didn't support as of file 5.11, pygments 1.6rc1
+ # Types that file outputs which pygmentize didn't support as of file 5.14, pygments 1.6
# text/calendar
+ # text/inf
# text/PGP
# text/rtf
# text/texmacs
+ # text/vnd.graphviz
# text/x-bcpl
# text/x-info
# text/x-m4
@@ -53,7 +54,7 @@ if [ "$lexer" = "text" ]; then
esac
fi
-encoding=`file --brief --mime-encoding $file_common_opts "$1"`
+encoding=`file --mime-encoding $file_common_opts "$1"`
if [ -n "$lexer" ]; then
# FIXME: Specify input encoding rather than output encoding https://bitbucket.org/birkenfeld/pygments-main/issue/800
diff --git a/external/markdown-processor.py b/external/markdown-processor.py
index 12e64680..eef85b22 100644
--- a/external/markdown-processor.py
+++ b/external/markdown-processor.py
@@ -6,14 +6,9 @@
This fragment is a Markdown_ preprocessor that renders source code
to HTML via Pygments. To use it, invoke Markdown like so::
- from markdown import Markdown
+ import markdown
- md = Markdown()
- 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.
+ html = markdown.markdown(someText, extensions=[CodeBlockExtension()])
This uses CSS classes by default, so use
``pygmentize -S <some style> -f html > pygments.css``
@@ -25,7 +20,7 @@
some code
[/sourcecode]
- .. _Markdown: http://www.freewisdom.org/projects/python-markdown/
+ .. _Markdown: https://pypi.python.org/pypi/Markdown
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
@@ -40,17 +35,17 @@ INLINESTYLES = False
import re
-from markdown import TextPreprocessor
+from markdown.preprocessors import Preprocessor
+from markdown.extensions import Extension
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import get_lexer_by_name, TextLexer
-class CodeBlockPreprocessor(TextPreprocessor):
+class CodeBlockPreprocessor(Preprocessor):
- pattern = re.compile(
- r'\[sourcecode:(.+?)\](.+?)\[/sourcecode\]', re.S)
+ pattern = re.compile(r'\[sourcecode:(.+?)\](.+?)\[/sourcecode\]', re.S)
formatter = HtmlFormatter(noclasses=INLINESTYLES)
@@ -63,5 +58,10 @@ class CodeBlockPreprocessor(TextPreprocessor):
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, lines)
+ joined_lines = "\n".join(lines)
+ joined_lines = self.pattern.sub(repl, joined_lines)
+ return joined_lines.split("\n")
+
+class CodeBlockExtension(Extension):
+ def extendMarkdown(self, md, md_globals):
+ md.preprocessors.add('CodeBlockPreprocessor', CodeBlockPreprocessor(), '_begin')