summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/src/index.txt2
-rw-r--r--docs/src/moinmoin.txt38
-rw-r--r--external/moin-parser.py54
3 files changed, 72 insertions, 22 deletions
diff --git a/docs/src/index.txt b/docs/src/index.txt
index 97438d95..3676f6c7 100644
--- a/docs/src/index.txt
+++ b/docs/src/index.txt
@@ -46,6 +46,8 @@ Welcome to the Pygments documentation.
- `Using Pygments in ReST documents <rstdirective.txt>`_
+ - `Using Pygments with MoinMoin <moinmoin.txt>`_
+
- About Pygments
- `Changelog <changelog.txt>`_
diff --git a/docs/src/moinmoin.txt b/docs/src/moinmoin.txt
new file mode 100644
index 00000000..783c7f4d
--- /dev/null
+++ b/docs/src/moinmoin.txt
@@ -0,0 +1,38 @@
+.. -*- mode: rst -*-
+
+============================
+Using Pygments with MoinMoin
+============================
+
+From Pygments 0.7, the source distribution ships a `Moin`_ parser plugin that
+can be used to get Pygments highlighting in Moin wiki pages.
+
+To use it, copy the file `external/moin-parser.py` from the Pygments
+distribution to the `data/plugin/parser` subdirectory of your Moin instance,
+edit the options at the top of the file and give the file the name that the
+parser directive should have. For example, if you name the file ``code.py``, you
+can get a highlighted Python code sample with this Wiki markup::
+
+ {{{
+ #!code python
+ [...]
+ }}}
+
+where ``python`` is the Pygments name of the lexer to use.
+
+Additionally, if you set the ``ATTACHMENTS`` option to True, Pygments will also
+be called for all attachments for whose filenames there is no other parser
+registered.
+
+You are responsible for including CSS rules that will map the Pygments CSS
+classes to colors. You can output a stylesheet file with `pygmentize`, put it
+into the `htdocs` directory of your Moin instance and then include it in the
+`stylesheets` configuration option in the Moin config, e.g.::
+
+ stylesheets = [('screen', '/htdocs/pygments.css')]
+
+If you do not want to do that and are willing to accept larger HTML output, you
+can set the ``INLINESTYLES`` option to True.
+
+
+.. _Moin: http://moinmoin.wikiwikiweb.de/
diff --git a/external/moin-parser.py b/external/moin-parser.py
index 5d00be83..b84b2070 100644
--- a/external/moin-parser.py
+++ b/external/moin-parser.py
@@ -3,32 +3,33 @@
The Pygments MoinMoin Parser
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- This is a MoinMoin parser plugin that renders source code
- to HTML via Pygments.
+ This is a MoinMoin parser plugin that renders source code to HTML via
+ Pygments; you need Pygments 0.7 or newer for this parser to work.
- To use it, put it in the data/plugin/parser subdirectory of
- your Moin instance, and give it the name that the parser directive
- should have. For example, if you name the file ``code.py``, you
- can get a highlighted Python code sample with this Wiki markup::
+ To use it, set the options below to match your setup and put this file in
+ the data/plugin/parser subdirectory of your Moin instance, and give it the
+ name that the parser directive should have. For example, if you name the
+ file ``code.py``, you can get a highlighted Python code sample with this
+ Wiki markup::
{{{
#!code python
[...]
}}}
- Additionally, if you set ATTACHMENTS below to True, Pygments will
- also be called for all attachments for whose filenames there is no other
- parser registered.
+ Additionally, if you set ATTACHMENTS below to True, Pygments will also be
+ called for all attachments for whose filenames there is no other parser
+ registered.
- You are responsible for including CSS rules that will map the Pygments
- CSS classes to colors. You can output a stylesheet file with `pygmentize`,
- put it into the `htdocs` directory of your Moin instance and then include
- it in the `stylesheets` configuration option in the Moin config, e.g.::
+ You are responsible for including CSS rules that will map the Pygments CSS
+ classes to colors. You can output a stylesheet file with `pygmentize`, put
+ it into the `htdocs` directory of your Moin instance and then include it in
+ the `stylesheets` configuration option in the Moin config, e.g.::
stylesheets = [('screen', '/htdocs/pygments.css')]
- If you do not want to do that and are willing to accept slightly larger
- HTML output, you can set the INLINESTYLES option below to True.
+ If you do not want to do that and are willing to accept larger HTML
+ output, you can set the INLINESTYLES option below to True.
:copyright: 2007 by Georg Brandl.
:license: BSD, see LICENSE for more details.
@@ -41,9 +42,6 @@
# {{{ }}} blocks.
ATTACHMENTS = True
-# Set to False if you don't want to have line numbers in the output.
-LINENOS = True
-
# Set to True if you want inline CSS styles instead of classes
INLINESTYLES = False
@@ -51,12 +49,20 @@ INLINESTYLES = False
import sys
from pygments import highlight
-from pygments.util import ObjectNotFound
from pygments.lexers import get_lexer_by_name, get_lexer_for_filename, TextLexer
from pygments.formatters import HtmlFormatter
+from pygments.util import ObjectNotFound
+
+
+# wrap lines in <span>s so that the Moin-generated line numbers work
+class MoinHtmlFormatter(HtmlFormatter):
+ def wrap(self, source, outfile):
+ for line in source:
+ yield 1, '<span class="line">' + line[1] + '</span>'
-formatter = HtmlFormatter(linenos=LINENOS, noclasses=INLINESTYLES)
+htmlformatter = MoinHtmlFormatter(noclasses=INLINESTYLES)
textlexer = TextLexer()
+codeid = [0]
class Parser:
@@ -98,5 +104,9 @@ class Parser:
self.lexer = textlexer
def format(self, formatter):
- self.req.write(
- formatter.rawHTML(highlight(self.raw, self.lexer, formatter)))
+ codeid[0] += 1
+ id = "pygments_%s" % codeid[0]
+ w = self.req.write
+ w(formatter.code_area(1, id, start=1, step=1))
+ w(formatter.rawHTML(highlight(self.raw, self.lexer, htmlformatter)))
+ w(formatter.code_area(0, id))