use crate::plectureparser::{
pabstractcontent::{PAbstractContent, PAbstractLectureBackend},
plabeler::PLabelId,
preferenceurl::PReferenceUrl,
pveccontent::PVecContent
};
#[derive(Debug, Clone, PartialEq)]
pub struct PContentFootnote{
content: PVecContent,
}
impl PContentFootnote{
pub fn new() -> Self{
PContentFootnote {
content: Default::default(),
}
}
pub fn get_content_mut(&mut self) -> &mut PVecContent {
&mut self.content
}
}
impl PAbstractContent for PContentFootnote{
fn has_embeded_label(&self) -> bool{
true
}
fn get_reference_url(&self, current_file: &String, id: usize) -> PReferenceUrl{
PReferenceUrl::from_text(current_file, id, &String::from(&format!("PContentFootnote {}", id)))
}
fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
where TLectureBackend: PAbstractLectureBackend
{
backend.write(&format!("<sup class=\"footnote\" id=\"{}\">", id.get_id()));
backend.write(&String::from("<a href=\"#\">note<span class=\"footnotespan\">"));
self.content.to_html(backend, id);
backend.write(&String::from("</span></a>"));
id.to_html(backend, false);
backend.write(&String::from("</sup>"));
}
}
#[cfg(test)]
mod tests{
use super::*;
use crate::plectureparser::{PContentText, PContentType, plabeler::PLabeler, pstrbackend::PStrBackend};
#[test]
fn test_content_footnote(){
let mut footnote = PContentFootnote::new();
footnote.get_content_mut().add_child(&PContentType::Text(PLabeler::new(43, &PContentText::new(&String::from("An important footnote")))));
let mut backend = PStrBackend::new();
footnote.to_html(&mut backend, &PLabelId::new(42));
assert_eq!(backend.get_body(), &String::from("<sup class=\"footnote\" id=\"42\"><a href=\"#\">note<span class=\"footnotespan\">An important footnote</span></a></sup>"));
}
}