Skip to content

Instantly share code, notes, and snippets.

@cnaccio
Last active August 29, 2015 14:20
Show Gist options
  • Save cnaccio/1cc8da9c4b72d0451a71 to your computer and use it in GitHub Desktop.
Save cnaccio/1cc8da9c4b72d0451a71 to your computer and use it in GitHub Desktop.
x-ray-html

/node_modules/x-ray-html/index.js

/**
* Module Dependencies
*/

// Any module dependencies go here

/**
* Export the default `driver`
*/

module.exports = driver;

/**
* Initialize the html
* `driver` to support
* html strings instead of
* just a url
* @param {Object} opts
* @return {Function} plugin
*/

function driver(opts) {

	return function plugin(xray) {
	
		xray.request = function request(htmlString, fn) {
			return fn(null, htmlString);
		};
	
		return xray;
	}
}

Usage

var xrayHtml = require('x-ray-html');

xray('<p class="title"><strong>It Works!</strong></p>')
	.use(xrayHtml())
	.select('.title')
	.run(function(err, extraction) {

		// Return on error
		if (err) return console.log(err);
		
		// Log extraction results to console
		console.log(extraction);
	});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment