html_site_generator/html/
text.rs1use crate::html::IsParagraph;
2
3#[derive(Debug, Default)]
4pub enum TextElementStyling {
5 #[default]
6 Normal,
7 Bold,
8 Emphasized,
9 Important,
10 Highlighted,
11}
12
13impl TextElementStyling {
14 fn get_tags(&self) -> [&str; 2] {
15 match self {
16 TextElementStyling::Normal => [""; 2],
17 TextElementStyling::Bold => ["<b>", "</b>"],
18 TextElementStyling::Emphasized => ["<em>", "</em>"],
19 TextElementStyling::Important => ["<strong>", "</strong>"],
20 TextElementStyling::Highlighted => ["<mark>", "</mark>"],
21 }
22 }
23}
24
25#[derive(Debug)]
26pub struct TextElement {
27 raw: String,
28 tag: TextElementStyling,
29}
30
31impl TextElement {
32 pub fn new<S: Into<String>>(text: S) -> Self {
33 Self::new_with_styling(text, TextElementStyling::default())
34 }
35
36 pub fn new_with_styling<S: Into<String>>(text: S, styling: TextElementStyling) -> Self {
37 TextElement {
38 raw: text.into(),
39 tag: styling,
40 }
41 }
42}
43
44impl IsParagraph for TextElement {
45 fn to_raw(&self) -> String {
46 let [suffix, prefix] = self.tag.get_tags();
47
48 format!("{}{}{}", suffix, self.raw, prefix)
49 }
50}