sciforge_parser/html/
writer.rs1pub fn push_html_escaped(out: &mut String, text: &str) {
2 for c in text.chars() {
3 match c {
4 '&' => out.push_str("&"),
5 '<' => out.push_str("<"),
6 '>' => out.push_str(">"),
7 '"' => out.push_str("""),
8 '\'' => out.push_str("'"),
9 _ => out.push(c),
10 }
11 }
12}
13
14pub fn push_html_row(out: &mut String, label: &str, value: &str) {
15 out.push_str("<tr><td>");
16 push_html_escaped(out, label);
17 out.push_str("</td><td>");
18 push_html_escaped(out, value);
19 out.push_str("</td></tr>\n");
20}
21
22pub fn push_js_escaped(out: &mut String, s: &str) {
23 for ch in s.chars() {
24 match ch {
25 '\\' => out.push_str("\\\\"),
26 '"' => out.push_str("\\\""),
27 '\n' => out.push_str("\\n"),
28 '\r' => out.push_str("\\r"),
29 '<' => out.push_str("\\x3c"),
30 '>' => out.push_str("\\x3e"),
31 _ => out.push(ch),
32 }
33 }
34}