pretty print is not working for js file

138 views
Skip to first unread message

Rajitha

unread,
Mar 18, 2017, 5:03:08 PM3/18/17
to js-code-prettifier
Hi,
       I am getting html code dynamically from database and showing the content through js .pretty print script is not working when i keep script  in html page.Below is the code:

index.html:
<script type='text/javascript' src="js/display.js"></script>

display.js:

contentHtml += '<pre class="prettyprint tryit linenums">'+ arBody +'</pre>';

But if I keep a pretty print class in HTML pretty print function is working and the code is highlighting.

index.html:

<script type='text/javascript' src="js/display.js"></script>
<pre class="prettyprint tryit linenums">
 <p>hii</p>
</pre>

Greg Griffiths

unread,
Mar 29, 2017, 4:59:55 PM3/29/17
to js-code-prettifier
There are a few other posts in this forum that indicate that you would need to recall the PrettyPrint method after the JS has rendered, see https://groups.google.com/forum/#!topic/js-code-prettifier/I7D0MKorRCQ

Amro

unread,
Mar 30, 2017, 1:05:45 PM3/30/17
to js-code-prettifier
note that there two main function to call, PR.prettyPrint and PR.prettyPrintOne, you want the latter.
See https://github.com/google/code-prettify/issues/268 (with links to some examples)
Reply all
Reply to author
Forward
0 new messages