validator / gulp-html

Gulp plugin for HTML validation, using the official Nu Html Checker (v.Nu)

Home Page:https://validator.github.io/gulp-html/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False errors in files, compiled with partials

kpobococ opened this issue · comments

I'm using gulp-file-include to move repetitive parts of my html pages (like page header and footer) to outside files. However, gulp-html does not seem to use the compiled version for its validation, because it gives me errors about missing title element within head (which is inside one of the partials).

Here's a shortened version of my gulpfile.js:

var gulp            = require('gulp');
var gulpFileInclude = require('gulp-file-include');
var gulpHtml        = require('gulp-html');

gulp.task('html', function () {
    return gulp.src('src/*.html')

        // Include partials
        .pipe(gulpFileInclude({
            prefix:   '<!-- partial:',
            suffix:   ' -->',
            basepath: 'src/partials/',
            context:  {
                'compileJs': false
            }
        }))

        // Validate
        .pipe(gulpHtml())
        .pipe(gulp.dest('dist/'));
});

Am I missing something or is it a bug?

It's not supported. PRs welcome.

However, gulp-html does not seem to use the compiled version for its validation, because it gives me errors about missing title element within head (which is inside one of the partials).

@kpobococ I know this is an old issue, but I ran into it today while using gulp-html for the first time. I solved it by moving validation to a separate task.

gulp.task('html', function () {
    return gulp.src('src/*.html')
        // Build HTML here using something like a static site generator
        .pipe(gulp.dest('dist/'));
});

gulp.task('validate', function () {
    return gulp.src('dist/*.html')
        .pipe(validator())
        .pipe(gulp.dest('dist/'));
});

To me it seems like this defeats the purpose of Gulp streams... you should just be able to .pipe the compiled HTML into the validator(). For whatever reason, it seems to only work in a separate task.

commented

For whatever reason, it seems to only work in a separate task.

I think he doesn't have a job, nor does he have a job in a separate task, sometimes it only reports running errors.
I tried to change the checked html code to a mess, and he didn't give any hints.
@XhmikosR

True. Most projects I've used this on, I ended up turning it off later when it threw random errors and blocked deployments. Hasn't been super useful.