Highlight.js: Add docs: Using only a subset of languages with Node/npm

Created on 24 Jul 2016  路  5Comments  路  Source: highlightjs/highlight.js

If you install the package from npm, the built file has all languages.

How is it possible to use only some languages?

docwebsite good first issue help welcome

Most helpful comment

Here's my complete example which is working for me

var hljs = require("highlight.js/lib/highlight.js");
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'));
hljs.registerLanguage('sql', require('highlight.js/lib/languages/sql'));

All 5 comments

Sure. You can pass languageSubset as a parameter for highlightAuto(): http://highlightjs.readthedocs.io/en/latest/api.html#highlightauto-value-languagesubset

@isagalaev but that will not exclude the files from the packed JavaScript file or am I missing something?

in index.js we have a ton of calls to require:

var hljs = require('./highlight');

hljs.registerLanguage('1c', require('./languages/1c'));
hljs.registerLanguage('abnf', require('./languages/abnf'));
...

As far as I understand we can just avoid index.js and include highlight.js directly and then call registerLanguage for the languages we actually need?

Here's my complete example which is working for me

var hljs = require("highlight.js/lib/highlight.js");
hljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'));
hljs.registerLanguage('sql', require('highlight.js/lib/languages/sql'));

Thanks, @remo. This was incredibly helpful. Would love to see it documented on the website or README.

This is in the README now.

Was this page helpful?
0 / 5 - 0 ratings