Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
highlighter
Advanced tools
Add syntax highlighting to all files, with built-in syntax highlighting of diffs and patches.
Highlighter provides a simple way to add syntax highlighting to all files by using highlight.js. Comes with built-in syntax highlighting for diffs and patches.
npm install highlighter --save
var highlight = require('highlighter')();
Highlighter can be used programmatically, by passing in the source string and the source language.
highlight('var foo = "bar";', 'javascript'); //=> '<span class="hljs-keyword">var</span> foo = <span class="hljs-string">"bar"</span>'
Highlighter returns a function that supports most markdown parsers already.
var marked = require('marked');
marked.setOptions({
highlight: highlight
});
Highlighter comes with complete diff support by appending .diff
or .patch
to the language name. This will wrap each section in a span with the section type class (diff-addition
, diff-deletion
, diff-header
, diff-chunk
or diff-null
).
highlight('+var foo = "bar";', 'js.diff'); //=> '<span class="diff-addition"><span class="hljs-keyword">var</span> foo = <span class="hljs-string">"bar"</span>;</span>'
This also works within Markdown files. The primary drawback of this approach causes the parent <code>
element to have the class appended with .diff
or .patch
, which may cause your specific CSS rules to fail. For example, <code class="lang-javascript.diff">
.
```javascript.diff
+var foo = "bar";
```
MIT
FAQs
Add syntax highlighting to all files, with built-in syntax highlighting of diffs and patches.
The npm package highlighter receives a total of 589 weekly downloads. As such, highlighter popularity was classified as not popular.
We found that highlighter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.