ESC
Type to search...
S
Soli Docs

Markdown Class

Convert Markdown text to HTML, with a safe helper for user-generated content.

Markdown.to_html(markdown)

Markdown.to_html(markdown)

Convert a Markdown string to HTML. Supports standard Markdown plus tables, strikethrough, and task lists. Use this for trusted Markdown; raw HTML in the Markdown is preserved.

Parameters

markdown : String - Markdown source text

Returns

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

Convert user-generated Markdown to HTML. Raw HTML is escaped, and unsafe link or image URLs such as javascript: are neutralized.

Parameters

markdown : String - Markdown source text

Returns

String - The rendered safe HTML
html = Markdown.to_safe_html(user.bio)

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

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

Tables

md = "| Name  | Age |\n|-------|-----|\n| Alice | 30  |\n| Bob   | 25  |"
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
  post = Post.find(params["id"])
  html_body = Markdown.to_safe_html(post.body)

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

Building Dynamic Content

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

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

html = Markdown.to_html(md)

Processing API Responses

# Fetch markdown content from an external API
response = Http.get("https://api.example.com/docs/readme")
data = JSON.parse(response.body)
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
  post = Post.find(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_safe_html() for content that comes from users or external sources at runtime — database fields, API responses, user-submitted text.