ftml/render/html/element/list.rs
1/*
2 * render/html/element/list.rs
3 *
4 * ftml - Library to parse Wikidot text
5 * Copyright (C) 2019-2025 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::prelude::*;
22use crate::tree::{AttributeMap, ListItem, ListType};
23
24pub fn render_list(
25 ctx: &mut HtmlContext,
26 ltype: ListType,
27 list_items: &[ListItem],
28 attributes: &AttributeMap,
29) {
30 debug!(
31 "Rendering list '{}' (items {})",
32 ltype.name(),
33 list_items.len(),
34 );
35 let list_tag = ltype.html_tag();
36 let mut tag = ctx.html().tag(list_tag);
37
38 tag.attr(attr!(;; attributes)).inner(|ctx| {
39 for list_item in list_items {
40 match list_item {
41 ListItem::Elements {
42 elements,
43 attributes,
44 } => {
45 ctx.html()
46 .li()
47 .attr(attr!(;; attributes))
48 .contents(elements);
49 }
50 ListItem::SubList { element } => {
51 render_element(ctx, element);
52 }
53 }
54 }
55 });
56}