Highlighter.all () syntax not working at DOM level?

Possible duplicate:
jquery loading problem

I am dynamically loading content into a div using the jQuery load () function. In the callback, I call SyntaxHighlighter.all () to print the syntax of the pre-block that just loaded in the div.

The problem is that the content is loading OK, but the syntax is not highlighted. However, when I hardcode the pre-block into a div, so I don’t load into the DOM via the jquery load () function, the syntax will be highlighted as it should.

So, I assume that SyntaxHighlighter.all () only works with preview blocks that are in the html source, which can be viewed using the source of the view page, and not on the actual content in the DOM?

Any idea how I can make it work?

javascript to load and highlight:

<script type="text/javascript"> $.ajaxSetup ({ cache: false }); $(document).ready(function() { var tree = $("#tree li"); var contentContainer = $("#contentContainer"); var content = $("#content"); SyntaxHighlighter.config.clipboardSwf = 'syntaxhighlighter_2.0.320/scripts/clipboard.swf'; SyntaxHighlighter.all(); // Treeview $("#tree").treeview({ persist: "location", collapsed: true }); tree.click(function() { if ($(this).hasClass("file")) { tree.removeClass("selected"); $(this).addClass("selected"); content.load("content/"+this.id+".html", function() { contentContainer.effect("highlight"); SyntaxHighlighter.all(); }); } }); }); </script> 

div content:

 <div id="content"> <pre class="brush: java;"> /** * The HelloWorldApp class implements an application that * simply prints "Hello World!" to standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string. } } </pre> </div> 

external file that is loaded using jQuery.load ():

 Hello World <pre class="brush: java;"> /** * The HelloWorldApp class implements an application that * simply prints "Hello World!" to standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); // Display the string. } } </pre> 

Yours faithfully

+4
source share
2 answers
+4
source
  • Make element hidden with css (display: none)
  • Add item to page
  • Call SyntaxHighlighter.all ()
  • When you are ready to make it visible, remove the css or the class that made it hidden.
0
source

All Articles