gucong3000 / postcss-syntax

Automatically switch PostCSS syntax based on file extensions
MIT License
45 stars 7 forks source link

Add support for HTML & XML source #26

Closed gucong3000 closed 6 years ago

gucong3000 commented 6 years ago

https://github.com/stylelint/stylelint/issues/3328#issuecomment-396301689

codecov[bot] commented 6 years ago

Codecov Report

Merging #26 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #26   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          11     13    +2     
  Lines         250    258    +8     
=====================================
+ Hits          250    258    +8
Impacted Files Coverage Δ
index.js 100% <100%> (ø) :arrow_up:
parse.js 100% <100%> (ø) :arrow_up:
is-html.js 100% <100%> (ø)
languages.js 100% <100%> (ø)
parser.js 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update eacae3e...5f2b1a9. Read the comment docs.

gucong3000 commented 6 years ago

@shinnn I used a new scheme to determine whether the file is XML. I use regular expressions to determine if the source of the file is XML. However, it is not valid for empty files. I suggest that before applying the XML file to stylelint, determine if it contains <xsl:stylesheet>

shinnn commented 6 years ago

What do you mean by "empty files"?

At least the following code doesn't throw any errors.

const postcss = require('postcss');

const result = postcss().process('', {
  syntax: require('postcss-syntax'),
  from: '/path/to/example.xml'
});
gucong3000 commented 6 years ago

What do you mean by "empty files"?

Empty string source.

*.xml is the only exception because this is the case in the regular, but the XML format supported by vscode has many other extensions, just like: .svg, .atom .mxml, .xhvml, xvml, xvm, I can't write all of them into this regular, because there are so many.

const postcss = require('postcss');

const result = postcss().process('', {
  syntax: require('postcss-syntax'),
  // empty source `*.svg` file will berak postcss-syntax
  from: '/path/to/example.svg'
});
gucong3000 commented 6 years ago

image

shinnn commented 6 years ago

Post https://github.com/gucong3000/postcss-syntax/pull/26#issuecomment-396505696 first. https://github.com/gucong3000/postcss-syntax/pull/26#issuecomment-396488882 was extremely confusing to me.

I can't write all of them into this regular, because there are so many.

Could you at least support all the XML-related extensions you know currently?

gucong3000 commented 6 years ago

In addition to XSL, other XML is actually not supported by us because they are not style files. I'm very puzzled, why should we apply a style-independent file to a tool that handles styles?

I found that there are about 100+ extensions for XML format, but in fact we only support one (XSL).

shinnn commented 6 years ago

@gucong3000 What is blocking this from being merged?

gucong3000 commented 6 years ago

What is blocking this from being merged?

Some integration test runs failed: packages version build
postcss-syntax NPM version Travis
postcss-html NPM version Travis
postcss-markdown NPM version Travis
postcss-jsx NPM version Travis
postcss-styled NPM version Travis
gucong3000 commented 6 years ago

Replace with #28