Skip to main content

Module parse

Module parse 

Source
Expand description

Markdown → Doc.

CommonMark nests; a Doc does not. Indent counts list nesting only:

  • a list item’s first paragraph becomes its marker block (bullet, ordered, task) at one level shallower than the open list count, and anything else in that item becomes a child at the list count itself;
  • everything else keeps its kind at the open list count.

A block inside a blockquote carries a Block::quote with the GFM alert the blockquote opened with. A blockquote never adds to the indent. Blockquotes nested in one another flatten to one, and the fixed-point test in [crate::serialize] keeps whatever the first parse decides.

The parse also normalizes what markdown itself would not preserve: leading and trailing whitespace per line, blank lines at a block’s edges, headings and table cells flattened to one line, and ordered runs renumbered consecutively. Each of those is a place where writing the document back out and reading it again would otherwise land somewhere new.

Raw HTML is read as the text it spells. Footnotes and reference-style link definitions are not carried. A setext heading is read as a heading and serialized with #.

Structs§

ParsedDoc
A parse, and where in the source each block came from.

Functions§

is_image
Whether a URL or a path names a picture, by the only thing either says about itself without being fetched — its extension, against what gpui can decode.
is_link
Whether source is one URL of any scheme, scheme://rest — what an explicit link may hold, the way a CommonMark autolink takes any scheme. is_url is the narrower question of what bare text links itself as.
is_url
Whether source is exactly one bare URL, and nothing else.
parse
Parse a markdown document.
parse_at
Parse markdown, and say where offset in it landed in the document.
parse_at_many
parse_at for many offsets: where each landed, in the same order, None for one whose sentinel would change what the source means or that is not on a character boundary.
parse_ranges
parse, keeping the source range each block was parsed from.
parse_ranges_with
parse_ranges with the app’s own marks — see parse_with.
parse_with
parse with the app’s own marks — see crate::Marks.