Git Product home page Git Product logo

marked-terminal's Introduction

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:

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

  // 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

Related

marked-terminal's People

Contributors

acemtp avatar amilajack avatar bkendall avatar cameronhunter avatar dependabot[bot] avatar devinivy avatar dzabrzenski avatar eush77 avatar gr2m avatar grigorii-horos avatar hzoo avatar ionicabizau avatar laurent22 avatar lkappeler avatar loklaan avatar mikaelbr avatar millette avatar pvdlg avatar rocky avatar shanehofstetter avatar thlorenz avatar uzitech avatar vansergen avatar wtgtybhertgeghgtwtg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.