Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
babel-plugin-syntax-highlight
Advanced tools
A Babel plugin that transforms the code contents of template literals lead by comments specifying a Prism.js language into syntax highlighted HTML.
A Babel plugin that transforms the code contents of template literals lead by comments specifying a Prism.js language into syntax highlighted HTML.
Build-time syntax highlighting advantages:
To install babel-plugin-syntax-highlight
with npm, run:
npm install babel-plugin-syntax-highlight --save-dev
Configure Babel to use the plugin:
{
"plugins": ["syntax-highlight"]
}
In a file transpiled by Babel, lead a template literal containing syntax to highlight with a comment containing syntax-highlight
and a Prism.js language name:
const highlighted = /* syntax-highlight graphql */ `
scalar Upload
`;
The comment may be surrounded by others on the same or other lines for editor syntax highlighting, Prettier formatting, etc.
const highlighted =
/* syntax-highlight graphql */
/* GraphQL */ `
scalar Upload
`;
A block or line comment may be used:
const highlighted =
// syntax-highlight graphql
`scalar Upload`;
The plugin removes the comment (preserving surrounding comments) and transforms the template literal contents into HTML:
const highlighted = `<span class="token keyword">scalar</span> <span class="token class-name">Upload</span>`;
Styling the HTML is up to you; there are many theme stylesheets available. Often themes require <pre>
and <code>
containers with appropriate language classes.
A React component can be used display highlighted code with appropriate HTML and styles:
function SyntaxHighlightedCode({ language, code }) {
return (
<pre className={`language-${language}`}>
<code
className={`language-${language}`}
dangerouslySetInnerHTML={{ __html: code }}
/>
</pre>
);
}
const syntaxHighlightedCode = (
<SyntaxHighlightedCode language="css" code={highlighted} />
);
Supported runtime environments:
^14.17.0 || ^16.0.0 || >= 18.0.0
.Projects must configure TypeScript to use types from the modules that have a // @ts-check
comment:
compilerOptions.allowJs
should be true
.compilerOptions.maxNodeModuleJsDepth
should be reasonably large, e.g. 10
.compilerOptions.module
should be "node16"
or "nodenext"
.The npm package babel-plugin-syntax-highlight
features optimal JavaScript module design. These CommonJS modules are exported via the package.json
field exports
:
FAQs
A Babel plugin that transforms the code contents of template literals lead by comments specifying a Prism.js language into syntax highlighted HTML.
The npm package babel-plugin-syntax-highlight receives a total of 3 weekly downloads. As such, babel-plugin-syntax-highlight popularity was classified as not popular.
We found that babel-plugin-syntax-highlight 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.