Giter Site home page Giter Site logo

gulp-html-extract's Introduction

gulp-html-extract Build Status

Extract text from HTML content into pseudo-files for further Gulp processing.

Install

Install with npm

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

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.

opts.strip

Strip to indented level of first non-whitespace character. Removes whitespace- only starting and ending lines around real text. Default: false

opts.pad

Pad text with newlines to start line in source file. Useful if line numbering of original source file is important (for eslint, stack traces, etc.). Default: false

gulp-html-extract's People

Contributors

ryan-roemer avatar felixzapata avatar ibc avatar

Watchers

Lionel Seguin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.