ftml/tree/tag.rs
1/*
2 * tree/tag.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
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub enum HtmlTag {
23 Tag(&'static str),
24 TagAndClass {
25 tag: &'static str,
26 class: &'static str,
27 },
28 TagAndStyle {
29 tag: &'static str,
30 style: &'static str,
31 },
32 TagAndId {
33 tag: &'static str,
34 id: String,
35 },
36}
37
38impl HtmlTag {
39 #[inline]
40 pub fn new(tag: &'static str) -> HtmlTag {
41 HtmlTag::Tag(tag)
42 }
43
44 #[inline]
45 pub fn with_class(tag: &'static str, class: &'static str) -> HtmlTag {
46 HtmlTag::TagAndClass { tag, class }
47 }
48
49 #[inline]
50 pub fn with_style(tag: &'static str, style: &'static str) -> HtmlTag {
51 HtmlTag::TagAndStyle { tag, style }
52 }
53
54 #[inline]
55 pub fn with_id(tag: &'static str, id: String) -> HtmlTag {
56 HtmlTag::TagAndId { tag, id }
57 }
58
59 #[inline]
60 pub fn tag(&self) -> &'static str {
61 match self {
62 HtmlTag::Tag(tag) => tag,
63 HtmlTag::TagAndClass { tag, .. } => tag,
64 HtmlTag::TagAndStyle { tag, .. } => tag,
65 HtmlTag::TagAndId { tag, .. } => tag,
66 }
67 }
68}