Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
postcss-html
Advanced tools
The postcss-html npm package is a tool that allows PostCSS to be used with HTML, including HTML-like syntaxes such as XML, XHTML, and HTML with inline styles. It enables developers to process styles within `<style>` tags or inline `style` attributes using PostCSS plugins.
Processing inline styles
This feature allows processing of inline styles within HTML. The code sample demonstrates how to use postcss-html to process a string containing HTML with a `<style>` tag.
const postcssHtml = require('postcss-html');
const result = postcssHtml.process('<style>h1 { color: red; }</style>', { /* options */ }).then(result => {
console.log(result.html);
});
Processing styles in HTML-like files
This feature processes styles within HTML-like files. The code sample shows how to read an HTML file, process it with postcss-html, and then write the processed HTML to a new file.
const postcssHtml = require('postcss-html');
const fs = require('fs');
fs.readFile('index.html', (err, html) => {
if (err) throw err;
postcssHtml.process(html, { /* options */ }).then(result => {
fs.writeFile('index-processed.html', result.html, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
});
});
The postcss-scss package is a syntax for PostCSS that allows you to work with SCSS (Sassy CSS) directly, without converting it to CSS first. It is similar to postcss-html in that it extends PostCSS's capabilities to non-standard CSS syntaxes, but it focuses on SCSS rather than HTML.
postcss-jsx is an npm package that enables PostCSS to parse and transform CSS within JSX files. It is similar to postcss-html as it extends PostCSS to handle CSS within a different context (JSX instead of HTML), allowing for linting and other transformations within JavaScript frameworks like React.
stylelint is a powerful, modern linter that helps you avoid errors and enforce conventions in your styles. It is similar to postcss-html in that it can be used to lint styles within HTML files, but it is primarily a standalone tool rather than a PostCSS plugin.
PostCSS Syntax for parsing HTML
First thing's first, install the module:
npm install postcss-html --save-dev
If you want support SCSS/SASS/LESS/SugarSS syntax in HTML, you need to install the corresponding module.
The main use case of this plugin is to apply PostCSS transformations directly to HTML source code. For example, if you ship a theme written in style tag in HTML and need Autoprefixer to add the appropriate vendor prefixes to it; or you need to lint style source in HTML with a plugin such as Stylelint.
var syntax = require('postcss-html');
postcss(plugins).process(html, { syntax: syntax }).then(function (result) {
result.content // HTML with transformations
});
var syntax = require('postcss-html');
postcss(plugins).process(html, {
syntax: syntax({
css: require('postcss'),
less: require('postcss-less'),
scss: require('postcss-scss'),
})
}).then(function (result) {
result.content // HTML with transformations
});
var syntax = require('postcss-html');
postcss(plugins).process(html, {
syntax: syntax((opts, lang) => {
if (lang) {
// `lang`: language of style tag in html.
// style tag in HTML file
if (lang === 'less') {
// `<style type="text/less">`
return require('postcss-scss')
}
} else if(opts.from) {
// `opts`: See http://api.postcss.org/global.html#processOptions
if (/\.less$/.test(opts.from)) {
// `*.less` file
return require('postcss-less')
}
}
})
}).then(function (result) {
result.content // HTML with transformations
});
FAQs
PostCSS syntax for parsing HTML (and HTML-like)
The npm package postcss-html receives a total of 527,137 weekly downloads. As such, postcss-html popularity was classified as popular.
We found that postcss-html demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.