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
use crate::escape::escape_xml;
use crate::{SvgElement, SvgId};
use std::io::Write;

#[derive(Default)]
pub struct SvgStyle {
    pub content: String,
}

impl From<SvgStyle> for SvgElement {
    fn from(value: SvgStyle) -> Self {
        Self::Style(value)
    }
}

impl SvgStyle {
    pub const fn new(content: String) -> Self {
        Self { content }
    }
    pub(crate) fn write<W: Write>(&self, id: Option<SvgId>, buffer: &mut W) {
        #![allow(clippy::unwrap_used)]
        buffer.write_all(b"<style").unwrap();
        if let Some(id) = id {
            id.write(buffer);
        }
        buffer.write_all(b">").unwrap();
        buffer
            .write_all(escape_xml(&self.content).as_bytes())
            .unwrap();
        buffer.write_all(b"</style>").unwrap();
    }
}