Find out the language of some code with node-js

142 views
Skip to first unread message

Marcelo Boeira

unread,
Sep 4, 2014, 8:05:10 PM9/4/14
to highl...@googlegroups.com
I have some strings at the database, and I want to find out what is the language on this files/strings...

Can I use Highlight.js at server side to do that?

Ivan Sagalaev

unread,
Sep 8, 2014, 7:06:22 PM9/8/14
to highl...@googlegroups.com
Hello Marcelo,

Technically, you can do this: the result of hljs.highlightAuto()
provides the detected language. But it may not be a good idea. The point
of a highlighter is not to detect a language reliably but rather to
provide a good looking highlighting. In a snippet:

return 5;

… we don't care if it's ended up being highlighted with cpp, java,
python or whatever, we care that "return" is marked up as keyword. And
apart from being inherently unreliable on short code snippets our
heuristics is, frankly, not as well debugged as it may (and should) be.
Reply all
Reply to author
Forward
0 new messages