Forum Feature requests

Please consider support text-emphasis properties

Shyujikou
Hi, would you please consider support text-emphasis properties? I'm aware that these properties are still under draft, but however, have been already implemented in major browsers. Additionally, these properties are quite necessary in formatting some Asian languages (CJK languages), and there seems to be no acceptable workarounds without using these properties.

Please refer to this page for details: https://developer.mozilla.org/en-US/docs/Web/CSS/text-emphasis

Thanks!
mikeday
Sure, we can add this to the roadmap.
Shyujikou
That's cool! Thank you so much!
hallvord
Hi,
this is not a real substitute for built-in support, but if you are interested in a hack that can be used with Prince today I've managed to get the jQuery.emphasis library to work. It can be applied to the document in a reasonably clean way without adding a jQuery dependency or lots of JavaScript to the document itself.

If you would like to test this, you will need to clone the jQuery.emphasis repository linked above and you will need a small compatibility helper script I've written which will sort out a couple of compat problems between Prince and the library. You will find it here: https://github.com/yeslogic/prince-scripts/blob/master/compatibility/jquery.emphasis/compat.js

Finally, you probably need to write a short helper script applying jQuery.emphasis() commands to the parts of the document you want emphasised. For example, if you have used the EM markup and a specific class name you would apply text-emphasis markup to - say
<p>Here is <em>emphasis applied</em>.</p>
<p class="dot-marked">This whole paragraph is marked with dots</p>


your helper file might look like this:
$('em').emphasis('filled black')
$('.dot-marked').emphasis('filled dot', 'under')


Now run Prince while using --script arguments to apply the required files. For example

prince --script /path/to/compat.js --script jquery.emphasis/assets/jquery-1.10.2.min.js --script jquery.emphasis/bin/jquery.emphasis.min.js --script my-emphasis-helper.js document.htm


If you try this, please let me know if it works for you! :)

Announcement: repos for tests/utils

Edited by hallvord

Shyujikou
Hi hallvord,

Thanks, this is quite helpful. I will give it a try.

Something not directly related to this topic, but it seems to be pretty tricky to get popular JS libraries work with Prince, e.g. MathJax. Now I need to call phantomjs first to generate an intermediate document with all formulas rendered as SVG and then feed it into Prince to build PDF. Do you have any idea if there is a way to get it work directly with Prince, let's say, with some sort of a hack script? Does it work differently using "--script" option instead of linking the script inside the document?
hallvord
I have done some investigations of MathJax requirements already. Unfortunately that's a really tricky library to get working in Prince - not very surprising, it requires a lot of information about DOM dimensions and text metrics and so on to arrange the formulas, and when Prince runs JavaScript before doing layout that information simply isn't available. I can get MathJax to run with some compat hacks, but the formulas it generated looked like a mess of letters because of the missing layout metrics. :-/

Now, Prince developers are very aware of this problem so perhaps the capability of reflowing a page and running JS along with layout, browser-style, will eventually land. It's a major, major job to implement though - touches how the entire architecture of the various parts gets organised.

Anyway, if I eventually find a hack that lets MathJax run I'll sure let you know :)

Announcement: repos for tests/utils

hallvord
BTW - if there are other popular JS libraries you'd like to use, just let me know - for example create a new forum thread for each. It's often possible to make things work with a few fixes or hacks.

Announcement: repos for tests/utils

Shyujikou
It's very nice to hear that the dev team is always ready to help. :)

MathJax is not an urgent issue, because it's OK for me to just let phantomjs do its job, and I think Prince should stick on its core features rather than to implement a full support towards Javascript.