I recently needed to print out all the code associated with a project. Whilst I could've copied everything from my IDE to a word processor, I thought it might be nice to have a tool that could do this for me, highlighting the code along the way.
Install it globally using npm or Yarn.
npm i -g @mrbbot/hilite yarn global add @mrbbot/hilite
To highlight all files in the
src directory, and output
index.pdf in the current directory run the
You can specify as many locations to highlight so if you also wanted to highlight files in the
hilite src dist
You can also specify globs to match:
Hilite will also include png, jpeg, gif and svg images in the output if they're matched.
If you want to change the output file names, you can use the
-o) flag. For example, the following command
will output to
code.pdf instead of the normal
hilite src -o code
Additionally, if you're just looking for HTML output, you can disable the PDF export with the
hilite src -p false
This will only generate an
Hilite uses Prism for code highlighting, so if you don't like the default theme, you can easily change it using the
-t) flag to either one of the
presets, or your own custom one.
If you wanted to change the output to use the funky theme:
hilite src -t funky
Other available presets are:
If you had a custom theme stored in
theme.css, you could use it with the following command:
hilite src -t theme.css
Finally, you can also change the amount of margin in the PDF export using the
hilite src -m 1in
You must include the unit in your value.