Skip to main content

Module marks

Module marks 

Source
Expand description

The inline marks an app spells itself.

Mark is closed — bold, italic, strike, code, links — because every one of those has a spelling CommonMark already reads. Underline, highlight and a colour do not, so they cannot be variants here without this crate inventing markdown for everyone. An app that wants them registers a name and the delimiter that spells it, and the parse and the serializer take it from there:

let marks = markdown::Marks::new().with("highlight", "==");
let doc = markdown::parse_with("a ==lit== word", &marks);
assert_eq!(markdown::serialize_with(&doc, &marks), "a ==lit== word");

The registry is a parameter rather than a global because parse_with and serialize_with are pure — the same reason the highlighter is a function pointer rather than a dependency. set_marks is the gpui-side half, for the editing surface, which has a cx and no other way to know.

A delimiter markdown already spells (*, _, `, ~, [) is yours to avoid: CommonMark reads it first and the registration never fires.

Structs§

MarkPaint
How a custom mark paints. Everything a gpui::TextRun can carry, and nothing a layout would have to move for.
Marks
The custom marks a document is read and written with.

Functions§

set_mark_paint
markdown::set_mark_paint(cx, my_paint) — call once at boot. Without it a custom mark round trips and paints as the text it wraps, which is what an unknown mark should look like rather than a hole.
set_marks
markdown::set_marks(cx, my_marks) — call once at boot, so the editing surface reads and writes the same markdown the app’s own calls do.

Type Aliases§

Painter
What a registered mark looks like. None for a name this build does not paint, which reads as ordinary text.