Convert markdown to ansi with support of hyperlinks.
Meant for short snippets of markdown, markdown-to-ansi
supports a subset of (GFM) markdown:
---
)Other markdown is simply returned as markdown (not necessarily as-is because it does go through a parser). Pull requests are welcome to support additional markdown syntax. It's easy to extend because markdown-to-ansi
is built on the micromark
parser and friends.
This package is ESM-only.
Given an example.md
:
## Links
Literal url: https://example.com
Markdown link: [beep](https://example.com)
With formatting: [`boop`](https://example.com)
PR: https://github.com/vweevers/markdown-to-ansi/pull/1
Commit: https://github.com/vweevers/markdown-to-ansi/commit/1234567
Repo: https://github.com/vweevers/markdown-to-ansi
Package: https://www.npmjs.com/package/markdown-to-ansi
---
## Lists, strong and emphasis
- **foo**
- _bar_
- **_baz_**
And running the following example.js
:
import markdownToAnsi from 'markdown-to-ansi'
import fs from 'fs'
const markdown = fs.readFileSync('example.md', 'utf8')
const transform = markdownToAnsi()
const result = transform(markdown)
console.log(result)
Results in:
My terminal doesn't support bold, so let me demonstrate custom styles:
const chalk = require('chalk')
const transform = require('markdown-to-ansi')({
style: {
thematicBreak: chalk.red,
emphasis: chalk.underline,
strong: chalk.red
}
})
Results in:
transform = markdownToAnsi([options])
Factory that returns a transform
function. Options:
stream
: stream to detect support of hyperlinks on, defaults to stdout
width
(number): terminal width, used for thematic breaks, defaults to stream.columns
style
(object): override one or more styles by providing functions that return a formatted string for:
inlineCode
heading
emphasis
strong
thematicBreak
.ansi = transform(markdown)
Takes a markdown
string, returns a string containing ansi escape sequences.
With npm do:
npm install markdown-to-ansi
MIT © Vincent Weevers