matthewdown/visitor/html/html_write.rs
1use super::*;
2
3/// A trait to be implemented by types that write HTML output.
4///
5/// An `HtmlVisitor` can be constructed using the
6/// `HtmlVisitor::new_with_html_write` function, which allows it to send its
7/// output to a type implementing this trait, rather than `std::fmt::Write`.
8///
9pub trait HtmlWrite
10{
11 /// Write a text node.
12 ///
13 /// # Arguments
14 ///
15 /// * `s` - The text to include in the text node. This is NOT html-escaped.
16 ///
17 fn text(&mut self, s: &str) -> fmt::Result;
18
19 /// Open an HTML tag.
20 ///
21 /// i.e. Write `<tag>`.
22 ///
23 /// # Arguments
24 ///
25 /// * `tag` - The HTML tag to open.
26 ///
27 fn open(&mut self, tag: &HtmlTag) -> fmt::Result;
28
29 /// Close an HTML tag.
30 ///
31 /// i.e. Write `</tag>`.
32 ///
33 /// # Arguments
34 ///
35 /// * `tag` - The HTML tag to close.
36 ///
37 fn close(&mut self, tag: &HtmlTag) -> fmt::Result;
38
39 /// Write an unpaired HTML tag.
40 ///
41 /// i.e. Write `<tag />`.
42 ///
43 /// # Arguments
44 ///
45 /// * `tag` - The HTML tag to write.
46 ///
47 fn unpaired(&mut self, tag: &HtmlTag) -> fmt::Result;
48}