5

I'm using the Highlight.js library for syntax highlighting of code in Blogger and it refuses to highlight Lisp code properly.

In the article on Blogger:

<pre><code class="lisp">
  (coerce (average 1 2 3 4) 'float)
  > 2.5
</code></pre>

In the design template before the closing </head>:

<script src='http://yandex.st/highlightjs/7.0/lisp.min.js' ></script>
<script src='http://yandex.st/highlightjs/7.0/highlight.min.js' ></script>
<link href='http://yandex.st/highlightjs/7.0/styles/github.min.css' rel='stylesheet' />
<script type='text/javascript'>
  hljs.initHighlightingOnLoad();
</script>

Upon opening the article the highlighting is broken, Firebug shows this in the HTML panel:

<pre>
  <code class="lisp ruby"> // WTF
  ... stylized RUBY tokens here ...
  </code>
</pre>

On some code snippets highlighter puts <code class="lisp undefined"> and refuses to highlight at all. As I'm on a Blogger, I really don't want to download anything to anywhere, especially when there is already published language packs. What magic should I do for Lisp to become recognizable?

KyleMit
  • 30,350
  • 66
  • 462
  • 664
hijarian
  • 2,159
  • 1
  • 28
  • 34

1 Answers1

6

You're using the hosted version which includes a number of definitions for common languages but Lisp is not among them. See the download page for the full list. In this case the "lisp" word in the class attribute is unknown to highlight.js and it tries to detect the language automatically.

However even if Lisp was included in the package it wouldn't highlight your fragment since it includes output (> 2.5) that is not Lisp and the definition of Lisp in highlight.js doesn't allow for this.

isagalaev
  • 1,173
  • 11
  • 16
  • so, I suppose then that including the `lisp.min.js` before the main script will not work, huh? And I cannot work around this by including all language-specific parts of highlight.js instead of standard batch? – hijarian Jul 02 '12 at 11:02
  • Sorry, I totally missed that you linked the lisp.min.js in the first line :-). However, you still got the URL wrong (should be `http://yandex.st/highlightjs/7.0/languages/lisp.min.js`) and it should go *after* the highlight.min.js. – isagalaev Jul 02 '12 at 22:00
  • man, you really should mention it somewhere in your project page. Especially about that you can include main script _then_ additional languages. I just included like a dozen languages like Haskell, 1C and so on, and it worked like a charm. Thanks for a tip. By the way: highlight.js really totally stops parsing if it meets a token unexpected for declared language, irrelevant of declaration. – hijarian Jul 03 '12 at 03:18
  • I don't run the CDN hosting actually and I can't honestly recommend linking to a dozen of languages in several files. This is what the custom download is for. – isagalaev Jul 03 '12 at 06:55