asciidoctor / asciidoctor-fopub

A portable DocBook-to-PDF build command that wraps DocBook XSL and Apache FOP
MIT License
113 stars 37 forks source link

Warning: No numberLines function available : unable to get linenumbers on code block #65

Open jagdeepjain opened 8 years ago

jagdeepjain commented 8 years ago

Configured in the adoc

:source-highlighter: coderay
:coderay-linenums-mode: inline

and in the file calling as below:

[source,java,linenums]
----
// File:
public class ApplicationConfigurationProvider extends HttpConfigurationProvider
{
   @Override
   public Configuration getConfiguration(ServletContext context) <1>
   {
      return ConfigurationBuilder.begin()
               .addRule()
               .when(Direction.isInbound().and(Path.matches("/{path}")))
               .perform(Log.message(Level.INFO, "Client requested path: {path}"))
               .where("path").matches(".*");
   }
}
----

Also set below:

  <xsl:param name="linenumbering.width">2</xsl:param>
  <xsl:param name="linenumbering.everyNth">1</xsl:param>
  <xsl:param name="linenumbering.separator">1</xsl:param>

While trying to set:

<xsl:param name="use.extensions">1</xsl:param>

getting an exception:

WARNING: No numberLines function available.
Oct 15, 2016 8:47:19 PM org.apache.fop.cli.Main startFOP
SEVERE: Exception
org.apache.fop.apps.FOPException: Stylesheet directed termination
javax.xml.transform.TransformerException: Stylesheet directed termination
    at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:300)
    at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:126)
    at org.apache.fop.cli.Main.startFOP(Main.java:186)
    at org.apache.fop.cli.Main.main(Main.java:217)
Caused by: javax.xml.transform.TransformerException: Stylesheet directed termination
    at org.apache.xalan.templates.ElemMessage.execute(ElemMessage.java:123)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:139)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:392)
    at org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:246)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:126)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1999)
    at org.apache.xalan.transformer.TransformerImpl.transformToRTF(TransformerImpl.java:1921)
    at org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:310)
    at org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:246)
    at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
    at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemTemplate.execute(ElemTemplate.java:392)
    at org.apache.xalan.templates.ElemCallTemplate.execute(ElemCallTemplate.java:246)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemElement.constructNode(ElemElement.java:339)
    at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:288)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:126)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:139)
    at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
    at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
    at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
    at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
    at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
    at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemLiteralResult.execute(ElemLiteralResult.java:1374)
    at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
    at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
    at org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:393)
    at org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:176)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemIf.execute(ElemIf.java:160)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:139)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:139)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:139)
    at org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2411)
    at org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2281)
    at org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1367)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1284)
    at org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1262)
    at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:297)
    ... 3 more
mojavelinux commented 8 years ago

The source highlighters in Asciidoctor (pygments, rouge, coderay) don't work with fopub. The DocBook toolchain has a special way of doing source highlighting (which honestly isn't very good). If you want to use source highlighting in your PDF, I recommend using Asciidoctor PDF.

jagdeepjain commented 8 years ago

Thanks @mojavelinux I am quite comfortable with fopub :) now, and have almost good infra for writing pdf using it. Guessing now is the time to start with asciidoctor-pdf.

jagdeepjain commented 8 years ago

@mojavelinux I tried with asciidoctor-pdf and seems like footnotes at the end of page are still in development and other features like TOC and colophon etc requires additional effort that I have already pass through with fopub. Also I already configured fopub and just require the linenumber for code blocks can you please help with the usage of "The DocBook toolchain has a special way of doing source highlighting (which honestly isn't very good)" ? Pointers will be highly appreciated ! Later on once my work is completed I can test it with asciidoctor-pdf and find out the differences.

mojavelinux commented 8 years ago

I'm sorry, I can't help you. I'm not focusing on fopub right. I don't view it as a good use of my limited time. I'm close to getting Asciidoctor PDF up to parity with the capabilities of the DocBook toolchain (including the features you mentioned) and that's where I'm putting my focus right now.

However, @getreu might be able to help you.

getreu commented 8 years ago

I could not get it work either. This is what I found:

These 2 parameters in fo.pdf are needed:

  <xsl:param name="use.extensions">1</xsl:param> 
  <xsl:param name="linenumbering.extensions">1</xsl:param> 

http://www.sagehill.net/docbookxsl/AnnotateListing.html#LineNumbering

It seems that Apache FOP does not enable the required extension by default and "some" jar is not in CLASSPATH.

http://www.sagehill.net/docbookxsl/InstallingAnFO.html#UsingFop

Maybe this helps you further...

http://www.red-bean.com/kfogel/beautiful-code/tools/xsl/doc/extensions.html

https://lists.oasis-open.org/archives/docbook-apps/200705/msg00003.html

jagdeepjain commented 8 years ago

Thanks @getreu I will try these links and update whether success or failed :(

jagdeepjain commented 8 years ago

@getreu I followed the links you have provided and also got new link as: http://www.stevestreeting.com/2010/03/07/building-a-new-technical-documentation-tool-chain/

Did the required setup and as per the setup these are problem lines under verbatim.xsl

  <xsl:choose>
    <xsl:when test="function-available('sverb:numberLines')">
      <xsl:copy-of select="sverb:numberLines($rtf)"/>
    </xsl:when>
    <xsl:when test="function-available('xverb:numberLines')">
      <xsl:copy-of select="xverb:numberLines($rtf)"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:message terminate="yes">
        <xsl:text>No numberLines function available.</xsl:text>
      </xsl:message>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Not sure how to handle this :(

Just for your quick reference I have added a git repo for you review:

https://github.com/jagdeepjain/sample-pdf

getreu commented 8 years ago

You need to do 3 things:

mojavelinux commented 8 years ago

Nice summary. One critique.

You should definitely not be modifying the generated build/fopub/bin/fopub file. Instead, you should add the dependency to the build.gradle file, then let Gradle regenerate the fopub script (just delete the build directory).

dependencies {
  runtime 'xalan:xalan:2.7.2'
}

(there might also be a way to reference the local file, but it needs to be done in the build.gradle script or else it will get overwritten).

mojavelinux commented 8 years ago

I can't even begin to fathom why it's necessary to add an XSLT engine to the classpath when it's already available in Java. This is one of the many reasons I find the DocBook toolchain to be such a mess.

jagdeepjain commented 8 years ago

Thanks @getreu, @mojavelinux I will update on the proceedings at my end.

getreu commented 8 years ago

@jagdeepjain: I followed @mojavelinux advice and pushed a commit here: https://github.com/getreu/asciidoctor-fopub

I had not time to test it yet. Maybe this afternoon.

jagdeepjain commented 8 years ago

Thanks @getreu I took your changes but did not succeed, I have a sample project https://github.com/jagdeepjain/sample-pdf for testing the same, have added you on this project. Please help :(

I am using two steps command to generate the pdf.

$ asciidoctor -b docbook -d book basic-example.adoc $ ./asciidoctor-fopub/fopub basic-example.xml -xsl asciidoctor-fopub/build/fopub/docbook-xsl/fo-pdf.xsl

Output:

jagdeepjain:sample-pdf jagdeepjain$ ./asciidoctor-fopub/fopub basic-example.xml -xsl asciidoctor-fopub/build/fopub/docbook-xsl/fo-pdf.xsl
sed: 1: "basic-example.xml": undefined label 'asic-example.xml'
Oct 18, 2016 12:03:53 PM org.apache.fop.hyphenation.Hyphenator getHyphenationTree
SEVERE: Couldn't find hyphenation pattern for lang="en".
Oct 18, 2016 12:03:53 PM org.apache.fop.events.LoggingEventListener processEvent
INFO: Rendered page #1.
Oct 18, 2016 12:03:53 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Symbol,normal,700" not found. Substituting with "Symbol,normal,400".
Oct 18, 2016 12:03:53 PM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "ZapfDingbats,normal,700" not found. Substituting with "ZapfDingbats,normal,400".
Oct 18, 2016 12:03:53 PM org.apache.fop.cli.InputHandler warning
WARNING: No numberLines function available.
Oct 18, 2016 12:03:53 PM org.apache.fop.events.LoggingEventListener processEvent
INFO: Rendered page #2.
Oct 18, 2016 12:03:53 PM org.apache.fop.events.LoggingEventListener processEvent
INFO: Rendered page #3.
Oct 18, 2016 12:03:53 PM org.apache.fop.cli.Main startFOP
SEVERE: Exception
org.apache.fop.apps.FOPException: Stylesheet directed termination
javax.xml.transform.TransformerException: Stylesheet directed termination
    at org.apache.fop.cli.InputHandler.transformTo(InputHandler.java:300)
    at org.apache.fop.cli.InputHandler.renderTo(InputHandler.java:126)
    at org.apache.fop.cli.Main.startFOP(Main.java:186)
    at org.apache.fop.cli.Main.main(Main.java:217)
Caused by: javax.xml.transform.TransformerException: Stylesheet directed termination
getreu commented 8 years ago

@mojavelinux : the following does not refer to the right .jar

dependencies {
  runtime 'xalan:xalan:2.7.2'
}

What we need is this one: build/fopub/docbook/extensions/xalan27.jar.

I have no experience with gradle, how to reference the above jar?

jagdeepjain commented 8 years ago

@getreu for me nothing is working please look at https://github.com/jagdeepjain/sample-pdf and suggest what I am missing in my setup.

mojavelinux commented 8 years ago

There are three options to getting the right jar

  1. Find the right jar hosted on Maven Central (surely, it must be there)
  2. Add the jar to the list of dependencies in a doLast block of the extractDocbookXsl task (you can add a dependency using project.dependencies from inside of doLast I think)
  3. Add the jar to startScript by tweaking the unixScript and windowsScript text as you see at the bottom of build.gradle

The only way to get experience with Gradle is just to try. It's just a programming tool like any other.

jagdeepjain commented 8 years ago

I download fop-2.1 and was able to generate the pdf successfully with code blocks having line numbers. The same xml is not working with fopub even though I have set required classpath. Seems to be a bug in fopub.

getreu commented 8 years ago

I committed the solution no. 3 to https://github.com/getreu/asciidoctor-fopub Could you have a look? It should work out of the box.

jagdeepjain commented 8 years ago

Thanks @mojavelinux, @getreu 👍 it worked for me :) will you be merging with the main branch anytime sooner ?

getreu commented 8 years ago

@mojavelinux Dan, I wrote you through the email function of our forum. Has this email reached you? Best Jens

getreu commented 8 years ago

@jagdeepjain : has your test document also tables and figures with captions, headlines, titlepage etc...? If yes do they all appear correctly?

jagdeepjain commented 8 years ago

@getreu thanks for asking and cross checking, I will update you soon.

jagdeepjain commented 8 years ago

@getreu sorry for working on this so late, I build up my docbook using the code https://github.com/getreu/asciidoctor-fopub and the tables, chapter headers, section headers and title page were happily generated as was earlier.

I saw below difference: (I guess this are configuration points that I can take care of it )

  1. Table headers become italics and normal in weight
  2. Figure caption becomes italics and normal in weight

screenshot 2016-11-02 12 21 16

Many thanks for taking care of this 👍

If you have merge your code to mainstream I can close this issue.

getreu commented 8 years ago

Both are intentional layout improvements. Thank you for testing!

jagdeepjain commented 7 years ago

@getreu seems like changes are not visible now, could not see changes made in https://github.com/getreu/asciidoctor-fopub/commit/64062e80425d652d9a9de4e2b001fa11dba24e8a#diff-2559ef435ce261390c6a1bb7f3419fcb this repo as well as in https://github.com/getreu/asciidoctor-fopub/ repo. can you please let know how to get line numbers now?

getreu commented 7 years ago

Hello, after pull request #73 I discovered issue #74. The new download location does not include the directory asciidoctor-fopub/build/fopub/docbook/extensions which you need. Solution: get if from some other place and download it separately. Sorry.

getreu commented 7 years ago

This should work:

  1. get the file xalan27.jar (my md5: 9098eed8dc523b432acfb2596eec3d47) from here
  2. copy it into asciidoctor-fopub/build/fopub/docbook/extensions
  3. use my fork: https://github.com/getreu/asciidoctor-fopub
  4. test it:

test_linenums.adoc:


= tmp6 : Notes

[source,ruby,linenums]
----
ORDERED_LIST_KEYWORDS = {
  'loweralpha' => 'a',
  'lowerroman' => 'i',
  'upperalpha' => 'A',
  'upperroman' => 'I'
   #'lowergreek' => 'a'
   #'arabic'     => '1'
   #'decimal'    => '1'
}
----
jagdeepjain commented 7 years ago

Thanks @getreu, but it did not work for me.