metalsmith-pure-text
v1.2.0
Published
A Metalsmith plugin for extracting text from source files using textract.
Downloads
2
Maintainers
Readme
metalsmith-pure-text
A Metalsmith plugin that extracts plain text without HTML tags, Markdown syntax, etc.
It acts as a wrapper for textract and uses its capabilities for handling different file formats.
- Author: Sascha Zarhuber
- GitHub: @saschazar21
- Twitter: @saschazar
- Source: https://github.com/saschazar21/metalsmith-pure-text
- Issues: https://github.com/saschazar21/metalsmith-pure-text/issues
- Releases: https://github.com/saschazar21/metalsmith-pure-text/releases
Prerequisites
- Node.js >= v6
- Metalsmith
Installation
npm install metalsmith-pure-text
Options
The plugin takes an object containing different textract options - please look them up at textracts GitHub repository.
Additionally, some custom options are possible:
encoding
It can be either base64
or html
encoded, to provide a sane string without any unwanted special characters:
{
"encoding": "base64" // ...or "html" for HTML-encoded strings
}
pattern
It can be configured to filter specific file suffixes by providing a pattern
option:
{
"pattern": "**/*.html" // string for one pattern only, array for multiple patterns
}
upperCase/lowerCase
The outcome may be modified to contain only uppercase or lowercase letters. This can be done by adding only one key to the configuration:
{
// either:
"lowerCase": true
// or:
"upperCase": true
}
Usage
Usage is possible via JavaScript API and via Metalsmith CLI:
JavaScript API
Pass the plugin to the Metalsmith instance using its .use()
function:
const metalsmith = require('metalsmith');
const pureText = require('metalsmith-pure-text');
metalsmith.use(pureText({
pattern: ['**/*.html'], // The globbing pattern you want to use. Single pattern also in array.
preserveLineBreaks: true, // textract option: preserve line breaks in extracted text.
// (...)
}));
Metalsmith CLI
Similar to the JavaScript API, the plugin may be used as follows:
{
"plugins": {
"metalsmith-pure-text": {
"pattern": ["**/*.html"],
"preserveLineBreaks": true
}
}
}
Results
After the text extraction is done, the outcome is stored in the text
property of the respective file object, so one may be using it in templates similar like this (handlebars-example):
So you want to see the pure text contents of your file?
Here they are:
<pre>
{{text}}
</pre>
Issues
Please report any bugs or issues to the issues section.
Contribution
Contributors welcome!
Please fork this repository, open a pull request and drop me a line on twitter.
Credits
- @dbashford for textract
- @sindresorhus for multimatch
License
MIT
Milestones
- Support caching
- Handle image data
Changelog
- v1.2.0 - Added
encoding
functionality to encode the outcome either in base64 or html-compatible strings. - v1.1.0 - Added
lowerCase
/upperCase
functionality, removed whitespace from text outcome. - v1.0.0 - Initial version