Skip to content

tslide/marked-terminal

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Install

npm install marked marked-terminal

Example

var marked = require('marked');
var TerminalRenderer = require('marked-terminal');

marked.setOptions({
  // Define custom renderer
  renderer: new TerminalRenderer()
});

// Show the parsed data
console.log(marked('# Hello \n This is **markdown** printed in the `terminal`'));

This will produce the following:

Screenshot of marked-terminal

Syntax Highlighting

Also have support for syntax highlighting using cardinal. You can override highlight defaults by passing in settings as the second argument for TerminalRenderer, or you can create a .cardinalrc as defined in the cardinal README.

Having the following markdown input:

```js
var foo = function(bar) {
  console.log(bar);
};
foo('Hello');
```

...we will convert it into terminal format:

// Show the parsed data
console.log(marked(exampleSource));

This will produce the following:

Screenshot of marked-terminal

API

Constructur: new TerminalRenderer([options][, highlightOptions])

options

Optional Used to override default styling.

Default values are:

var defaultOptions = {
  // Colors
  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,

  // Reflow and print-out width
  width: 80, // only applicable when reflow is true
  reflowText: false,

  // Should it prefix headers?
  showSectionPrefix: true,

  // Wheter or not to undo marked escaping
  // of enitities (" -> " etc)
  unescape: true,

  // Whether or not to show emojis
  emoji: true,

  // Options passed to cli-table
  tableOptions: {}
};

Example of overriding defaults

marked.setOptions({
  renderer: new TerminalRenderer({
    codespan: chalk.underline.magenta,
  })
});

highlightOptions

Options passed into cardinal. See readme there to see what options to pass.

See more examples

About

A Renderer for the marked project. Allowing you to render Markdown to print to your Terminal

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%