Markdown rendering

Mouser renders Markdown (CommonMark with tables, strikethrough and task lists) instead of showing the raw markup:

What is drawn

Markdown Drawn as
# Heading bold; levels 1–2 in the theme accent, level 1 underlined
**bold**, *italic*, ~~strike~~ bold, slanted, struck through
`code` on a small rounded shade
fenced / indented code monospaced on a rounded background box; fenced blocks with a known language are syntax highlighted (Code)
> quote an accent bar per level
lists, - [x] tasks • or 1. marks, nested lists indented
[text](https://github.com/WeirdBrains/mouser/blob/main/docs/url) underlined in the accent
tables aligned columns with │ and a rule under the header; wide tables shrink, cells end in …
--- a rule across the width
![alt](https://github.com/WeirdBrains/mouser/blob/main/docs/img) an [image: alt] placeholder

Text wraps at word boundaries to the width it is shown at (long words break). Everything is one cell grid with the terminal font, so previews use the same face and theme colours as the rest of Mouser.

Code blocks

A fenced block's language tag picks the highlighter (only the first word counts, so rust,ignore and py title=x.py work):

Language Tags
Rust rust, rs
Python python, py
JavaScript / TypeScript js, jsx, ts, tsx, javascript, typescript
Shell sh, bash, zsh, shell, console, fish
JSON, TOML, YAML json, toml, yaml, yml
Go go
C / C++ c, h, cpp, c++, cc, hpp
HTML / XML, CSS html, xml, svg, css, scss
SQL sql
Markdown, diffs md, markdown, diff, patch

Any other tag, or none, stays plain monospace. Keywords, types, strings, numbers, function calls, comments and diff +/- lines take colours from the active theme's ANSI palette (the bright slots on dark themes, the normal ones on light themes; comments are muted text), so every theme brings its own highlighting. mouser md writes the same classes as ANSI colours, which your terminal's theme resolves.

The highlighter is a small built-in lexer (no extra dependencies). It works line by line and only carries state forward (an open /* comment */), so a code block that is still streaming in never recolours the rows above it.

In the terminal: mouser md

mouser md README.md            # one file
        mouser md a.md b.md            # one after another
        curl -s …/notes.md | mouser md # stdin (or `mouser md -`)
        mouser md --width 72 NOTES.md  # lay out at 72 columns
        mouser md --color never x.md   # plain text, no escapes
        

The output is ordinary text with SGR styles (bold, italic, underline, colours, a background behind code blocks) and OSC 8 hyperlinks, so it lands in the grid and the scrollback like any other output: scroll back with the wheel or shift+pageup, select and copy it, run it over SSH or inside tmux, in Mouser or any other terminal.

Links are OSC 8: Mouser makes them clickable (ctrl+click), other terminals that support OSC 8 do the same, and the rest show the link text.

How it works

mouser_core::markdown parses with pulldown-cmark and lays the document out as rows of styled spans (bold, italic, code, link, strike, muted; heading level, quote depth, indent). Each surface draws those rows its own way: the frame draws them as panel items in the theme's colours (commander, chat), and mouser md writes them as SGR-styled text (markdown::to_ansi).

Control characters in the text and in link targets are shown as � (or dropped), never passed through, so a file cannot send escape sequences to your terminal.

The parser and highlighter live in mouser-mode-api behind its markdown feature (mouser_mode_api::markdown, ::highlight), so mode plugins draw the same Markdown; mouser_core re-exports both. markdown::items turns Markdown into panel items for any action type.

Source: docs/markdown.md