Forum How do I...?

Comment in JavaScript causing prince to throw an error

stevejanke
Executing "prince -v --javascript my.html"

and getting this error:

prince: my.html:8: error: unexpected token identifier("ID")

I've tracked it down to this:

vvvvvvvvvvvvvvvvvvvvvvvvv
<script>
var componentNode = null;
var componentFunctionNode = null;
var failureNode = null;
var effectNode = null;
var rootCauseNode = null;

<!-- block ID=11201-->


componentNode = addToComponentTree(dfmeaTableItem.Children, 'Assy, Arm Drape');
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It's that comment that's causing the grief. So understand that there are a lot of these comments, and that they're autogenerated. I'm trying to figure out if I can suppress them during the autogeneration step, but in the meantime, how do I tell prince to ignore comments inside of JS sections?

Brilliant program, by the way.
hallvord
Hi,
this is an HTML-style comment, not a JavaScript-style comment (I suppose you know this already :)) and browsers have some slightly convoluted rules to ignore them inside SCRIPT tags. If Prince doesn't already do something similar, it probably should..

Ideally, whatever system generates this markup should use // or /* ... */ style comments instead. Browsers have some special-casing because when JavaScript was added to the web in the first place, older browsers would output the code as plain text in the page unless it was commented out. So in the beginning it was very common to write stuff like
<script>
<!--
..JS code goes here..
//-->
</script>

So it's an accident of history that <!-- works like a comment in a JS context at all, and it's always going to be more robust and safe to use JS-type comments.

Announcement: repos for tests/utils

Edited by hallvord