How can I add a new language?

935 views
Skip to first unread message

Fabiano Bernardo

unread,
Jul 3, 2012, 10:00:49 AM7/3/12
to highl...@googlegroups.com
Hi I'm using highlight.js module inside my node.js web application. I need to highlight snippets inside documentation and I have a particular syntax, so I'd like to add this new language to highlight.js but I don't know how to do it.

First of all is it possible to add a new language?

Second, how can I do it? (forking the github proj and add a new js inside the languages folder?)

Thanks in advance and hava a good day.

Oleg Efimov

unread,
Jul 3, 2012, 1:17:32 PM7/3/12
to highl...@googlegroups.com
Hi Fabiano!

> First of all is it possible to add a new language? 
Yes, it is possible and quite simple. The docs about language definition are places in [wiki].

> Second, how can I do it? (forking the github proj and add a new js inside the languages folder?)
It depends on your language. If it is known language, you are welcome to fork and pull changes back.
Or you can create you own language definition in you fork, build it and use only on your site.
If you run highlighting on server side, you can simply add new language via hljs.LANGUAGES array.

[wiki]:  http://softwaremaniacs.org/wiki/doku.php/highlight.js:language 

вторник, 3 июля 2012 г., 18:00:49 UTC+4 пользователь Fabiano Bernardo написал:

Fabiano Bernardo

unread,
Jul 4, 2012, 3:48:06 AM7/4/12
to highl...@googlegroups.com
Hi Oleg and thanks for the answer.

I'm trying to create a syntax highlighter for a new javascript framework (http://ariatemplates.com/) and yes maybe is a good idea to fork the project and add the new aria templates language.

Maybe it's not clear for me but I'm using highlight.js (https://github.com/andris9/highlight) that uses the highlight.js parser (http://softwaremaniacs.org/soft/highlight/en/), but the node module written by andris9 is just passing php, like languege, to highlight.js so I had to modify his code.
Basically to add a new language I need to create a new js inside the languages folder and modify the andris9 module to be able to pass all the languages that I want to use, right?

Thanks.

Fabiano Bernardo

unread,
Jul 4, 2012, 3:54:43 AM7/4/12
to highl...@googlegroups.com
one more thing, I just missed it or it's not possible to specify a specific language and pass it to highlight.js? I mean something like the highlightText(text, tabReplace) method but with a new param like: highlightTextLang(lang, text, tabReplace) ???

Ivan Sagalaev

unread,
Jul 5, 2012, 3:57:48 AM7/5/12
to highl...@googlegroups.com
Hey Fabiano,

Let me try to clear this all up.

You're using a third-party fork of highlight.js the point of which seems
to be the node.js integration. I doubt anyone here will be able to help
you with Andris' fork but the good news is that the main highlight.js is
now able to work node.js too. And I'd recommend you to switch to the
main project anyway since Andris' for uses the version of highlight.js
which is more than a year old. And *a lot* things happened during this
time :-).

On to your questions.

You can now install highlight.js using `npm install highlight.js` which
will install the library and all the languages it currently knows.
However if you plan to add your own languages you can get the source,
add your language files and then build it for the node.js yourself:

python tools/build.py -t node language1 language2 ...

The building docs are here:
http://softwaremaniacs.org/wiki/doku.php/highlight.js:building_testing

Also you might consider submitting your language definition to the main
project if you don't mind maintaining it occasionally :-).

The library API is described here:
http://softwaremaniacs.org/wiki/doku.php/highlight.js:api
To highlight code with a specific language you want the first function —
`highlight(language_name, value)`

Fabiano Bernardo

unread,
Jul 5, 2012, 5:35:39 AM7/5/12
to highl...@googlegroups.com
Thanks a lot Ivan, it was very clear your explanation.
I switched to the main project this morning and I'm trying to use it, but I have just a small doubt:

what is this line? <script src="highlight.pack.js"></script>

Thanks.

Ivan Sagalaev

unread,
Jul 5, 2012, 6:09:22 AM7/5/12
to highl...@googlegroups.com
> what is this line? <script src="highlight.pack.js"></script>

I have no idea what do you mean by that :-). Where is this line? What
are you trying to do? If you're working in node.js environment, why do
you even need <script> tags?

Fabiano Bernardo

unread,
Jul 5, 2012, 7:17:26 AM7/5/12
to highl...@googlegroups.com
I was just reading the readme file on GitHub  https://github.com/isagalaev/highlight.js#basic-usage 

Oleg Efimov

unread,
Jul 5, 2012, 8:42:04 AM7/5/12
to highl...@googlegroups.com
There is a node.js example in next paragraph:
https://github.com/isagalaev/highlight.js#nodejs

2012/7/5 Fabiano Bernardo <f.bern...@gmail.com>:
--
Best regards,
Oleg "Sannis" Efimov

http://sannis.ru
Reply all
Reply to author
Forward
0 new messages