Tuesday, December 27, 2011

Git-Scribe Syntax Highlighting on Ubuntu

‹prev | My Chain | next›

I had a couple of surprises while playing with the latest version of git-scribe yesterday. First, I was able to generate different size output (7.5in x 9in) (that did not, in fact, work -- I was using the wrong gem). Second, I could not get code syntax highlighting working.

I tried both over a few months back and failed to get the re-sizing working, but definitely got the syntax highlighting working:


Unfortunately, I seem to have deleted the spike that allowed that syntax highlighting to work.

The commit that added syntax highlighting to upstream hard-coded the xslt highlighting library to the most likely installation location under OSX. Since I am on Ubuntu, I need to switch the location of that file accordingly:
<!-- xsl:param name="highlight.xslthl.config">file:///usr/local/Cellar/docbook/5.0/docbook/xsl/1.76.1/highlighting/xslthl-config.xml</xsl:param -->
<xsl:param name="highlight.xslthl.config">file:///usr/share/xslthl/highlighters/xslthl-config.xml</xsl:param>
But that has no effect—there is still no syntax highlighting present in the resultant PDF.

There are at least three locations for xslthl-config.xml on my system:
➜  ~  find /usr/share | grep xslthl-config.xml
/usr/share/xslthl/highlighters/xslthl-config.xml
/usr/share/xml/docbook/stylesheet/docbook-xsl/highlighting/xslthl-config.xml
/usr/share/xml/docbook/stylesheet/docbook-xsl-ns/highlighting/xslthl-config.xml
None of them do the trick.

My next step is to switch back to the last commit in the upstream gem:
➜  git-scribe git:(upstream) ✗ git stash save
Saved working directory and index state WIP on upstream: dd5cce2 bump to 0.1.1
HEAD is now at dd5cce2 bump to 0.1.1
With that, I am greeted with:
➜  backbone-recipes git:(master) ✗ git scribe gen pdf
GENERATING PDF
GENERATING DOCBOOK

Making portrait pages on A4 paper (210mmx297mm)

[warning] /usr/bin/fop: Unable to locate servlet-api in /usr/share/java
log4j:WARN No appenders could be found for logger (org.apache.fop.util.ContentHandlerFactoryRegistry).
log4j:WARN Please initialize the log4j system properly.
That error is apparently known by some. Following this documentation, I edit /usr/bin/fop on my system so that the last line in there reads:
run_java -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog $HEADLESS org.apache.fop.cli.Main "$@"
Fixing that, I see:
➜  backbone-recipes git:(master) ✗ git scribe gen pdf
GENERATING PDF
GENERATING DOCBOOK

Making portrait pages on A4 paper (210mmx297mm)
Loading Xslthl configuration from file:///usr/share/xslthl/highlighters/xslthl-config.xml...
[warning] /usr/bin/fop: Unable to locate servlet-api in /usr/share/java
[ERROR] FOP - Exception javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: file:/home/cstrom/repos/backbone-recipes/output/book.fo:1:108583: Error(1/108583): fo:page-sequence is not a valid child element of fo:flow.
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:217)
        at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:125)
        at org.apache.fop.cli.Main.startFOP(Main.java:166)
        at org.apache.fop.cli.Main.main(Main.java:197)
Caused by: javax.xml.transform.TransformerException: org.apache.fop.fo.ValidationException: file:/home/cstrom/repos/backbone-recipes/output/book.fo:1:108583: Error(1/108583): fo:page-sequence is not a valid child element of fo:flow.
        at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:502)
        at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:214)
        ... 3 more
Caused by: org.apache.fop.fo.ValidationException: file:/home/cstrom/repos/backbone-recipes/output/book.fo:1:108583: Error(1/108583): fo:page-sequence is not a valid child element of fo:flow.
        at org.apache.fop.fo.FONode.invalidChildError(FONode.java:435)
        at org.apache.fop.fo.FONode.invalidChildError(FONode.java:420)
        at org.apache.fop.fo.pagination.Flow.validateChildNode(Flow.java:105)
...
Ugh. I think it is starting to come back to me. I believe that I ended up hand editing the fo output this fall. I don't think that is a viable long term solution, so I call it a night here to ruminate on next steps...

Update: I eventually track down the FO / page-sequence errors to the preface. If I eliminate the preface, I again get PDF with syntax highlighting:


But now I have two problems on my hands: the page size is again wrong and I cannot include preface chapters in my PDF anymore ugh. That is definitely something on which to ruminate.

Day #147

No comments:

Post a Comment