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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***************************************
Auteur : Pierre Aubert
Mail : pierre.aubert@lapp.in2p3.fr
Licence : CeCILL-C
****************************************/
use crate::pcontent::{
PContentText, PContentType, pabstractcontent::{PAbstractContent, PAbstractLectureBackend}, plabeler::{PLabelId, PLabeler}, pveccontent::PVecContent
};
///Content object of the lecture
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PReferenceUrl{
///Url of the PReferenceUrl
url: String,
///Text of url
text: PVecContent,
///Simple text of the reference
p_simple_text: String,
///Label of the PContent
p_label: String,
}
impl PReferenceUrl {
///Create a PReferenceUrl
/// # Parameters
/// - `current_file` : current output file
/// - `id` : id of the PContent to be referenced
/// - `text` : text of the url
pub fn from_text(current_file: &String, id: usize, text: &String) -> Self{
let mut other = PReferenceUrl {
url: String::from(&format!("{}#{}", current_file, id)),
text: Default::default(),
p_simple_text: text.clone(),
p_label: String::from(""),
};
other.get_text_mut().add_child(&PContentType::Text(PLabeler::new(id + 100000000000, &PContentText::new(text))));
return other;
}
///Create a PReferenceUrl
/// # Parameters
/// - `current_file` : current output file
/// - `id` : id of the PContent to be referenced
/// - `text` : text of the link as PVecContent
pub fn from_content(current_file: &String, id: usize, text: &PVecContent) -> Self{
PReferenceUrl {
url: String::from(&format!("{}#{}", current_file, id)),
text: text.clone(),
p_simple_text: String::from(""),
p_label: String::from(""),
}
}
///Create a PReferenceUrl
/// # Parameters
/// - `url` : url of the reference
/// - `text` : text of the link
pub fn from_url(url: &String, text: &String) -> Self{
let mut other = PReferenceUrl {
url: url.clone(),
text: Default::default(),
p_simple_text: text.clone(),
p_label: String::from(""),
};
other.get_text_mut().add_child(&PContentType::Text(PLabeler::new(200000000000, &PContentText::new(text))));
return other;
}
///Get the mutable text of the PReferenceUrl
/// # Returns
/// Mutable text of the PReferenceUrl
pub fn get_text_mut(&mut self) -> &mut PVecContent {
&mut self.text
}
///Get the url of the PReferenceUrl
/// # Returns
/// Url of the PReferenceUrl
pub fn get_url(&self) -> &String{
&self.url
}
///Get the simple text of the PReferenceUrl
/// # Returns
/// Simple text of the PReferenceUrl
pub fn get_simple_text(&self) -> &String{
&self.p_simple_text
}
}
impl PAbstractContent for PReferenceUrl{
///Say if the PContent has an embeded label
/// # Returns
/// True if the PContent has an embeded label, false otherwise
fn has_embeded_label(&self) -> bool{
false
}
///Get the reference url of the current PContent
/// # Parameters
/// - `_current_file` : current output file of the PContent
/// - `_id` : id of the current PContent
/// # Returns
/// Corresponding PReferenceUrl
fn get_reference_url(&self, _current_file: &String, _id: usize) -> PReferenceUrl{
Default::default()
}
///Convert the current struct into html
/// # Parameters
/// - `backend` : backend which write a lecture in files
/// - `id` : id of the current PContent
fn to_html<TLectureBackend>(&self, backend: &mut TLectureBackend, id: &PLabelId)
where TLectureBackend: PAbstractLectureBackend
{
//If there is no url, we do not print the reference
if self.url.is_empty() {
println!("PReferenceUrl::to_html : cannot save reference because url is empty");
return;
}
if self.text.len() == 0 { //If there is not content we repeat the url in the text
backend.write(&format!("<a href=\"{}\">{}</a>", self.url, self.url));
}else{ //If there is a content we convert it into html
backend.write(&format!("<a href=\"{}\"><b>", self.url));
self.text.to_html(backend, id);
backend.write(&String::from("</b></a>"));
}
// backend.write(&phoenix_html_label(&self.p_label, None));
}
}