docbook-apps

  • 1.  syntax highlighting with xslt2/pygments/jython/saxon

    Posted 10-29-2011 21:43
    I am trying to get syntax hightlighting working as described in

    http://norman.walsh.name/2011/08/31/xsltPygments

    which was a response to a mail thread:

    http://lists.oasis-open.org/archives/docbook-apps/201108/msg00132.html
    respectively for the beginning of the thread:
    http://lists.oasis-open.org/archives/docbook-apps/201108/msg00079.html

    i. e. I'd like to

    * use the xslt2 stylesheets

    * have pygments do the syntax highlighting
    (instead of xslthl as described e. g. in
    http://www.sagehill.net/docbookxsl/SyntaxHighlighting.html
    or http://xmlguru.cz/2006/07/docbook-syntax-highlighting)

    * by calling jython directly from saxonb/saxonhe
    (there are some instructions to use pygments with
    docbook at http://lunaryorn.de/articles/docbook_pygments.html
    but according to Norman's blog there should be an easier
    way to call jython directly from saxon)

    What I have now is this:

    * I can use the xslt2 stylesheets in my toolchain like this

    java \
    -cp "/opt/saxonhe/saxon9he.jar:/opt/dbk/xslt2/lib/docbook-xsl2-saxon.jar" \
    net.sf.saxon.Transform \
    -s:myfile.dbk \
    -xsl:fo-xslt2.xsl \
    -o:myfile.fo \
    -xi:on \
    -ext:on \
    use.extensions=1 \
    fop1.extensions=1

    fo-xslt2.xsl is my customization layer stylesheet
    which besides my customizations imports the main xslt2 stylesheet
    <xsl:import href="/opt/dbk/xslt2/xslt/base/fo/docbook.xsl" />
    in this case for fo output, but it works equally well with html

    /opt/saxonhe ist just the path where I have put my saxonhe
    and my xslt2 stylesheets live in /opt/dbk

    * This works equally well for me if I use the (debian packaged)
    saxonb-xslt, in that case my classpath is
    "/usr/share/java/saxonb.jar:/opt/dbk/xslt2/lib/docbook-xsl2-saxon.jar"

    * Now I have installed jython as a debian package (I am on wheezy)

    # aptitude install jython

    * and installed pygments within jython
    by first getting easy_install working in jython

    # wet -nd http://peak.telecommunity.com/dist/ez_setup.py
    # jython ez_setup.py

    and then easy installing

    # /usr/share/jython/bin/easy_install pygments

    had to call it several times (don't know why),
    but it finally installed pygments, now I can call

    $ jython
    blahblah...
    >>> import pygments

    * Now I understand that I have to add jython.jar to my classpath
    above and have to initialize saxon (-init:docbook.Initializer)

    java \
    -cp "/opt/saxonhe/saxon9he.jar:/opt/dbk/xslt2/lib/docbook-xsl2-saxon.jar:/usr/share/java/jython.jar" \
    net.sf.saxon.Transform \
    -init:docbook.Initializer \
    -s:myfile.dbk \
    -xsl:fo-xslt2.xsl \
    -o:myfile.fo \
    -xi:on \
    -ext:on \
    use.extensions=1 \
    fop1.extensions=1

    OK, my toolchain still works, but no highlighting yet

    * I understand that saxon should call some jython script that
    contains at least something like

    from pygments.formatters import HtmlFormatter
    print HtmlFormatter().get_style_defs('.highlight')

    (or I guess something similar for fo) - but how do I tell saxonb/saxonhe
    to actually call this jython script?

    * Also there is mention of some python.path setting in ~/.jython
    what does that look exactely (the path to the script maybe)?

    * I use neither Saxon PE or EE, but saxonb and/or saxonhe
    so I guess I don't have to set

    <resources>
    <extensionFunction>org.docbook.extensions.xslt20.Cwd</extensionFunction>
    <extensionFunction>org.docbook.extensions.xslt20.ImageIntrinsics</extensionFunction>
    <extensionFunction>org.docbook.extensions.xslt20.Pygmenter</extensionFunction>
    </resources>


    Anyway, thanks in advance.

    -Andreas






  • 2.  RE: [docbook-apps] syntax highlighting with xslt2/pygments/jython/saxon

    Posted 11-02-2011 18:54
    | -----Original Message-----
    | From: Andreas Reuleaux

    | java \
    | -cp
    |
    "/opt/saxonhe/saxon9he.jar:/opt/dbk/xslt2/lib/docbook-xsl2-saxon.jar:/usr/sh
    are/java/jython.jar" net.sf.saxon.Transform \
    | -init:docbook.Initializer \
    | -s:myfile.dbk \
    | -xsl:fo-xslt2.xsl \
    | -o:myfile.fo \
    | -xi:on \
    | -ext:on \
    | use.extensions=1 \
    | fop1.extensions=1
    |
    | OK, my toolchain still works, but no highlighting yet


    At present, highlighting does not work for XSL-FO. There are two reasons as
    far as I can tell:
    1. The code for calling Pygments via Jython only handles (X)HTML output.
    2. Pygments does not provide an XSL-FO formatter.

    For XHTML, it took me a while to figure out how to make highlighting work
    (Saxon HE on Windows XP). These points were particularly important:

    1. Add role="pygments" to the <programlisting> element in the source XML.

    2. Add

    -Dpython.path=<path to Pygments install dir>

    to the "java" command. This was necessary in order to avoid "ImportError: No
    module named pygments".

    3. Add the output generated from this snippet,

    from pygments.formatters import HtmlFormatter
    print HtmlFormatter().get_style_defs()

    to a CSS file, and ensure that this file is referenced in the output (see
    the docbook.css parameter).

    Below is the contents of my Windows BAT file. I run it from the root
    directory of the 2.0.2 relase downloaded from http://docbook.github.com/.

    ----------
    java
    -Dpython.path=c:/Java/jython2.5.2/Lib/site-packages/Pygments-1.4-py2.5.egg ^
    -cp
    c:/Java/saxon93/saxon9he.jar;./lib/docbook-xsl2-saxon.jar;c:/Java/jython2.5.
    2/jython.jar ^
    net.sf.saxon.Transform ^
    -init:docbook.Initializer ^
    -s:verbatim.xml ^
    -xsl:./xslt/base/html/docbook.xsl ^
    -o:verbatim.html ^
    -xi:on ^
    -ext:on ^
    docbook.css=mydefault.css
    ----------


    | * Also there is mention of some python.path setting in ~/.jython
    | what does that look exactely (the path to the script maybe)?


    As an alternative to '-Dpython.path=...' at the command line, you can add

    python.path=<path to Pygments install dir>

    to ~/.jython.

    See http://wiki.python.org/jython/UserGuide#the-jython-registry


    | * I use neither Saxon PE or EE, but saxonb and/or saxonhe
    | so I guess I don't have to set
    |
    | <resources>
    |
    | <extensionFunction>org.docbook.extensions.xslt20.Cwd</extensi
    onFunction>
    |
    | <extensionFunction>org.docbook.extensions.xslt20.ImageIntrins
    ics</extensionFunction>
    |
    | <extensionFunction>org.docbook.extensions.xslt20.Pygmenter</e
    xtensionFunction>
    | </resources>


    That's right, configuration files cannot be used with Saxon HE. See
    http://www.saxonica.com/documentation/configuration/configuration-file.xml.

    Mauritz