rustc_errors/markdown/
mod.rs1use std::io;
6
7mod parse;
8mod term;
9
10#[derive(Clone, Debug, Default, PartialEq)]
12pub struct MdStream<'a>(Vec<MdTree<'a>>);
13
14impl<'a> MdStream<'a> {
15 #[must_use]
17 pub fn parse_str(s: &str) -> MdStream<'_> {
18 parse::entrypoint(s)
19 }
20
21 pub fn write_anstream_buf(&self, buf: &mut Vec<u8>) -> io::Result<()> {
23 term::entrypoint(self, buf)
24 }
25}
26
27pub fn create_stdout_bufwtr() -> anstream::Stdout {
29 anstream::Stdout::always(std::io::stdout())
30}
31
32#[derive(Clone, Debug, PartialEq)]
34pub enum MdTree<'a> {
35 Comment(&'a str),
37 CodeBlock {
38 txt: &'a str,
39 lang: Option<&'a str>,
40 },
41 CodeInline(&'a str),
42 Strong(&'a str),
43 Emphasis(&'a str),
44 Strikethrough(&'a str),
45 PlainText(&'a str),
46 Link {
48 disp: &'a str,
49 link: &'a str,
50 },
51 RefLink {
53 disp: &'a str,
54 id: Option<&'a str>,
55 },
56 LinkDef {
58 id: &'a str,
59 link: &'a str,
60 },
61 ParagraphBreak,
64 LineBreak,
66 HorizontalRule,
67 Heading(u8, MdStream<'a>),
68 OrderedListItem(u16, MdStream<'a>),
69 UnorderedListItem(MdStream<'a>),
70}
71
72impl<'a> From<Vec<MdTree<'a>>> for MdStream<'a> {
73 fn from(value: Vec<MdTree<'a>>) -> Self {
74 Self(value)
75 }
76}