Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

postcss-html

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-html - npm Package Compare versions

Comparing version 0.23.6 to 0.23.7

template-parse.js

72

extract.js
"use strict";
const htmlparser = require("htmlparser2");
const loadSyntax = require("postcss-syntax/load-syntax");
function iterateCode (source, onStyleTag, onStyleAttribute) {
const currentTag = {};
let style;
const openTag = {};

@@ -12,6 +14,8 @@ const parser = new htmlparser.Parser({

if (!/^style$/i.test(name)) {
openTag[name] = true;
return;
}
currentTag[name] = {
style = {
inHtml: openTag.html,
tagName: name,

@@ -24,16 +28,36 @@ attribute,

onclosetag (name) {
const tag = currentTag[name];
if (!tag) {
if (name !== "style" || !style) {
openTag[name] = false;
return;
}
currentTag[name] = null;
tag.content = source.slice(tag.startIndex, parser.startIndex);
onStyleTag(tag);
let content = source.slice(style.startIndex, parser.startIndex);
const firstNewLine = /^[ \t]*\r?\n/.exec(content);
if (firstNewLine) {
const offset = firstNewLine[0].length;
style.startIndex += offset;
content = content.slice(offset);
}
style.content = content.replace(/[ \t]*$/, "");
onStyleTag(style);
style = null;
},
onattribute (name, value) {
onattribute (name, content) {
if (name !== "style") {
return;
}
onStyleAttribute(value, parser._tokenizer._index);
const endIndex = parser._tokenizer._index;
const startIndex = endIndex - content.length;
if (source[startIndex - 1] !== source[endIndex] || !/\S/.test(source[endIndex])) {
return;
}
onStyleAttribute({
content,
startIndex,
inline: true,
inTemplate: openTag.template,
});
},

@@ -58,23 +82,23 @@ });

styles = styles || [];
const standard = opts.from && /\.(?:[sx]?html?|[sx]ht|markdown|md)$/i.test(opts.from);
function onStyleTag (style) {
const firstNewLine = /^[ \t]*\r?\n/.exec(style.content);
if (!(style.inHtml || standard) && (style.attribute.src || style.attribute.href) && !style.content.trim()) {
return;
}
style.lang = getLang(style.attribute);
if (firstNewLine) {
const offset = firstNewLine[0].length;
style.startIndex += offset;
style.content = style.content.slice(offset);
}
style.content = style.content.replace(/[ \t]*$/, "");
styles.push(style);
}
function onStyleAttribute (content, endIndex) {
const startIndex = endIndex - content.length;
if (source[startIndex - 1] === source[endIndex] && /\S/.test(source[endIndex])) {
styles.push({
content: content,
startIndex,
inline: true,
});
function onStyleAttribute (style) {
if (style.inTemplate && /\{\{[\s\S]*?\}\}/g.test(style.content)) {
style.syntax = loadSyntax(opts, __dirname);
style.lang = "custom-template";
} else {
style.lang = "css";
}
styles.push(style);
}
iterateCode(source, onStyleTag, onStyleAttribute);

@@ -81,0 +105,0 @@

{
"name": "postcss-html",
"version": "0.23.6",
"version": "0.23.7",
"description": "PostCSS syntax for parsing HTML (and HTML-like)",

@@ -46,16 +46,17 @@ "repository": {

"postcss": ">=5.0.0",
"postcss-syntax": "^0.9.0"
"postcss-syntax": "^0.10.0"
},
"devDependencies": {
"autoprefixer": "^8.3.0",
"autoprefixer": "^8.5.0",
"chai": "^4.1.2",
"codecov": "^3.0.1",
"codecov": "^3.0.2",
"mocha": "^5.1.1",
"nyc": "^11.7.1",
"postcss": "^6.0.21",
"nyc": "^11.8.0",
"postcss": "^6.0.22",
"postcss-less": "^1.1.5",
"postcss-safe-parser": "^3.0.1",
"postcss-scss": "^1.0.5",
"postcss-syntax": "^0.9.0",
"postcss-syntax": "^0.10.0",
"sugarss": "^1.0.1"
}
}

@@ -16,3 +16,3 @@ PostCSS HTML Syntax

- [PHP](http://php.net)
- [Vue component](https://vue-loader.vuejs.org/)
- [Vue Single-File Component](https://vue-loader.vuejs.org/spec.html)
- [Quick App](https://doc.quickapp.cn/framework/source-file.html)

@@ -55,6 +55,6 @@

- SCSS: [PostCSS-SCSS](https://github.com/postcss/postcss-scss)
- SASS: [PostCSS-SASS](https://github.com/aleshaoleg/postcss-sass)
- LESS: [PostCSS-LESS](https://github.com/shellscape/postcss-less)
- SugarSS: [SugarSS](https://github.com/postcss/sugarss)
- SCSS: [postcss-scss](https://github.com/postcss/postcss-scss)
- SASS: [postcss-sass](https://github.com/aleshaoleg/postcss-sass)
- LESS: [postcss-less](https://github.com/shellscape/postcss-less)
- SugarSS: [sugarss](https://github.com/postcss/sugarss)

@@ -61,0 +61,0 @@ ## Advanced Use Cases

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc