Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
rehype-add-classes
Advanced tools
Add classes by selector to elements with rehype.
Useful for adding:
hljs
class to <pre>
tag when converting markdown code snippets to htmlnpm:
npm install rehype-add-classes
Consider the following example.js
with rehype processor (or use unified) setup as follows:
import rehype from 'rehype';
import vfile from 'to-vfile';
import addClasses from 'rehype-add-classes';
const processor = rehype()
.data('settings', { fragment: true })
.use(addClasses, {
pre: 'hljs',
'h1,h2,h3': 'title',
h1: 'is-1',
h2: 'is-2',
p: 'one two'
});
const html = `
<pre><code></code></pre>
<h1>header</h1>
<h2>sub 1</h2>
<h2 class="existing">sub 2</h2>
<p></p>
`;
const { contents } = processor.processSync(vfile({ contents: html }));
console.log(contents);
Now, running node example.js
yields:
<pre class="hljs"><code></code></pre>
<h1 class="title is-1">header</h1>
<h2 class="title is-2">sub 1</h2>
<h2 class="existing title is-2">sub 2</h2>
<p class="one two"></p>
rehype().use(addClasses, additions])
Add to rehype
or unified
pipeline with .use
, where additions
is an object
with keys that are the css selectors and the values are a string to add to
the class
of each found node.
Example:
{
pre: 'hljs',
'h1,h2,h3': 'title',
h1: 'is-1',
h2: 'is-2',
p: 'one two'
}
<h1 class="title is-1">
value
is added to existing classes: <h2 class="existing title is-2">sub 2</h2>
value
is added: <p class="one two">
This library uses hast-util-select
under the hood. See these details
for supported selectors.
MIT ©2018 Marty Nelson
FAQs
Add classes by selector to a rehype HAST (html tree)
The npm package rehype-add-classes receives a total of 6,388 weekly downloads. As such, rehype-add-classes popularity was classified as popular.
We found that rehype-add-classes 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.