0.0.1 • Published 10 years ago

gulp-html-extract-x v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

gulp-html-extract-x

Actually, For realz, Extract text from HTML content into pseudo-files for further Gulp processing.

Install

Install with npm

npm install --save-dev gulp-html-extract-x

This is a fork of a great little tool, I just needed it to do my shit.

Example

A good use case is extracting JavaScript from <script> tags and then piping to gulp-jshint. Here, we extract JavaScript from <script> tags and anything matching the code.javascript CSS selector:

var gulp = require("gulp"),
  jshint = require("gulp-jshint"),
  extract = require("gulp-html-extract");

gulp.task("jshint:html", function () {
  gulp
    .src("site/**/*.html")
    .pipe(extract({
      sel: "script, code.javascript"
    }))
    .pipe(jshint())
    .pipe(jshint.reporter("default"))
    .pipe(jshint.reporter("fail"));
});

Pseudo-Files

The plugin extracts each text snippet from an HTML source as an independent faux Vinyl file, with a path of: HTML_PATH-ELEMENT_ID or HTML_PATH-TAG_NAME-INDEX (if no id attribute).

Some examples:

path/to/file1.html-CODE-1
path/to/file2.html-my-identifier

API

extract(opts)

opts.sel

CSS selector string to match on. Default: script.