Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

mikaelbr/marked-terminal

Repository files navigation

Custom Renderer formarkedallowing for printing Markdown to the Terminal. Supports pretty tables, syntaxhighlighting for javascript, and overriding all colors and styles.

Could for instance be used to print usage information.

buildnpm 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

constmarked=require('marked');constTerminalRenderer=require('marked-terminal');marked.setOptions({// Define custom rendererrenderer:newTerminalRenderer()});// Show the parsed dataconsole.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 usingcli-highlight.You can override highlighting defaults by passing in settings as the second argument for TerminalRenderer.

Having the following markdown input:

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

...we will convert it into terminal format:

// Show the parsed dataconsole.log(marked(exampleSource));

This will produce the following:

Screenshot of marked-terminal

API

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

options

OptionalUsed to override default styling.

Default values are:

vardefaultOptions={// Colorscode: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 listslist:function(body,ordered){/* ... */},// Reflow and print-out widthwidth:80,// only applicable when reflow is truereflowText:false,// Should it prefix headers?showSectionPrefix:true,// Whether or not to undo marked escaping// of enitities (" -> " etc)unescape:true,// Whether or not to show emojisemoji:true,// Options passed to cli-table3tableOptions:{},// The size of tabs in number of spaces or as tab characterstab:3// examples: 4, 2, \t, \t\timage:function(href,title,text){}// function for overriding the default image handling.};

Example of overriding defaults

marked.setOptions({renderer:newTerminalRenderer({codespan:chalk.underline.magenta})});

highlightOptions

Options passed intocli-highlight. See readme there to see what options to pass.

Seemore examples

Related

About

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

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp