1.8.0 • Published 9 months ago

postcss-html v1.8.0

Weekly downloads
2,136,294
License
MIT
Repository
github
Last release
9 months ago

PostCSS HTML Syntax

NPM license NPM version NPM downloads NPM downloads NPM downloads Build Status

PostCSS syntax for parsing HTML (and HTML-like)

Getting Started

First thing's first, install the module:

npm install postcss-html --save-dev

If you want support SCSS/SASS/LESS/SugarSS syntax, you need to install the corresponding module.

Use Cases

const postcss = require('postcss');
const syntax = require('postcss-html')({
    // syntax for parse scss (non-required options)
    scss: require('postcss-scss'),
    // syntax for parse less (non-required options)
    less: require('postcss-less'),
    // syntax for parse css blocks (non-required options)
    css: require('postcss-safe-parser'),
});
postcss(plugins).process(source, { syntax: syntax }).then(function (result) {
    // An alias for the result.css property. Use it with syntaxes that generate non-CSS output.
    result.content
});

If you want support SCSS/SASS/LESS/SugarSS syntax, you need to install these module:

Advanced Use Cases

Options

const options = {
    rules: [
        {
            // custom language
            test: /^postcss$/i,
            lang: 'scss'
        },
        {
            // custom language
            test: /^customcss$/i,
            lang: 'custom'
        },
    ],

    // custom parser for CSS (using `postcss-safe-parser`)
    css: 'postcss-safe-parser',
    // custom parser for SASS (PostCSS-compatible syntax.)
    sass: require('postcss-sass'),
    // custom parser for SCSS (by module name)
    scss: 'postcss-scss',
    // custom parser for LESS (by module path)
    less: require.resolve('./node_modules/postcss-less'),
    // custom parser for SugarSS
    sugarss: require('sugarss'),
    // custom parser for custom language
    custom: require('postcss-custom-syntax'),
}
const syntax = require('postcss-html')(options);

Turning PostCSS off from within your HTML

PostCSS can be temporarily turned off by using special comments in your HTML. For example:

<html>
<body>
<!-- postcss-ignore -->
<a style="color: red;" description="style is not parsed."></a>

<a style="color: red;" description="style is parsed."></a>
<html>
<body>
<!-- postcss-disable -->
<a style="color: red;" description="style is not parsed."></a>
<a style="color: red;" description="style is not parsed."></a>
<!-- postcss-enable -->

<a style="color: red;" description="style is parsed."></a>

Linting with Stylelint

The main use case of this plugin is to apply linting with Stylelint to <style> tags and <div style="*"> property in HTML (and HTML-like).

You can use it by configuring your stylelint config as follows:

{
    "overrides": [
        {
            "files": ["*.html", "**/*.html"],
            "customSyntax": "postcss-html"
        }
    ]
}

You can use it more easily if you use an already configured sharable config.

{
+    "extends": [
+        "stylelint-config-html",
         // If you are using Vue.
+        "stylelint-config-recommended-vue"
+    ],
-    "overrides": [
-        {
-            "files": ["*.html", "**/*.html"],
-            "customSyntax": "postcss-html"
-        }
-    ]
}
@hovey/stylelint-config-basic@frog-res/stylelint-config-vue-scssstylelint-common-config@clevercanyon/utilities-dev-npm@infinitebrahmanuniverse/nolb-postcss-h@longwoo/stylelint-config-standard@wfly/config-lint@cmsk/stylelint-config@redco/stylelint-config-hdred@everything-registry/sub-chunk-2460@ucstu/fast-nuxt-app@sacc/stylelint-config@beardeddudes-dev/postcss-config@trpl/stylelint-config-defaultfejn-stylelint-configvscode-lintvue-ellipsis-tooltip@pospal/prettier-config@pospal/stylelint-config@postanu/stylelint-config@rubixibuc/build-scripts@voltix/stylelint-configk100-lintergulp-html-postcsshfex-stylelint-configh-com-lintersgwscjg-uikolibri-formatmb-stylelint-config@wii/stylelint-config-wii@whfm/stylelint-config@wfrog/stylelint-config-vue-scss@web-utils/stylelint-config-scss@winner-fed/f2elint@wisdom-w/config-vite@wsvaio/stylelint-config@webank/stylelint-config-webank@webhb/less-config-plugin@tttiga/stylelint-config@trpl/stylelint-config-standard@typhoon41/stylelint-config@tsofist/web-buddy@trscd/stylelint-config-tpconfig@uni-daily/stylelint-config-vue@tonyptang/stylelint-config@tomjs/stylelint@trague/stylelint-config@transfermarkt/global-styles@transfermarkt/stylelint-config@tresinternet/stylelint-config@tresinternet/stylelint-config-vue3@vexip-ui/stylelint-config@vft/lint@vic1707/stylelint-config@vayne/cli@virtual-live-lab/stylelint-config@v-ed/stylelint-config@vituum/vite-plugin-juice@yangss/stylelint-config-vue@yangzw/bruce-std@xiaohe01/stylelint-config@yikoyu/eslint-config-prettier@yikoyu/stylelint-config@yaxc/stylelint-config@yugutou/stylelint-config@yupeiq1718/map-creator@yutengjing/stylelint-config-basic@yungezeit/stylelint-config-base@yungezeit/stylelint-config-svelte@zhbhun/stylelint-config@zalastax/nolb-postcss-h@teleskop-labs/stylelint-config-css@teleskop150750/stylelint-config-css@teleskop150750/stylelint-config-vue@ztjy/stylelint-config@zxd2219/stylelint-config@zmtlwzy/stylelint-config@zzzz-/stylelint-config-test@atomspace/stylelint@citruslime/config@-ysh-/code-specification-unid@1stg/stylelint-config4cs-cli@hankliu/lint@aarongoldenthal/stylelint-config-standard@abmao/stylelint-config-vue@grixu/stylelint-config@gsc-basic/stylelint-config@haltcase/style@gx-web/stylelint-config@agro-expo/rules@agro-tech/rules@adbros/stylelint-config@easytool/stylelint-config@codenatsu/stylelint-config-vue3@cocoy/esp-config@condorhero/stylelint-config-css@condorhero/stylelint-config-vue@alexlit/config-stylelint@convidera-team/stylelint-config-vue-convidera
1.8.0

9 months ago

1.7.0

1 year ago

1.6.0

2 years ago

1.5.0

3 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.2

4 years ago

0.36.0

7 years ago

0.34.0

7 years ago

0.33.0

7 years ago

0.32.0

7 years ago

0.31.0

7 years ago

0.30.0

7 years ago

0.28.0

7 years ago

0.27.0

7 years ago

0.26.0

7 years ago

0.25.0

7 years ago

0.24.0

7 years ago

0.23.7

7 years ago

0.23.6

7 years ago

0.23.5

7 years ago

0.23.4

7 years ago

0.23.3

7 years ago

0.23.2

7 years ago

0.23.1

7 years ago

0.23.0

7 years ago

0.22.0

7 years ago

0.21.0

8 years ago

0.20.1

8 years ago

0.20.0

8 years ago

0.19.0

8 years ago

0.18.0

8 years ago

0.17.0

8 years ago

0.16.0

8 years ago

0.15.0

8 years ago

0.14.0

8 years ago

0.13.0

8 years ago

0.12.0

8 years ago

0.11.0

8 years ago

0.10.0

8 years ago

0.9.0

8 years ago

0.8.0

8 years ago

0.7.0

8 years ago

0.6.0

8 years ago

0.5.0

8 years ago

0.4.0

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago