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
Basic Usage
Section titled “Basic Usage”Render Markdown in the main view:
import mercury as mr
_ = mr.Markdown( "# Hello\nThis is **Markdown** rendered in Mercury.")Layout
Section titled “Layout”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")Basic Markdown Syntax
Section titled “Basic Markdown Syntax”The Markdown widget supports standard Markdown syntax.
Headings
Section titled “Headings”# Heading 1## Heading 2### Heading 3Emphasis
Section titled “Emphasis”*italic***bold*****bold and italic***Unordered list:
- Item A- Item B- Item COrdered list:
1. First2. Second3. Third[Mercury documentation](https://mljar.com/mercury)Inline code:
Use `print()` to display output.Markdown Props
Section titled “Markdown Props”type: string
Markdown content to render.
position
Section titled “position”type: "inline" | "sidebar" | "bottom"
Controls where the widget is rendered.
Default: "inline"
type: string
Unique identifier used to reuse the same widget instance.
Return value and display behavior
Section titled “Return value and display behavior”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.