Skip to main content

ftml/render/html/
render.rs

1/*
2 * render/html/render.rs
3 *
4 * ftml - Library to parse Wikidot text
5 * Copyright (C) 2019-2026 Wikijump Team
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21use super::context::HtmlContext;
22use super::element::{render_element, render_elements};
23use crate::tree::Element;
24use std::borrow::Cow;
25
26pub trait ItemRender {
27    fn render(&self, ctx: &mut HtmlContext);
28}
29
30impl ItemRender for &'_ str {
31    #[inline]
32    fn render(&self, ctx: &mut HtmlContext) {
33        ctx.push_escaped(self);
34    }
35}
36
37impl ItemRender for &'_ Cow<'_, str> {
38    #[inline]
39    fn render(&self, ctx: &mut HtmlContext) {
40        ctx.push_escaped(self);
41    }
42}
43
44impl ItemRender for String {
45    #[inline]
46    fn render(&self, ctx: &mut HtmlContext) {
47        ctx.push_escaped(self);
48    }
49}
50
51impl ItemRender for &'_ String {
52    #[inline]
53    fn render(&self, ctx: &mut HtmlContext) {
54        ctx.push_escaped(self);
55    }
56}
57
58impl ItemRender for &'_ Element<'_> {
59    #[inline]
60    fn render(&self, ctx: &mut HtmlContext) {
61        render_element(ctx, self)
62    }
63}
64
65impl ItemRender for &'_ [Element<'_>] {
66    #[inline]
67    fn render(&self, ctx: &mut HtmlContext) {
68        render_elements(ctx, self)
69    }
70}
71
72impl ItemRender for &'_ Vec<Element<'_>> {
73    #[inline]
74    fn render(&self, ctx: &mut HtmlContext) {
75        render_elements(ctx, self)
76    }
77}