Home

Awesome

🎩 charMD

deno badge JSR snapper_deno

A simple, extendable markdown renderer for your terminal.

charMD enables you to render a markdown text into a string, which printed in the terminal provides a well formatted output, instead of plain text.

Showcase

Try it out

To see the general capabilities of this module run:

deno run https://deno.land/x/charmd/example.ts

To see, how a specific markdown gets rendered run:

deno run --allow-read https://deno.land/x/charmd/example.ts ./README.md

Usage

Simply import the module and call the renderMarkdown method with your markdown text.

import { renderMarkdown } from 'https://deno.land/x/charmd/mod.ts';

console.log(renderMarkdown('# Hello world 🌍!'));

Alternatevily you can import from JSR

import { renderMarkdown } from 'jsr:@littletof/charmd';

🧩 Extensions

The module provides a way to extend it functionality with additional extensions, which can be provided in it's options param.

An extension can implement any of the Extension interface's methods, which are:

A simple extension, that renders link with green and blue instead of the built-in cyan would look something like this:

const LinkExt = {
    generateNode(genFn, node: Node, parent: Node, options: Options) {
          if(node.type === 'link') {
            const linkText = node.children?.map(ch => genFn(ch, node, options)).join('') || '';
            const link = `Link with text '${colors.blue(linkText)}' points to ${colors.cyan(node.url!)}`
            return colors.green(link);
          }
      }
}

console.log(renderMarkdown(
    '[charMD](https://github.com/littletof/charmd)',
    { extensions: [LinkExt] }
));

Direct use - cli.ts

For direct use in the terminal run cli.ts:

deno run --allow-net https://deno.land/x/charmd/cli.ts -r https://raw.githubusercontent.com/denoland/deno/master/README.md

Or install it with deno install

It has three options:

Permissions

The module itself requires no permissions to run.

Limitations

These could change in the future, but the aim is to keep the module's complexity minimal.

Also, many of these should also be solvable using extensions.

syntax highlight example

Notes

Contributions

Feedback and contributions are always welcome. Open an issue or a PR, or contact me on the Deno discord.

TODO