marked-terminal
Custom Renderer for marked
allowing for printing Markdown to the Terminal. Supports pretty tables, syntax
highlighting for javascript, and overriding all colors and styles.
Could for instance be used to print usage information.
![npm marked-terminal](https://img.shields.io/npm/v/marked-terminal.svg)
Install
npm install marked marked-terminal
Example
import { marked } from 'marked';
import { markedTerminal } from 'marked-terminal';
marked.use(markedTerminal([options][, highlightOptions]));
marked.parse('# Hello \n This is **markdown** printed in the `terminal`');
Using older versions
const marked = require('marked');
const TerminalRenderer = require('marked-terminal');
marked.setOptions({
renderer: new TerminalRenderer()
});
console.log(
marked('# Hello \n This is **markdown** printed in the `terminal`')
);
This will produce the following:
![Screenshot of marked-terminal](https://github.com/mikaelbr/marked-terminal/raw/HEAD/./screenshot.png)
Syntax Highlighting
Also have support for syntax highlighting using cli-highlight.
You can override highlighting defaults by passing in settings as the second argument for TerminalRenderer.
Having the following markdown input:
```js
var foo = function(bar) {
console.log(bar);
};
foo('Hello');
```
...we will convert it into terminal format:
console.log(marked(exampleSource));
This will produce the following:
![Screenshot of marked-terminal](https://github.com/mikaelbr/marked-terminal/raw/HEAD/./screenshot2.png)
API
Constructur: new TerminalRenderer([options][, highlightOptions])
options
Optional
Used to override default styling.
Default values are:
var defaultOptions = {
code: chalk.yellow,
blockquote: chalk.gray.italic,
html: chalk.gray,
heading: chalk.green.bold,
firstHeading: chalk.magenta.underline.bold,
hr: chalk.reset,
listitem: chalk.reset,
table: chalk.reset,
paragraph: chalk.reset,
strong: chalk.bold,
em: chalk.italic,
codespan: chalk.yellow,
del: chalk.dim.gray.strikethrough,
link: chalk.blue,
href: chalk.blue.underline,
list: function (body, ordered) {},
width: 80,
reflowText: false,
showSectionPrefix: true,
unescape: true,
emoji: true,
tableOptions: {},
tab: 3
image: function (href, title, text) {}
};
Example of overriding defaults
marked.setOptions({
renderer: new TerminalRenderer({
codespan: chalk.underline.magenta
})
});
highlightOptions
Options passed into cli-highlight. See readme there to see what options to pass.
See more examples
Related