1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use crate::node::{Node, NodeContainer};
use crate::components::TextStyle;
use std::borrow::BorrowMut;
use crate::DefaultModifiers;
use crate::{Renderable};

#[derive(Debug, Clone)]
pub struct ComplexText {
    node: Node,
    pub content: String,
    pub style: TextStyle,
}

impl NodeContainer for ComplexText {
    fn get_node(&mut self) -> &mut Node {
        self.node.borrow_mut()
    }
}

impl DefaultModifiers<ComplexText> for ComplexText {}

impl ComplexText {
    pub fn new(content: &str, style: TextStyle) -> Self {
        let mut node = Node::default();
        node.text = Some(markdown::to_html(content.as_ref()));
        ComplexText {
            node,
            content: content.to_string(),
            style,
        }
    }
}

impl Renderable for ComplexText {
    fn render(&self) -> Node {
        let text = self.clone()
            .add_class("text")
            .add_class(format!("text--{:?}", self.style).to_lowercase().as_str());
        text.node
    }
}