Search code examples
javascriptsmalltalkseaside

Smalltalk syntax highlighting


I'm building a Seaside application and I'm searching for a way to highlight some code snippets on the browser with JS. I found highlight.js which support Smalltalk syntax but it doesn't work. I add this script and hljs.initHighlightingOnLoad(); in the header but it doesn't work.

Probably I miss something but what?


Solution

  • I use highlight.js from CDN:

    <link href='http://yandex.st/highlightjs/8.0/styles/sunburst.min.css' rel='stylesheet'/>
    <script src='http://yandex.st/highlightjs/8.0/highlight.min.js' type='text/javascript'/>
    

    I also define a format function like:

    function format(){
        var b=document.getElementsByTagName(&quot;pre&quot;);
        for (i=0;i&lt;b.length;i++) {
            hljs.tabReplace = &#39;  &#39;; // 2 spaces
            b[i].style.fontSize = &#39;0.9em&#39;;
            hljs.highlightBlock(b[i],&#39;  &#39;,false);
        }
    }
    

    and use

    <pre class="smalltalk"><code>……</code></pre>
    

    for highlightable block. Then I call format() when the page is loaded (or a dynamic content with code is loaded into page)