marked-terminal

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

  • 所有者: mikaelbr/marked-terminal
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

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.

Build Status npm marked-terminal

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:

...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,

  // Formats the bulletpoints and numbers for lists
  list: function (body, ordered) {/* ... */},

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

  // Should it prefix headers?
  showSectionPrefix: true,

  // Whether 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: {},

  // The size of tabs in number of spaces or as tab characters
  tab: 3 // examples: 4, 2, \t, \t\t

  image: function (href, title, text) {} // function for overriding the default image handling.
};

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

主要指标

概览
名称与所有者mikaelbr/marked-terminal
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2014-07-28 19:47:28
推送于2025-09-02 04:46:24
最后一次提交2025-09-01 22:46:24
发布数37
最新版本名称v7.3.0 (发布于 2025-01-28 20:30:54)
第一版名称v0.1.0 (发布于 2014-07-28 21:54:58)
用户参与
星数461
关注者数3
派生数69
提交数332
已启用问题?
问题数50
打开的问题数13
拉请求数145
打开的拉请求数11
关闭的拉请求数166
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?