What is marked-terminal?
The marked-terminal package is a custom renderer for the marked library, allowing Markdown content to be rendered in the terminal. It converts Markdown into ANSI escape codes to display styled text and other elements directly in the command line interface. This is particularly useful for CLI applications that want to display rich text content or documentation in a more readable and visually appealing format.
What are marked-terminal's main functionalities?
Rendering Headers
This feature allows the rendering of Markdown headers in the terminal with appropriate styling to distinguish them from other text.
const TerminalRenderer = require('marked-terminal');
const marked = require('marked');
marked.setOptions({
renderer: new TerminalRenderer()
});
console.log(marked('# Header 1'));
// This will output a styled Header 1 in the terminal
Rendering Links
This feature enables the display of clickable links in the terminal, making it easier to reference web resources directly from the command line output.
const TerminalRenderer = require('marked-terminal');
const marked = require('marked');
marked.setOptions({
renderer: new TerminalRenderer()
});
console.log(marked('[GitHub](https://github.com)'));
// This will output the text 'GitHub' as a clickable link in the terminal, if supported, or display the URL next to the text.
Rendering Lists
This feature supports the rendering of bullet and numbered lists, enhancing the readability of list information in the terminal.
const TerminalRenderer = require('marked-terminal');
const marked = require('marked');
marked.setOptions({
renderer: new TerminalRenderer()
});
console.log(marked('- Item 1\n- Item 2'));
// This will output a styled list with 'Item 1' and 'Item 2' as its elements.
Other packages similar to marked-terminal
chalk
Chalk is a popular npm package for styling terminal text with ANSI colors but does not directly support Markdown. Unlike marked-terminal, users need to manually specify styles for each piece of text.
ansi-styles
ansi-styles allows for styling terminal output with ANSI escape codes. It provides lower-level access to styling compared to marked-terminal, which abstracts Markdown rendering into styled terminal output.
cli-md
cli-md is a tool similar to marked-terminal that renders Markdown files in the terminal. It focuses on converting Markdown files to terminal output, similar to marked-terminal, but may have different rendering options and styles.
marked-terminal
Early release of a custom Renderer for marked
allowing for printing Markdown to the Terminal.
Could for instance be used to print usage information.
Install
npm install marked marked-terminal
Example
var marked = require('marked');
var TerminalRenderer = require('../');
marked.setOptions({
renderer: new TerminalRenderer()
});
console.log(marked('# Hello \n This is **markdown** printed in the `terminal`'));
This will produce the following:
See more examples