DEPRECATED - Use the builtin functions instead: markdown_html(), markdown_ansi(), and markdown_text().
Render markdown text to HTML or ANSI-formatted output for terminal display.
This is not a complete markdown implementation. But it is good for most purposes and it's easy to extend and bend to your wishes. If your application requires extensive markdown features, I suggest adding goldmark (https://github.com/yuin/goldmark) to the go layer and building a custom binary.
markdown = require("markdown")
markdown.html(text) // → HTML (use markdown_html() builtin instead)
markdown.ansi(text [, theme]) // → ANSI with colors (use markdown_ansi() builtin instead)
markdown.text(text) // → Plain text (use markdown_text() builtin instead)
Render markdown to HTML.
text (string) - Markdown text to rendermarkdown = require("markdown")
html = markdown.html("# Hello\n\n**Bold** text")
print(html)
// prints <h1>Hello</h1><p><strong>Bold</strong>text</p>
Render markdown to ANSI-formatted output for terminal display.
text (string) - Markdown text to rendertheme (object, optional) - Custom theme object with color codesmarkdown = require("markdown")
docs = doc("split")
ansi_output = markdown.ansi(docs)
print(ansi_output)
Render markdown to plain text without color codes or formatting.
text (string) - Markdown text to rendermarkdown = require("markdown")
ansi = markdown.text("# Hello\n\n**Bold** text")
print(ansi)
// prints: Hello
// Bold text
Create a custom theme object for ansi():
markdown = require("markdown")
ansi = require("ansi")
custom_theme = {
h1 = ansi.combine(fg="red", bold=true),
h2 = ansi.combine(fg="red"),
code_inline = ansi.combine(fg="blue"),
link = ansi.combine(fg="cyan", underline=true),
reset = ansi.clear
}
ansi_output = markdown.ansi(text, custom_theme)
Recommended (builtin functions):
Other: