term-md
v1.0.0
Published
Render Markdown strings for terminal output.
Readme
term-md
Render Markdown strings for terminal output.
Install
npm install term-mdUsage
import termMd from 'term-md';
const output = termMd('# Title\n\nHello **terminal** `markdown`.');
console.log(output);Override styles
import chalk from 'chalk';
import termMd from 'term-md';
const output = termMd('Read [docs](https://example.com).', {
heading: chalk.cyan.bold,
link: chalk.green,
href: chalk.gray.underline,
codespan: chalk.yellow,
});Reflow text
import termMd from 'term-md';
console.log(
termMd('A long paragraph that should wrap for narrow terminals.', {
reflowText: true,
width: 40,
}),
);Custom list wrapper
import termMd from 'term-md';
console.log(
termMd('- first\n- second', {
list(body, ordered) {
return ordered ? `ordered:\n${body}` : `unordered:\n${body}`;
},
}),
);Options
import chalk from 'chalk';
const options = {
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,
list(body, ordered) {
return body;
},
width: 80,
reflowText: false,
showSectionPrefix: true,
unescape: true,
emoji: true,
tableOptions: {
paddingLeft: 0,
paddingRight: 0,
colWidths: [],
},
tab: 3,
};Import defaults
import termMd, { defaultOptions } from 'term-md';
const output = termMd('~~old~~ **new**', {
...defaultOptions,
del: (value) => value,
});