Re: Code block syntax highlighting
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!
Re: Code block syntax highlighting
Cool. On 20/09/2022 08:58, Andreas Reichel wrote: On Tue, 2022-09-20 at 08:10 +0200, Dave The Dane wrote: Can it handle the WITH Clause Please see https://manticore-projects.com/JSQLFormatter/samples.html#select (The structural formatting is done by JSQLFormatter, although the highlighting is still done by Pygments to ease website publishing.) Cheers Andreas
Re: Code block syntax highlighting
On Tue, 2022-09-20 at 08:10 +0200, Dave The Dane wrote: > Can it handle the WITH Clause Please see https://manticore-projects.com/JSQLFormatter/samples.html#select (The structural formatting is done by JSQLFormatter, although the highlighting is still done by Pygments to ease website publishing.) Cheers Andreas
Re: Code block syntax highlighting
Even nested WITHs (although the heavy lifting is done by JSQLParser, where I am only a strong contributor for). A good test for the Highlighter is this one, Pygments gets it totally wrong: SELECT Overlaps( overlaps ) AS overlaps FROM overlaps.overlaps overlaps WHERE overlaps = 'overlaps' AND (CURRENT_TIME, INTERVAL '1' HOUR) OVERLAPS (CURRENT_TIME, INTERVAL -'1' HOUR) Cheers Andreas On Tue, 2022-09-20 at 08:10 +0200, Dave The Dane wrote: > Can it handle the WITH Clause? > ...probably the most unknown tool for structuring SQL Queries! > > DaveLaw, > Subquery-Factoring Evangelist 😎 > > On 20/09/2022 07:45, Andreas Reichel wrote: > > > > > Thanks Dave. > > > > I have written a good SQL > > Formatter https://manticore-projects.com/JSQLFormatter/index.html > > > > I only will need to add xsl-fo output which is easy. > > > > All the best > > Andreas > > > > On 20 Sept 2022 06:01, Dave The Dane wrote: > > > > > 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! > > > > > > > > > > > > > > > --- > > -- To unsubscribe, e-mail: > > fop-users-unsubscr...@xmlgraphics.apache.org For additional > > commands, e-mail: fop-users-h...@xmlgraphics.apache.org >
Re: Code block syntax highlighting
Can it handle the WITH Clause? ...probably the most unknown tool for structuring SQL Queries! DaveLaw, Subquery-Factoring Evangelist 😎 On 20/09/2022 07:45, Andreas Reichel wrote: Thanks Dave. I have written a good SQL Formatter https://manticore-projects.com/JSQLFormatter/index.html I only will need to add xsl-fo output which is easy. All the best Andreas On 20 Sept 2022 06:01, Dave The Dane wrote: 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! - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org
Re: Code block syntax highlighting
Thanks Dave. I have written a good SQL Formatter https://manticore-projects.com/JSQLFormatter/index.htmlI only will need to add xsl-fo output which is easy. All the bestAndreasOn 20 Sept 2022 06:01, Dave The Dane wrote: 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!
Re: Code block syntax highlighting
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!
Re: Code block syntax highlighting
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!
Re: Code block syntax highlighting
On 16.09.22 14:44, Andreas Reichel wrote: Greetings and compliments of the day. We use FOP successfully to generate nice PDF files for our technical documentation. Although there is one more requirement: printing formatted code blocks with syntax highlighting (e. g. SQL or Java code snippets). What would be the best way to achieve that? I have tried to convert the SQL/Java code to SVG via Pygments and to insert it as EXTERNAL_GRAPHICS. This works in general, but I cant control the sizing. Each EXTERNAL_GRAPHICS will have a different size of characters based on the size of the graphics. Does anyone know a better way or has done something similar already? I would appreciate any idea or hint. Thank you in advance and best regards Andreas Hi Andreas, I haven't had such a problem yet, so I don't know tools that perform the actual syntax highlighting. But what I do not understand is why you are using SVG and external graphics. FO is capable of doing preformatted text and also of colorizing text. So no need to go that path. Since you using scripts anyway (as far as I understand), it shouldn't be too complicated to generated XML fragments to be inserted into you document. Regards, Klaus - To unsubscribe, e-mail: fop-users-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-users-h...@xmlgraphics.apache.org