Jump to:

23007 Posts in 11866 Topics by 2828 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: 473 Views
  • benjamin-smith
    Avatar
    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
    Avatar
    Forum Moderator
    1038 Posts

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

    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; ">
    &lt;script type="JavaScript"&gt;
    alert('hi');
    &lt;/script&gt;</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?

  • benjamin-smith
    Avatar
    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;

       &lt;h2&gt;{$Title}&lt;/h2&gt;
       
       &lt;h3&gt;Address:&lt;/h3&gt;
       &lt;p&gt;
          {$Address}&lt;br&gt;
          {$City}, {$State} {$Zip}
       &lt;/p&gt;

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

    &lt;% end_control %&gt;
    </pre>

    Thanks again!

    473 Views
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.