Socket
Socket
Sign inDemoInstall

marked-terminal

Package Overview
Dependencies
39
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

marked-terminal

A custom render for marked to output to the Terminal


Version published
Maintainers
1
Weekly downloads
1,920,226
increased by0.75%
Install size
5.43 MB

Weekly downloads

Package description

What is marked-terminal?

The marked-terminal package is a custom renderer for the marked library, allowing Markdown content to be rendered in the terminal. It converts Markdown into ANSI escape codes to display styled text and other elements directly in the command line interface. This is particularly useful for CLI applications that want to display rich text content or documentation in a more readable and visually appealing format.

What are marked-terminal's main functionalities?

Rendering Headers

This feature allows the rendering of Markdown headers in the terminal with appropriate styling to distinguish them from other text.

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

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

console.log(marked('# Header 1'));
// This will output a styled Header 1 in the terminal

Rendering Links

This feature enables the display of clickable links in the terminal, making it easier to reference web resources directly from the command line output.

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

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

console.log(marked('[GitHub](https://github.com)'));
// This will output the text 'GitHub' as a clickable link in the terminal, if supported, or display the URL next to the text.

Rendering Lists

This feature supports the rendering of bullet and numbered lists, enhancing the readability of list information in the terminal.

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

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

console.log(marked('- Item 1\n- Item 2'));
// This will output a styled list with 'Item 1' and 'Item 2' as its elements.

Other packages similar to marked-terminal

Readme

Source

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:

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

  • ink-markdown - Markdown component for Ink

Keywords

FAQs

Last updated on 06 Feb 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc