For the complete documentation index, see llms.txt. This page is also available as Markdown.

md

Markdown to HTML (CommonMark + GFM via goldmark)

Use md to turn Markdown into HTML (and back with md.fromHTML). It is built for serving pages with serve and composing markup with template.

import "osl/md"

Example

import "osl/md"

log md.toHTML("# Hello\n\n**world**")
// <h1 id="hello">Hello</h1>\n<p><strong>world</strong></p>\n

With serve

Pass the HTML string straight to ctx.html when you want a full response body:

import "osl/md"
import "osl/serve"

*serve.Router app = serve.new()

app.GET("/", def(ctx) -> (
  string body = md.toHTML("# Home\n\nWelcome.")
  ctx.html(200, body)
))

app.run(":8080")

Or wrap it in a small page layout first:

With template

template.renderHTML escapes interpolated values by default. Use {{& name}} when the value is already HTML from md.toHTML:

Using {{body}} (without &) would escape the tags and show the HTML source.

API reference

md.toHTML(source)string

Renders Markdown source to HTML. Enables GitHub Flavored Markdown (tables, strikethrough, autolinks, task lists) and auto heading IDs. Raw HTML tags in the source are not passed through (safe default for untrusted content).

md.toHTMLUnsafe(source)string

Same as md.toHTML, but raw HTML in the Markdown is left as-is. Only use this with trusted input.

md.fromHTML(source)string

The inverse of md.toHTML: converts an HTML source string into Markdown. Headings, emphasis, links, lists, and other common elements map to their Markdown equivalents; unconvertible input yields an empty string.

Notes

  • Standard-library imports accept both import "osl/md" and import "md".

  • Rendering is powered by goldmark.

  • Return values are ordinary OSL strings — pass them to ctx.html, ctx.send, or template slots as needed.

Last updated