webhelp.head.script converts &,<,> to &amp; &lt; &gt;

Post here questions and problems related to editing and publishing DITA content.
mdslup
Posts: 167
Joined: Tue Mar 06, 2018 1:34 am

webhelp.head.script converts &,<,> to &amp; &lt; &gt;

Post by mdslup »

I'm using Oxygen 20 classic webhelp.

My company has asked me to add a widget from a customer support company called ZenDesk. The widget is javascript and looks like this (I've replaced my company name with "company"):

<!-- Start of company Zendesk Widget script -->
<script>/*<![CDATA[*/window.zEmbed||function(e,n){var t,o,d,s,i,a=[],r=document.createElement("iframe");window.zEmbed=function(){a.push(arguments)},window.zE=window.zE||window.zEmbed,r.src="javascript:false",r.title="",r.role="presentation",(r.frameElement||r).style.cssText="display: none",d=document.getElementsByTagName("script"),d=d[d.length-1],d.parentNode.insertBefore(r,d),s=r.contentWindow,i=s.document;try{o=i}catch(e){t=document.domain,r.src='javascript:var d=document.open();d.domain="'+t+'";void(0);',o=i}o.open()._l=function(){var e=this.createElement("script");t&&(this.domain=t),e.id="js-iframe-async",e.src="https://assets.zendesk.com/embeddable_f ... his.t=+new Date,this.zendeskHost="company.zendesk.com",this.zEQueue=a,this.body.appendChild(e)},o.write('<body onload="document._l();">'),o.close()}("https://assets.zendesk.com/embeddable_f ... endesk.com");
/*]]>*/</script>
<!-- End of company Zendesk Widget script -->

I tried embedding this script directly into an HTML file that Oxygen generates, and it works - a little "Support" bubble appears on the bottom right. To automatically add this to all my output HTML files, I copied the script to a file and pointed to it from my transformation scenario using the webhelp.head.script parameter.

It didn't work...and it seems like the reason is that it converts these characters:

& --> &
< --> <
> --> >

For some reason, this causes the widget to not work. When I go into one of the generated HTML files and replace the "&", "<", and ">" with the original characters, then it works fine.

Is there a way to have Oxygen *not* convert these characters?

I tried a little javascript test to see if those character replacements interfere with normal Javascript, and it seems like they do:
=== This outputs "YES" ===
<html>
<head>
<script type="text/javascript">
if (1==1 && 2==2) {
document.write('YES');
}
</script>
</head>
</html>

=== This outputs nothing ===
<html>
<head>
<script type="text/javascript">
if (1==1 && 2==2) {
document.write('YES');
}
</script>
</head>
</html><html>
<head>
<script type="text/javascript">
if (1==1 && 2==2) {
document.write('YES');
}
</script>
</head>
</html>
Last edited by mdslup on Thu Apr 26, 2018 9:12 pm, edited 1 time in total.
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

Re: webhelp.head.script converts &,<,> to &amp; &lt; &gt;

Post by alin »

Hello,

You should place your JS content inside an XML comment (<!-- -->):

Code: Select all


<script type="text/javascript"> 
<!--
if (1==1 && 2==2) {
document.write('YES');
}
//-->
</script>
Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
mdslup
Posts: 167
Joined: Tue Mar 06, 2018 1:34 am

Re: webhelp.head.script converts &,<,> to &amp; &lt; &gt;

Post by mdslup »

Sorry I think I was unclear. The main problem is that I need oxygen to *not* do this character conversion. Is there a parameter for that?
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

Re: webhelp.head.script converts &,<,> to &amp; &lt; &gt;

Post by alin »

Hello,

There is no predefined option (parameter) that would allow you to instruct the WebHelp plugin to not escape the XML special characters (&, <, >, etc.).
The content of the file referenced using the "webhelp.head.script" parameter is included in the output HTML files via XSLT. When serializing the output, the XSLT processor expands the XML special characters into their corresponding character entities.
To avoid this behavior it is recommended to wrap the inline JavaScript (or CSS) fragments in an XML comment. The XSLT processor will not escape the special characters within the XML comment content.

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
mdslup
Posts: 167
Joined: Tue Mar 06, 2018 1:34 am

Re: webhelp.head.script converts &,<,> to &amp; &lt; &gt;

Post by mdslup »

I figured this out! The way to do this is to have the file that is pointed to by webhelp.head.script include a file reference, not the script inline. Then add the file that contains the script to the resources folder using webhelp.custom.resources.

It's the second bullet point in item #1 of this link: https://www.oxygenxml.com/doc/versions/ ... assic.html
Post Reply