Markdown: rendering, settings, themes and documents in panes
DABT renders Markdown into styled, wrapped rows: a document can be shown in a pane (tui.md.show, or the <markdown> tag), edited with a styled source view (tui.md.style), or read as plain text (tui.md.strip). API tables: ../api/markdown.md.
What the renderer draws
| Supported | Not supported |
|---|---|
| ATX and setext headings; headings with block-letter fonts | Math |
| Paragraphs, hard and soft breaks, block quotes, nested lists | Footnotes |
Task lists (- [ ], - [x]) |
Raw HTML beyond the subset |
Fenced and indented code, with highlighting for bash, sh, shell, zsh and json |
Pictures other than local PNGs on kitty/Ghostty |
**bold**, *italic*, ~~strike~~, `code`, <autolinks> |
|
Inline, reference ([t][ref]) and <a> links |
|
| Pipe tables | |
HTML subset: <br>, <img>, <a>, <b>, <i>, <code>, <s>, <hr>, <h1> to <h6>, comments (other tags are dropped, their text kept) |
Wide characters (CJK, emoji) take two cells under a UTF-8 locale. A render also reports the rows of links and headings (TUI_MD_LINK_ROWS, TUI_MD_HEADS, TUI_MD_ANCHORS), which the reading keys below use.
Settings > Markdown
The Settings page writes these keys (see ../api/config.md):
- Profile (
md.profile):dabtfor DABT’s own look, orthemeto take the active theme’s Markdown classes. - Fonts per level (
md.font.1tomd.font.6):style(plain styled text), or a block font such asblock5,blk3,seg3,box3orhalf2. - Tables (
md.tables):grid,rounded,plainorstacked. Overflowing cells wrap or truncate (md.table_overflow). - Images (
md.images):placeholder,alt,hiddenorgraphics. - Styles (
md.style.CLASS): a specFG[/BG][:MODS], for examplewhite/#102030:bold. Thepageclass sets the document background.
Themes
With profile theme, every .md_CLASS rule of the active theme sets that class (fg, bg and mods). A class the theme does not define keeps DABT’s look, and a style set in Settings goes on top:
An app can switch the profile on once, on first run:
tui.config.get md.profile "" profile
[[ -z "$profile" ]] && { tui.config.set md.profile theme; tui.md.config_apply; }
.md_h1 { fg: cyan; mods: bold underline; }
.md_link { fg: blue; mods: underline; }
.md_page { bg: #1e1e2e; }
The classes are h1 to h6, strong, em, code, codeblock, quote, bullet, link, hr, marker, strike, hl_keyword, hl_string, hl_comment, hl_number, hl_var, page, table (the outline of tables) and table_head (the header row). The base look is Theme default in the profile setting; dabt restores DABT’s table.
Reading documents in a pane
A Markdown pane reads with the keyboard and the mouse; nothing has to be bound by the app. The keys act on the keyboard pane, else the pane under the pointer, else the only Markdown pane of the page. f2 shows the list with the keys as bound right now.
| Key | Action |
|---|---|
| left click on a link | follow it (tui.md.click) |
alt+j / alt+k |
next / previous link |
alt+l |
follow the focused link (tui.md.link_open) |
alt+b, alt+left, mouse side button 2 |
back to the previous document or position (tui.md.back) |
alt+right, mouse side button 1 |
forward again (tui.md.forward) |
alt+s |
search (tui.md.search_prompt) |
alt+g / alt+h |
next / previous match |
alt+o |
outline: jump to a heading (tui.md.outline_choose) |
alt+z |
fold or unfold the section at the top (tui.md.fold_toggle) |
alt+y / alt+u |
copy the section / the document (tui.md.copy) |
Reader mode. <markdown pane="docs" src="x.md" keys="reader"/> or tui.md.keys docs reader adds plain keys, in the style of a pager, that act while the pane has the keyboard (click it or press f6): n / N next / previous link, Enter follow, b or Backspace back, / search, ] / [ next / previous match, o outline, z fold, y / Y copy section / document, g / G top / bottom, and j / k scroll as in any pane. A focused text box keeps its keys. none turns the keys off for a pane. The demo’s Docs and Case Study pages use reader mode.
Links to #anchor scroll to that heading; a relative .md link loads that file in the pane (tui.md.on_navigate is called); other links are copied to the clipboard. A pane filled with tui.md.show needs the FILE argument for relative links to resolve. Set a custom handler for the first case with tui.md.on_link.
Images
 draws [img: alt], only the alt text, or nothing, as set by md.images (placeholder, alt, hidden). With graphics it draws the picture itself where it can:
- Terminal: kitty or Ghostty (
tui.md.image_protocolsayskitty). iTerm2 and WezTerm speak another protocol that is not drawn yet; inside tmux nothing is drawn. - Images: a paragraph made only of images,
or[](link); several share a row (badges) and wrap like words. A linked image registers its link. An image inside a sentence or a heading stays a placeholder. - Formats: PNG as it is; SVG with
rsvg-convert, and GIF, JPEG, WebP … with ImageMagick (elseffmpeg) converted once to a PNG in~/.cache/DABT/md-images. Without the tool: placeholder. - Remote images (the README badges) are fetched only when you turn on Fetch remote images (
md.fetch):curlorwgetin the background, shown when they arrive. - How: DABT sends the file path to the terminal once (kitty reads the file itself, so no base64 of the image and no chunking), creates a virtual placement of the right size in cells, and fills the rows with Unicode placeholder cells (
U+10EEEEplus row and column diacritics, the image id in the foreground color). To everything else the picture is ordinary text, so wrapping, scrolling, clipping, folding, search and the row cache need no placement layer. - Size: about 9 x 18 pixels per cell, at most 60 x 20 cells (
TUI_MD_IMAGE_MAX_COLS,TUI_MD_IMAGE_MAX_ROWS) and never wider than the pane; the aspect ratio is kept. The size comes from the PNG header. - Lifetime: images are deleted from the terminal when the document changes and when the app exits.
Set it in Settings > Markdown > Images, or tui.md.images graphics (config md.images=graphics).
Pictures as headings and table cells. A heading that holds only a picture (<h2 id="news"><img src="..." alt="news"></h2>, the README’s section banners) is drawn as the picture in graphics mode; in the other modes, and until the picture has arrived, it is its alt text as a heading, so the outline and #news anchors work either way. A table cell that holds only pictures is drawn as pictures, each no wider than an equal share of the table (the theme tables of the README); a table too narrow for that, or a cell that mixes text and a picture, stays text.
In a chat-style app
alt+ycopies the source of the section at the top of the view andalt+uthe whole document. “Copy the last answer” is yours to write: keep the text and calltui.clipboard.copy(OSC 52: kitty, foot, WezTerm, Alacritty, iTerm2 and tmux withset-clipboard onwork; VTE terminals ignore it).- The plain reading keys (
tui.md.keys PANE reader) act while the pane has the keyboard. In an app with a text input keep the defaultchordsmode, so a focused input keeps its own keys. - Every redraw renders all of the text. For a long transcript draw only the newest part: see Fast apps.
- For
.md_*rules in your theme to apply, switch thethemeprofile on once (see Themes above).
