javascript - Import and syntax highlight code from external source -


i'm not front-end developer , have been struggling hours highlight.js want. need display code nicely in blog. okay, works in renders code post into

<pre><code>...</code></pre> 

...very nicely , colourfully chosen style, idea.css example. i've got styles , highlight.pack.js ready go in directory.

but messy paste whole program between tags! more cleanly reusable other things if code can stay in file.

what shortest , elegant way (without loading in external libraries if possible) pull code out of python file in same directory mycode.py in between tags?

the main reference library here.

i assuming code file highlight lives on webserver.

  1. import file using jquery get.
  2. put content code tags.
  3. call appropriate function hightlight.js make highlight code.

here html/js code:

<pre><code></code></pre> <script type="text/javascript">   $.get("/mycode.py", function(response) {  //(1)     $("code").html(response);               //(2)     $("code").each(function(i, block) {         hljs.highlightblock(block);             //(3)     }); }); </script> 

note assumes there 1 <code> tag in page.otherwise step 2 needs adjusted.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -