Jump to:

23493 Posts in 19011 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SyntaxHighlighter an Javascript in the CMS

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 548 Views
  • benjamin-smith
    Community Member
    17 Posts

    SyntaxHighlighter an Javascript in the CMS Link to this post

    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!

  • martimiz
    Forum Moderator
    1086 Posts

    Re: SyntaxHighlighter an Javascript in the CMS Link to this post


    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; ">
    &lt;script type="JavaScript"&gt;

    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?

  • benjamin-smith
    Community Member
    17 Posts

    Re: SyntaxHighlighter an Javascript in the CMS Link to this post

    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; ">
    &lt;% control Store %&gt;

          {$City}, {$State} {$Zip}

       &lt;script type="text/javascript"&gt;
          var MapJSON = jQuery.parseJSON('{$Top.StoreGeolocationJSON}');
       &lt;div id="map_canvas" style="width:500px;height:300px;"&gt;&lt;/div&gt;

    &lt;% end_control %&gt;

    Thanks again!

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.