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

trimd

v0.11.1

Published

Trim HTML to Markdown from the command line.

Downloads

18

Readme

trimd

Convert between HTML, Markdown, and plain text from the command line.

An online companion tool is available at danburzo.ro/trimd.

Getting started

Install trimd globally using npm:

npm install -g trimd

Or run trimd on the fly using npx:

npx trimd markdown my-file.html

Usage

trimd [command] [options] [file1, [file2, …]]

Trimd accepts one or more input files, or uses the standard input (stdin) when no files are provided. You can also concatenate stdin in addition to other input files using the - operator.

A couple of general options are available:

  • -h, --help - output help information.
  • -v, --version - output program version.
  • --silent - suppress the output of commands.

By default, the results of processing the operands are concatenated to stdout. Use the --write option to write the results back to their respective original files.

Below is a list of supported commands.

trimd markdown

Convert HTML to Markdown.

trimd markdown my-file.html

You can pass your own preferences for generating Markdown with options in the form --md.<option>=<value>, which will get forwarded to remark-stringify:

trimd markdown --md.strong='*' my-file.html

These are the default Markdown options:

const MD_DEFAULTS = {
	fences: true,
	emphasis: '_',
	strong: '_',
	resourceLink: true,
	rule: '-'
};

trimd markup

Convert Markdown to HTML.

trimd markup my-file.md

This command ignores any YAML/TOML front-matter data present in the source file.

Use the --data-url flag to output the HTML as a base64-encoded data: URL. This format can be useful for viewing the HTML content in a browser:

trimd markup --data-url my-file.md | xargs open -a Firefox

Note that at the time of writing, Firefox does not immediately render data: URLs passed from the command line (you need to press Return in the URL bar). See #1892289, which is in the process of being fixed.

Use the --no-sanitize flag to skip the HTML sanitization step. Sanitization should only be disabled when the Markdown input is known to be safe.

trimd remarkup

Simplify HTML by converting it to Markdown and back. The command is more or less the equivalent of trimd markdown | trimd markup.

Use the --data-url flag to output the HTML as a base64-encoded data: URL.

Use the --no-sanitize flag to skip the HTML sanitization step. Sanitization should only be disabled when the HTML input is known to be safe.

trimd remarkdown

Convert Markdown to Markdown. The command accepts the same options as trimd markdown.

trimd remarkdown my-file.md

The trimd remarkdown command is useful for converting Markdown that may contain raw HTML into the Markdown style specified with the --md.<option>=<value> options.

This command preserves any YAML/TOML front-matter data present in the source file.

You can transform the Markdown output by providing a transform function specified in an external JavaScript file and passed via the -t <transform> or --transform=<transform> option.

trimd remarkdown --transform=exclamation.js my-input.md
// File: exclamation.js

export default function exclamation(visit) {
	return function transform(tree, file) {
		visit(tree, 'text', function (node, index, parent) {
			node.value += '!';
		});
	};
}

The default export of your transformer will receive a reference to the visit function from the unist-util-visit package. This is provided as a convenience, you can use it or write your own processing logic.

This export must return a function that transforms the MDAST tree passed as the first argument. See unified.use(Plugin) for more details.

trimd demarkdown

Convert Markdown to plain text.

trimd demarkdown my-file.md

This command ignores any YAML/TOML front-matter data present in the source file.

trimd demarkup

Convert HTML to plain text.

trimd demarkup my-file.html

Plain text is produced according to the algorithm for HTMLElement.innerText.

You can also convert HTML to plain text via Markdown by piping markdown and demarkdown commands:

trimd markdown my-file.html | trimd demarkdown

Acknowledgements

Trimd is a command-line interface on top of a chain of unified.js libraries.

See also

  • Clipboard Inspector, a tool to help you explore the kinds of data available when you paste something on a web page, or drop something onto it.
  • percollate, a command-line tool to turn web pages into beautiful, readable PDF, EPUB, or HTML docs.
  • hred, extract data from HTML (and XML) from the command line, using a syntax inspired by CSS selector.
  • yamatter, inspect and transform YAML frontmatter data from the command line.