MCPcopy Index your code
hub / github.com/mikaelbr/marked-terminal

github.com/mikaelbr/marked-terminal @v7.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v7.3.0 ↗ · + Follow
45 symbols 118 edges 14 files 0 documented · 0% 14 cross-repo links updated 10mo agov7.2.0 · 2024-10-30★ 49816 open issues

Browse by type

Functions 45 Types & classes 0
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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 npm marked-terminal

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({
  // 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 cli-highlight. You can override highlighting defaults by passing in settings as the second argument for TerminalRenderer.

Having the following markdown input:

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-table3
  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 cli-highlight. See readme there to see what options to pass.

See more examples

Related

Core symbols most depended-on inside this repo

Shape

Function 45

Languages

TypeScript100%

Modules by API surface

index.js28 symbols
tests/markedTerminal-e2e.js4 symbols
tests/e2e.js4 symbols
tests/usage.js3 symbols
tests/markedTerminal-usage.js3 symbols
tests/options.js1 symbols
tests/markedTerminal-options.js1 symbols
tests/_marked.js1 symbols

For agents

$ claude mcp add marked-terminal \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page