markdown

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.

Signature

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)

html()

Render markdown to HTML.

Parameters:

Returns:

Example:

markdown = require("markdown")
html = markdown.html("# Hello\n\n**Bold** text")
print(html)

// prints <h1>Hello</h1><p><strong>Bold</strong>text</p>

ansi()

Render markdown to ANSI-formatted output for terminal display.

Parameters:

Returns:

Example:

markdown = require("markdown")
docs = doc("split")
ansi_output = markdown.ansi(docs)
print(ansi_output)

text()

Render markdown to plain text without color codes or formatting.

Parameters:

Returns:

Example:

markdown = require("markdown")
ansi = markdown.text("# Hello\n\n**Bold** text")
print(ansi)

// prints: Hello
// Bold text

Custom Themes

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)

See Also

Recommended (builtin functions):

Other: