Add javascript to a WYSIWYG pdf transform with Prince?
Post here questions and problems related to editing and publishing DITA content.
-
- Posts: 8
- Joined: Thu Sep 29, 2016 12:44 am
Add javascript to a WYSIWYG pdf transform with Prince?
Hi,
I've been exploring different ways to display codeblocks in pdf. We have some long lines of code that need to wrap but we want to show that the text is still all the same line. One of the more appealing options is adding zebra strips to codeblocks, such that the lines alternate colors.
The instructions I've found online for doing this (http://www.nealgrosskopf.com/tech/thread.php?pid=33) use javascript, and javascript is an option for inputting into the Prince processor, but I can't see a way to do it within Oxygen. Is there a way to do this?
Thanks again for your help,
Justine
I've been exploring different ways to display codeblocks in pdf. We have some long lines of code that need to wrap but we want to show that the text is still all the same line. One of the more appealing options is adding zebra strips to codeblocks, such that the lines alternate colors.
The instructions I've found online for doing this (http://www.nealgrosskopf.com/tech/thread.php?pid=33) use javascript, and javascript is an option for inputting into the Prince processor, but I can't see a way to do it within Oxygen. Is there a way to do this?
Thanks again for your help,
Justine
-
- Posts: 501
- Joined: Mon Feb 03, 2003 10:56 am
Re: Add javascript to a WYSIWYG pdf transform with Prince?
Ok, there are two ways of doing that zebra type of codeblock styling:
1. Modify the index-pass2.js file from the "com.oxygenxml.pdf.css" plugin, adding your JavaScript code.
The Prince XML processor is invoked from the build.xml file, in the target with name="prince". You can modfify this target if you need to change further the Prince XML command line. (https://www.princexml.com/doc/8.1/command-line/)
2. You can do it using XSLT:
Create a new XSLT file in "com.oxygenxml.pdf.css/xsl" folder. Name it "post-process-codeblock.xsl".
Create an import for it in "post-process.xsl".
In "post-process-codeblock.xsl", create a template that matches the codeblocks and creates a DIV for the codeblock, then parses the text, wrapping each line in an inner DIV.
The parent DIV element is marked with an class='zebra', so you can match it later from your CSS customisation.
Here is a the XSLT template:
And here is the CSS you can use to create the zebra effect.
Many regards,
Dan
1. Modify the index-pass2.js file from the "com.oxygenxml.pdf.css" plugin, adding your JavaScript code.
The Prince XML processor is invoked from the build.xml file, in the target with name="prince". You can modfify this target if you need to change further the Prince XML command line. (https://www.princexml.com/doc/8.1/command-line/)
2. You can do it using XSLT:
Create a new XSLT file in "com.oxygenxml.pdf.css/xsl" folder. Name it "post-process-codeblock.xsl".
Create an import for it in "post-process.xsl".
In "post-process-codeblock.xsl", create a template that matches the codeblocks and creates a DIV for the codeblock, then parses the text, wrapping each line in an inner DIV.
The parent DIV element is marked with an class='zebra', so you can match it later from your CSS customisation.
Here is a the XSLT template:
Code: Select all
<xsl:template match="*[contains(@class, ' pr-d/codeblock ')]">
<div class='zebra'>
<xsl:analyze-string regex="\n" select=".">
<xsl:matching-substring/>
<xsl:non-matching-substring>
<div><xsl:value-of select="."/></div>
</xsl:non-matching-substring>
</xsl:analyze-string>
</div>
</xsl:template>
And here is the CSS you can use to create the zebra effect.
Code: Select all
div[class ~= "zebra"] {
display:block;
border: 2pt solid red;
font-family:courier, fixed, monospace;
line-height:1.2em;
}
div[class ~= "zebra"]> *:nth-of-type(odd){
display:block;
background-color: silver;
}
Dan
-
- Posts: 8
- Joined: Thu Sep 29, 2016 12:44 am
Re: Add javascript to a WYSIWYG pdf transform with Prince?
Hi Dan,
Thanks for the code - the XSL method was easiest for me and worked just how I wanted it to with the color banding (I removed the red border). The only problem I'm running into is that the indentation of text within codeblocks is no longer being preserved. How do I get that back?
Thanks,
Justine
Thanks for the code - the XSL method was easiest for me and worked just how I wanted it to with the color banding (I removed the red border). The only problem I'm running into is that the indentation of text within codeblocks is no longer being preserved. How do I get that back?
Thanks,
Justine
-
- Posts: 501
- Joined: Mon Feb 03, 2003 10:56 am
Re: Add javascript to a WYSIWYG pdf transform with Prince?
Please add a white-space property to the "zebra" div, like:
You can read more about this property here:
https://developer.mozilla.org/en/docs/W ... hite-space
Regards,
Dan
Code: Select all
div[class ~= "zebra"] {
...
white-space:pre-wrap;
...
}
https://developer.mozilla.org/en/docs/W ... hite-space
Regards,
Dan
Return to “DITA (Editing and Publishing DITA Content)”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service