ESC
Type to search...
S
Soli Docs

Markdown Class

Convert Markdown text to HTML. Render content from databases, APIs, or user input.

Markdown.to_html(markdown)

Markdown.to_html(markdown)

Convert a Markdown string to HTML. Supports standard Markdown plus tables, strikethrough, and task lists.

Parameters

markdown : String - Markdown source text

Returns

String - The rendered HTML
let html = Markdown.to_html("# Hello World")
println(html)  # <h1>Hello World</h1>

Supported Syntax

Headings

Markdown.to_html("# Heading 1")    # <h1>Heading 1</h1>
Markdown.to_html("## Heading 2")   # <h2>Heading 2</h2>
Markdown.to_html("### Heading 3")  # <h3>Heading 3</h3>

Inline Formatting

Markdown.to_html("**bold**")        # <strong>bold</strong>
Markdown.to_html("*italic*")        # <em>italic</em>
Markdown.to_html("`code`")          # <code>code</code>
Markdown.to_html("~~strikethrough~~")  # <del>strikethrough</del>

Links and Images

Markdown.to_html("[Soli](https://example.com)")
# <a href="https://example.com">Soli</a>

Markdown.to_html("![alt](image.png)")
# <img src="image.png" alt="alt">

Lists

# Unordered
Markdown.to_html("- apple\n- banana\n- cherry")

# Ordered
Markdown.to_html("1. first\n2. second\n3. third")

Code Blocks

let md = "```soli\nlet x = 42\nprintln(x)\n```"
let html = Markdown.to_html(md)
# Renders a <pre><code> block

Tables

let md = "| Name  | Age |\n|-------|-----|\n| Alice | 30  |\n| Bob   | 25  |"
let html = Markdown.to_html(md)
# Renders an HTML <table>

Blockquotes

Markdown.to_html("> This is a quote")
# <blockquote><p>This is a quote</p></blockquote>

Common Patterns

Rendering Content from a Database

# In a controller action
def show(req)
    let post = Post.find(req.params["id"])
    let html_body = Markdown.to_html(post.body)

    render("posts/show", { post: post, html_body: html_body })
end

Building Dynamic Content

let title = "Release Notes"
let items = ["Bug fixes", "New features", "Performance"]

let md = "# #{title}\n\n"
for item in items
    md = md + "- #{item}\n"
end

let html = Markdown.to_html(md)

Processing API Responses

# Fetch markdown content from an external API
let response = Http.get("https://api.example.com/docs/readme")
let data = JSON.parse(response.body)
let html = Markdown.to_html(data["content"])

Markdown View Files

The template engine automatically renders .md and .html.md view files as HTML. No controller changes needed — just create a Markdown file in your views directory and it works like any other view.

Resolution Order

When you call render("posts/show", data), the template engine looks for files in this order:

  1. posts/show.html.slv — Soli template (preferred)
  2. posts/show.slv
  3. posts/show.html.md — Markdown view
  4. posts/show.md — Markdown view

If a .slv and .md file both exist for the same view, the .slv file wins.

Static Markdown View

Create a plain Markdown file — it gets converted to HTML and wrapped in your layout automatically.

# About Us

We build **great** software.

- Fast
- Reliable
- Simple

Markdown with Template Tags

Mix Markdown with Soli template tags. Template expressions are evaluated first, then the result is rendered as Markdown.

# <%= title %>

*Published on <%= published_at %>*

<%= body %>

---

Tags: <% for tag in tags %>**<%= tag %>** <% end %>
def show(req)
    let post = Post.find(req.params["id"])
    render("posts/show", {
        title: post.title,
        published_at: post.published_at,
        body: post.body,
        tags: post.tags
    })
end

Markdown Partials

Partials also work with Markdown. Prefix the filename with an underscore as usual.

**Disclaimer:** This content is provided *as-is* without warranties.
<article>
    <h1><%= title %></h1>
    <div class="content"><%- body %></div>
    <%= render "shared/disclaimer" %>
</article>

When to use view files vs Markdown.to_html()

Use .md view files for pages where the content structure is known at design time — documentation pages, about pages, static content with a few dynamic variables.

Use Markdown.to_html() for content that comes from external sources at runtime — database fields, API responses, user-submitted text.