21295 Posts in 5734 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 299 Views |
-
SyntaxHighlighter an Javascript in the CMS

18 January 2012 at 2:45pm Last edited: 18 January 2012 2:46pm
I have SyntaxHighlighter working in the CMS (using the SyntaxHL plugin for TinyMCS). It's all fine and dandy and code shows perfectly on the front end.
The problem is Javascript. TinyMCE reformats all of my Javascript, adding multiple CDATA's to the point where the code is invalid (the problem is well documented in the forums, for example here).
But I have seen other SilverStripe sites that display Javascript on the front end without problem, such as the SilverStripe documentation.
Is there something I am missing? How can I display Javascript in formatted code blocks on the front end using SyntaxHighlighter. Bonus points for anyone that can get me to run executable JS that has been inserted into TinyMCE in the backend (I realize the security risks, just looking for proof of concept).
BTW, I have tried to modify 'valid_elements' in _config.php with no success; javascript is still rewritten to include CDATAs.
Thanks to all!
-
Re: SyntaxHighlighter an Javascript in the CMS

20 January 2012 at 6:07am Last edited: 20 January 2012 6:07am
Hi,
I use the SyntaxHighlighter and the plugin on my site, and so far I haven't had any of the problems you describe. What it generates is something like this:
<pre class="brush: jscript;fontsize: 100; first-line: 1; ">
<script type="JavaScript">
alert('hi');
</script></pre>This is SilverStripe 246. It's definitely the <pre tag that prevents tinyMCE from messing with it - if I add it to HTML plain, without <pre, all javascript gets stripped away in my case... You do have the 'pencil' button installed and otherwise working in your editor, I presume?
-
Re: SyntaxHighlighter an Javascript in the CMS

25 January 2012 at 8:50am
Thanks for the reply martimiz.
I've got it working, I was using the wrong brush. I was mixing HTML and JavaScript (and SS template code), so I should have used the XML/HTML brush instead:
<pre class="brush: xml;fontsize: 100; first-line: 1; ">
<% control Store %><h2>{$Title}</h2>
<h3>Address:</h3>
<p>
{$Address}<br>
{$City}, {$State} {$Zip}
</p><script type="text/javascript">
var MapJSON = jQuery.parseJSON('{$Top.StoreGeolocationJSON}');
</script>
<div id="map_canvas" style="width:500px;height:300px;"></div><% end_control %>
</pre>Thanks again!
| 299 Views | ||
|
Page:
1
|
Go to Top |

