Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/valpackett/pug-walk-extract-text
Walk and transform a Pug AST, extracting text nodes from e.g. script and style tags
https://github.com/valpackett/pug-walk-extract-text
pug
Last synced: 8 days ago
JSON representation
Walk and transform a Pug AST, extracting text nodes from e.g. script and style tags
- Host: GitHub
- URL: https://github.com/valpackett/pug-walk-extract-text
- Owner: valpackett
- License: unlicense
- Created: 2015-08-05T10:29:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-15T22:21:41.000Z (almost 7 years ago)
- Last Synced: 2024-10-11T23:21:04.141Z (about 1 month ago)
- Topics: pug
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[![npm version](https://img.shields.io/npm/v/pug-walk-extract-text.svg?style=flat)](https://www.npmjs.org/package/pug-walk-extract-text)
[![npm downloads](https://img.shields.io/npm/dm/pug-walk-extract-text.svg?style=flat)](https://www.npmjs.org/package/pug-walk-extract-text)
[![Build Status](https://img.shields.io/travis/myfreeweb/pug-walk-extract-text.svg?style=flat)](https://travis-ci.org/myfreeweb/pug-walk-extract-text)
[![Unlicense](https://img.shields.io/badge/un-license-green.svg?style=flat)](http://unlicense.org)# pug-walk-extract-text
A small module for extracting text (e.g. inline `script` and `style` tags) from [Pug] files (formerly called Jade)!
Used by [eslint-plugin-pug].
[Pug]: https://pugjs.org
[eslint-plugin-pug]: https://github.com/myfreeweb/eslint-plugin-pug## Installation
Install with [npm], obviously:
```bash
npm install --save-dev pug-parser pug-lexer pug-walk-extract-text
```[npm]: https://www.npmjs.com
## Usage
```javascript
const lexer = require('pug-lexer')
const parser = require('pug-parser')
const walkExtract = require('pug-walk-extract-text')function shouldExtract (node) {
return node.type === 'Tag' && (node.name === 'script' || node.name === 'style')
}const filename = 'some-file.pug'
const text = fs.readFileSync(filename, { encoding: 'utf-8' })
const 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!
By participating in this project you agree to follow the [Contributor Code of Conduct](http://contributor-covenant.org/version/1/4/) and to release your contributions under the Unlicense.
[The list of contributors is available on GitHub](https://github.com/myfreeweb/pug-walk-extract-text/graphs/contributors).
## License
This is free and unencumbered software released into the public domain.
For more information, please refer to the `UNLICENSE` file or [unlicense.org](http://unlicense.org).