npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

metalsmith-pure-text

v1.2.0

Published

A Metalsmith plugin for extracting text from source files using textract.

Downloads

4

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.

Prerequisites

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

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