- Notifications
You must be signed in to change notification settings - Fork60
A Renderer for the marked project. Allowing you to render Markdown to print to your Terminal
License
mikaelbr/marked-terminal
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
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.
npm install marked marked-terminal
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`');
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:
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:
Constructur:new TerminalRenderer([options][, highlightOptions])
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.};
marked.setOptions({renderer:newTerminalRenderer({codespan:chalk.underline.magenta})});
Options passed intocli-highlight. See readme there to see what options to pass.
- ink-markdown - Markdown component for Ink
About
A Renderer for the marked project. Allowing you to render Markdown to print to your Terminal