Would ANTLR & their Grammars for Java, SQL, etc. make sense for this?
https://www.antlr.org/
https://github.com/antlr/grammars-v4

All the best,
DaveLaw

On 19/09/2022 10:07, Andreas Reichel wrote:
Klaus and Team,

thank you for your feedback.
I have actually figured out something working nicely:

1) based on Pygments
2) use the XSLFO Pygments formatter (can be installed from PIP, the code is fairly simple and straight forward)
3) from your XML document containing the Code Block:
a) iterate through all code blocks
        b) call Pygments with the XSLFO Formatter and format the block into a temporary XML file (your FO styled codeblock)         c) when this succeeded, add to the Code Block node a childnode with the absolute path to this temporary XML file 4) amend your XSL file and for each code-block use the XSL:COPY-OF directive to insert the FO formatted content of the temporary XML file into the final PDF directly. (Apply a XSL:CHOOSE, when child exists then XSL:COPY-OF otherwise XSL:VALUE.)
5) clean up all the temporary files from step 3)

Caveats:
a) you need to call Python Pygmentize from Java using ProcessBuilder/Process (and react to failures) b) Pygments understanding of the code is limited and the highlighting can be questionable especially for SQL. However, I will use my own SQL Formatter to properly format complex SQL in FO

Cheers!

Reply via email to