Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
highlight
Advanced tools
Readme
This project is deprecated in favor of isagalaev/highlight.js. I never created the parser myself, the module was created in the early days of node as a wrapper for an existing browser based parser highlight.js so if you are using this module and have problems with the parsing logic, I can't help you much as I'm not familiar with the inner details.
Pull requests are still welcomed - if you find a bug and fix it, then I'll pull the change in but I won't be fixing the bugs myself. Sorry for that.
highlight for node.js is based on highlight.js parser and is meant to highlight code syntax in languages that are not known beforehand (highlight.js detects the used language automatically). This is especially important for pages in Markdown format - there's no easy way to know which language is actually used.
Use npm
package manager
npm install highlight
Include syntax highlighter
var hl = require("highlight").Highlight;
highlight code
html = hl("for(var i=0;i<10;i++)alert(i);");
use special tab replacing string (default is 4 spaces)
html = hl(code_string, "<span> </span>");
convert code only between <code> blocks (leaves everything else as is) - especially useful if used together with converted Markdown syntax that includes <code> blocks.
html = hl("<p>PHP:</p><code><?php echo 'Hello world!';?></code>", false, true);
highlight outputs HTML code with predefined CSS class names for different elements. This doesn't make a lot of sense by default (it's just a bunch of SPAN's) so you need to use a CSS file that sets the used color set for the highlighting. There's some sample CSS files in /lib/vendor/highlight.js/styles that can be used with no modification - just include one of the files in the page you are showing the highlighted code.
<link rel="stylesheet" href="/path/to/styles/default.css"/>
FAQs
Highlight code syntax with node.js
The npm package highlight receives a total of 1,652 weekly downloads. As such, highlight popularity was classified as popular.
We found that highlight demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.