express-highlights v1.0.0
Express-Highlights
Integrates Express and Highlights to make writing Handlebars templates containing highlighted code snippets easy.
It achieves that by providing a express-handlebars helper that calls Highlights, the Atom syntax highlighter, to perform the actual highlighting.
Atom has lots of highlight themes, such as the atom-dark-syntax and the solarized-light-syntax.
See below how to use them in your own HTML pages.
Basic Usage
Include your favourite syntax highlight theme's CSS in the HTML file that includes the handlebars template:
<link rel="stylesheet" href="atom-dark.css" theme="theme" title="Atom Dark">
On the server, add the express-highlights
helper to your express-handlebars
engine:
const highlight = require("express-highlights").highlight;
const exphbs = require('express-handlebars');
// create handlebars instance that uses express-highlights
const hbs = exphbs.create({
helpers: {
code: highlight
}
});
// register it with Express and you're all set
app.engine('handlebars', hbs.engine);
Using custom languages
Highlights supports a few languages out-of-the-box, such as JavaScript, CoffeeScript, Java and Python.
If your language grammar is not included by default, you can install it as in the example below for Scala support:
const expressHighlights = require("express-highlights");
const scala = require.resolve('language-scala/package.json');
expressHighlights.use(scala);
// create handlebars instance that uses express-highlights
const hbs = exphbs.create({
helpers: {
code: expressHighlights.highlight
}
});
7 years ago