html-validator
html-validator copied to clipboard
Does this package support CSS?
Thank you for this package. I'm just curious whether this returns CSS validation errors as well as HTML or only HTML?
Good question!
Never thought of checking CSS. However, according to the validator HTML, CSS and SVG is supported. I did a couple of tests and it seems to work fine for CSS. I've updated the README.
Hi! I looking for the usage in case of test a CSS file ? I tried things like pass
{ isFragment: true }
in the constructor, but the W3C Validator indicate that the style tag isn't allowed as child of body element.. And in the case of
{ isFragment: false }
it indicate that the HTML isn't correct as the <DOCTYPE html> isn't the first element of the data...
If need i can show you the all code i use.
The CSS i want to try is typical CSS as it should be in a .css file
h1 {
color: #FFFFFF
}
/* and so on... */
Edit: I use a function that create a valid HTML string that look like
function createValidHTML(css) {
return `<!DOCTYPE html>
<html lang="en">
<head>
<title>title</title>
<meta charset="UTF-8">
<style>
${css}
</style>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>`;
}
and then try to valid throught html-validator the string returned.
So, If I understand correct it is the cssfrom the function you want to test?
If css is in a separate file you would do something like:
(async () => {
const validator = require('html-validator')
const options = {
url: 'https://mysite.com/styles/mystyle.css'
}
try {
const result = await validator(options)
console.info(result)
} catch (error) {
console.error(error)
}
})()
To validate a snippet you could try
(async () => {
const validator = require('html-validator')
const options = {
data: css
}
try {
const result = await validator(options)
console.info(result)
} catch (error) {
console.error(error)
}
})()
Indeed this is the css passed in argument.
I tried what you proposed and it return an error, like it isn't a HTML-valid file. It seem that the validator do not detect it is only a CSS file and try to check it as if it is a HTML file.
I don't know if you understand? My English is rusty...
It seems like it only supports urls to css and only because there is a redirect to the w3c validator https://jigsaw.w3.org/css-validator/.
I'll update the README
@ghost you can also use w3c-css npm module that also uses W3C