Skip to content

danburzo/trimd

Repository files navigation

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

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

These are the default HTML options:

const HTML_DEFAULTS = {};

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

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.

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.