Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Special thanks to the author of the idea akopyl.
Attention!
This library works with the APIs provided bynode.js
.
npm i css2html
yarn add css2html
import { CssToHtml } from 'css2html';
let result = new CssToHtml({ css: 'div{}' });
console.log(result.outputHTML);
It converts this:
section#some-id {
/* {{ This is text inside }} */
--attr-title: 'Title';
background: red;
color: aliceblue;
}
section#some-id header[data-attribute='v'] {
/* {{ This is the header text }} */
color: blue;
}
section#some-id span {
/*
{{ Text of span }}
Text after
*/
color: peru;
}
To this:
<section id="some-id" title="Title">
This is text inside
<header data-attribute="v">This is the header text</header>
<span>Text of span</span>
Text after
</section>
You can create an element via selector:
div.classname#id[attr-1][attr-2='v'] {
/* None of the parts of a selector are mandatory */
/* But at least something needs to be left */
}
<!-- Result -->
<div id="id" class="classname" attr-1 attr-2="v"></div>
Nesting is supported:
div {
}
div span {
}
<div>
<span></span>
</div>
If you want to add styles but not add elements (that is, so that some selectors are ignored), add one of the following to the selector:
*
, +
, >
, ||
, |
, ~
@at-rule
Example - these selectors will be ignored:
> div.classname#id[attr-1][attr-2='v'] {
}
div::before {
/* Yes, and this one too */
}
div:not(:has(span)) {
/* And this one too! */
}
@container (width > 1440px) {
div[data-a='This element will be ignored too'] {
}
}
Attributes can be set via a selector (it can be useful for styling), or you can use a custom property:
/* In a selector */
a[title='Title!'] {
/* Specific attribute */
--attr-href: './index.html';
--data-attribute: 'Value';
/* And massively! */
--attrs: 'target="_self" rel="noopener"';
}
<a
title="Title!"
data-attribute="Value"
href="./index.html"
target="_self"
rel="noopener"
>
</a>
You can add text inside the tag using comments or variables:
/* The old way is not recommended for use */
div {
--text-before: 'The battle ';
--text: 'continues';
--text-after: ' again';
}
/* New way, recommended for use. Curly braces are required! */
section {
/*
The battle
{{ continues }}
again
*/
}
The battle <div>continues</div> again
The battle
<section> continues </section>
again
The very minimum to run looks like this:
// This code outputs to the terminal/console the result of processing the simplest CSS from the single tag.
import { CssToHtml } from 'css2html';
let result = new CssToHtml({ css: 'div{}' });
console.log(result.outputHTML);
To write in a file, add the write
parameter:
(Attention! The entire file will be overwritten)
new CssToHtml({
...,
write: {
in: "your_path_to_html_file",
},
})
Using the after
and/or before
parameters, you will not overwrite the entire file, but specify the area to be overwritten.
You can omit one of these parameters or not specify them at all.
Without after
and before
parameters:
new CssToHtml({
...,
write: {
in: "your_path_to_html_file",
},
})
<some-html-content>
<div>Your content from CSS</div>
</some-html-content>
<!-- to... -->
<div>Your content from CSS</div>
With after
and before
parameters:
new CssToHtml({
...,
write: {
...,
after: '<some-html-content>',
before: '</some-html-content>',
},
})
<some-html-content>
<div>Your content from CSS</div>
</some-html-content>
<!-- Without changes -->
<some-html-content>
<div>Your content from CSS</div>
</some-html-content>
Before giving you html, it is formatted by the html-format library. You can either enable or disable formatting:
new CssToHtml({
format: true, // default value
});
FAQs
The library for converting CSS to HTML
The npm package css2html receives a total of 60 weekly downloads. As such, css2html popularity was classified as not popular.
We found that css2html demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.