rustc_errors/markdown/
mod.rs
1use std::io;
6
7use termcolor::{Buffer, BufferWriter, ColorChoice};
8mod parse;
9mod term;
10
11#[derive(Clone, Debug, Default, PartialEq)]
13pub struct MdStream<'a>(Vec<MdTree<'a>>);
14
15impl<'a> MdStream<'a> {
16 #[must_use]
18 pub fn parse_str(s: &str) -> MdStream<'_> {
19 parse::entrypoint(s)
20 }
21
22 pub fn write_termcolor_buf(&self, buf: &mut Buffer) -> io::Result<()> {
24 term::entrypoint(self, buf)
25 }
26}
27
28pub fn create_stdout_bufwtr() -> BufferWriter {
30 BufferWriter::stdout(ColorChoice::Always)
31}
32
33#[derive(Clone, Debug, PartialEq)]
35pub enum MdTree<'a> {
36 Comment(&'a str),
38 CodeBlock {
39 txt: &'a str,
40 lang: Option<&'a str>,
41 },
42 CodeInline(&'a str),
43 Strong(&'a str),
44 Emphasis(&'a str),
45 Strikethrough(&'a str),
46 PlainText(&'a str),
47 Link {
49 disp: &'a str,
50 link: &'a str,
51 },
52 RefLink {
54 disp: &'a str,
55 id: Option<&'a str>,
56 },
57 LinkDef {
59 id: &'a str,
60 link: &'a str,
61 },
62 ParagraphBreak,
65 LineBreak,
67 HorizontalRule,
68 Heading(u8, MdStream<'a>),
69 OrderedListItem(u16, MdStream<'a>),
70 UnorderedListItem(MdStream<'a>),
71}
72
73impl<'a> From<Vec<MdTree<'a>>> for MdStream<'a> {
74 fn from(value: Vec<MdTree<'a>>) -> Self {
75 Self(value)
76 }
77}