Building and testing
The build tool is written in JavaScript using node.js. Before running thescript, make sure to have node installed and run to get thedependencies.
The tool is located in tools/build.js
. A few useful examples:
- Build for a browser using only common languages:
- Build for node.js including all available languages:
On some systems the node binary is named nodejs
; simply replace node
with nodejs
in the examples above if that is the case.
The build result will be in the build/
directory.
The usual approach to debugging and testing a language is first doing itvisually. You need to build highlight.js with only the language you’re workingon (without compression, to have readable code in browser error messages) andthen use the Developer tool in tools/developer.html
to see how it highlightsa test snippet in that language.
A test snippet should be short and give the idea of the overall look of thelanguage. It shouldn’t include every possible syntactic element and shouldn’teven make practical sense.
Testing is done using Mocha and thefiles are found in the test/
directory. You can use the node build torun the tests in the command line with npm test
after installing thedependencies with .
Note: for Debian-based machine, like Ubuntu, you might need to create analias or symbolic link for nodejs to node. The reason for this is thedependencies that are requires to test highlight.js has a reference to“node”.
Place the snippet you used inside the browser intest/detect/<language>/default.txt
, build the package with all the languagesfor node and run the test suite. If your language breaks auto-detection, itshould be fixed by , which is a black artin and of itself. When in doubt, please refer to the discussion group!
A test case consists of two files:
test/markup/<language>/<test_name>.txt
: test code- : reference rendering
To generate reference rendering use the Developer tool located attools/developer.html
. Make sure to explicitly select your language in thedrop-down menu, as automatic detection is unlikely to work in this case.