pug-walk-extract-text

1.1.0 • Public • Published

pug-walk-extract-text npm version npm downloads Build Status Dependency Status Unlicense

A small module for extracting text (e.g. inline script and style tags) from Pug files (formerly called Jade)!

Used by eslint-plugin-pug.

Installation

Install with npm, obviously:

npm install --save-dev pug-parser pug-lexer pug-walk-extract-text

Usage

var lexer = require('pug-lexer')
var parser = require('pug-parser')
var walkExtract = require('pug-walk-extract-text')
 
function shouldExtract (node) {
    return node.type === 'Tag' && (node.name === 'script' || node.name === 'style')
}
 
var filename = 'some-file.pug'
var text = fs.readFileSync(filename, { encoding: 'utf-8' })
var results = walkExtract(parser(lexer(text, filename), filename), text, shouldExtract)
// [
//   { text: "body { background: #efefef; color: #444; }\n  html { font-size: 105%; }",
//     indent: 6, line: 9,
//     node: { attrs: [], ..., name: 'style', type: 'Tag' } },
//   { text: "console.log({\n  scri: 'pt'\n})",
//     indent: 6, line: 15,
//     node: { attrs: [], ..., name: 'script', type: 'Tag' } },
// ]

Contributing

Please feel free to submit pull requests! Bugfixes and simple non-breaking improvements will be accepted without any questions :-)

By participating in this project you agree to follow the Contributor Code of Conduct.

License

This is free and unencumbered software released into the public domain.
For more information, please refer to the UNLICENSE file or unlicense.org.

Readme

Keywords

Package Sidebar

Install

npm i pug-walk-extract-text

Weekly Downloads

748

Version

1.1.0

License

Unlicense

Last publish

Collaborators

  • valpackett