Skip to content

Markdown

The Markdown widget displays Markdown-formatted text in a Mercury App. It converts Markdown to HTML and renders it as a first-class widget with full Mercury layout support.

Markdown supports headings, lists, code blocks, tables, links, and images. Mercury automatically removes scripts and custom HTML styles, including when you update the widget using .text.

The Markdown rendering dependency is installed automatically with the mercury package, so no additional setup is required.

The widget supports Mercury layout placement via the position argument:

  • "inline" — render in the main notebook flow (default)
  • "sidebar" — render in the sidebar
  • "bottom" — render after all notebook cells

Render Markdown in the main view:

import mercury as mr
_ = mr.Markdown(
"# Hello\nThis is **Markdown** rendered in Mercury."
)

Use position to control where the Markdown is displayed:

import mercury as mr
_ = mr.Markdown(
"## Sidebar note\nYou can put documentation or hints here.",
position="sidebar"
)
import mercury as mr
_ = mr.Markdown(
"_Footer-style text_ shown at the bottom.",
position="bottom"
)

The Markdown widget supports standard Markdown syntax.

# Heading 1
## Heading 2
### Heading 3

*italic*
**bold**
***bold and italic***

Unordered list:

- Item A
- Item B
- Item C

Ordered list:

1. First
2. Second
3. Third

[Mercury documentation](https://mljar.com/mercury)

Inline code:

Use `print()` to display output.


type: string

Markdown content to render.


type: "inline" | "sidebar" | "bottom"

Controls where the widget is rendered.

Default: "inline"


type: string

Unique identifier used to reuse the same widget instance.

Markdown() returns a MarkdownWidget and displays it immediately. Assign the return value to prevent IPython from automatically rendering the same widget a second time when the call is the final expression in a notebook cell:

message = mr.Markdown("**Rendered once**")

Use _ = mr.Markdown(...) when you do not need to access the returned widget.