use std::{collections::HashMap, ops::Range}; use markdown::mdast::{self, AlignKind}; use super::markdown::{span, tree, walk}; mod blocks; mod emoji; pub(crate) mod html; mod html_block; mod sources; mod stack; pub use blocks::{AlertKind, DocumentHeading, alert, is_toc}; use html_block::html_block_text; pub use sources::Escapes; pub(crate) use sources::{inside, lines_at}; use stack::close; /// How a stretch of inline text prints. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Style { Strong, Emphasis, Strike, Code, Link, Math, Footnote, Underline, /// A highlighted run, as ``. Mark, } /// Inline text, its styled stretches and link addresses. #[derive(Clone, Debug, Default, PartialEq)] pub struct Inline { pub text: String, pub styles: Vec<(Range, Style)>, pub links: Vec<(Range, String)>, /// Where each piece was written: drawn start, source span. pub sources: Vec<(usize, Range, Escapes)>, } /// A block of a markdown document. #[derive(Clone, Debug, PartialEq)] pub enum Node { Paragraph(Inline), Heading(u8, Inline), Quote(Vec), Code { language: Option, text: String, /// Where its lines start in the source. from: usize, }, /// Items and blocks; ordered from `start`; tasks carry checkboxes. List { start: Option, items: Vec<(Option, Vec)>, }, /// Each cell's blocks: its text, split at pictures. Table { aligns: Vec, head: Vec>, rows: Vec>>, }, Rule, Math(String), /// A picture, and the link around it. Image { alt: String, url: String, link: Option, /// Its source start. at: usize, }, Footnote { label: String, body: Vec, }, /// A GitHub alert: a quote under its kind's title. Alert { kind: AlertKind, body: Vec, }, /// `[toc]`: the file's headings. Toc(Vec), /// Front matter, its fences cut; lines start at `from`. FrontMatter { text: String, from: usize, }, } /// A tree read against its source and its link definitions. pub struct Reader<'a> { source: &'a str, urls: HashMap, /// Footnotes numbered by their first reference. notes: HashMap, /// Every heading, as `[toc]` lists them. pub headings: Vec, /// Soft breaks as lines, as the screen draws them. lines: bool, } /// An open element, as HTML names it. struct Opened { name: String, start: usize, style: Option