Stack Exchange's syntax highlighting engine (which is based on Google Prettify) has some heuristics to choose between programming languages when highlighting a block of code. That doesn't work so well on Emacs Stack Exchange, where many code blocks are blocks of text that shouldn't be highlighted at all, but the engine would often guess some wrong programming language.

The engine can be configured via tags, but that doesn't help much, because just about any question on this site can be answered with some Emacs Lisp code.

The syntax chosen by a block can be chosen explicitly with a HTML comment just before the block like <!-- language: lang-el --> for Emacs Lisp, or with <!-- language-all: lang-el --> to set the default for all blocks in a post. <!-- language: lang-none --> turns off highlighting. It would be nice to have better defaults, though.

A heuristic that works very well is to highlight blocks that start with one of the characters `(;' as Lisp and default any other block to having no highlighting. Among the earliest few hundred questions and answers on this site (totalling 623 code blocks), this heuristic would correctly find more than 99% of the Lisp blocks and would incorrectly highlight as Lisp less than 1% of the non-Lisp blocks.

Please allow fine-tuning the heuristics in the syntax highlighting engine so that code blocks default to a particular language based on a per-site rule associating a prefix with a language.

You must log in to answer this question.

Browse other questions tagged .