D.A.B.Tv0.0.33 Tutorial API DABT Tools ↗ GitHub ↗

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): dabt for DABT’s own look, or theme to take the active theme’s Markdown classes.
  • Fonts per level (md.font.1 to md.font.6): style (plain styled text), or a block font such as block5, blk3, seg3, box3 or half2.
  • Tables (md.tables): grid, rounded, plain or stacked. Overflowing cells wrap or truncate (md.table_overflow).
  • Images (md.images): placeholder, alt, hidden or graphics.
  • Styles (md.style.CLASS): a spec FG[/BG][:MODS], for example white/#102030:bold. The page class 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

![alt](src) 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_protocol says kitty). iTerm2 and WezTerm speak another protocol that is not drawn yet; inside tmux nothing is drawn.
  • Images: a paragraph made only of images, ![alt](file) or [![alt](file)](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 (else ffmpeg) 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): curl or wget in 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+10EEEE plus 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+y copies the source of the section at the top of the view and alt+u the whole document. “Copy the last answer” is yours to write: keep the text and call tui.clipboard.copy (OSC 52: kitty, foot, WezTerm, Alacritty, iTerm2 and tmux with set-clipboard on work; 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 default chords mode, 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 the theme profile on once (see Themes above).