docx_reader/documents/elements/
instr_hyperlink.rs1use serde::Serialize;
2
3#[derive(Serialize, Debug, Clone, PartialEq, Default)]
5#[serde(rename_all = "camelCase")]
6pub struct InstrHyperlink {
7 pub target: String,
8 pub anchor: bool,
10}
11
12impl InstrHyperlink {
13 pub fn new(target: impl Into<String>) -> Self {
14 Self {
15 target: target.into(),
16 ..Default::default()
17 }
18 }
19}
20
21impl std::str::FromStr for InstrHyperlink {
22 type Err = ();
23
24 fn from_str(instr: &str) -> Result<Self, Self::Err> {
25 let mut s = instr.split(' ');
26 let mut target = "".to_string();
27 let mut anchor = false;
28 loop {
29 if let Some(i) = s.next() {
30 match i {
31 "\\l" => {
32 anchor = true;
33 }
34 "\\m" => {
35 }
37 "\\n" => {
38 }
40 "\\o" => {
41 let _ = s.next();
43 }
44 "\\t" => {
45 let _ = s.next();
47 }
48 _ => {
49 target = i.replace(""", "").replace("\"", "").to_string();
50 }
51 }
52 } else {
53 if target.is_empty() {
55 return Err(());
56 }
57 return Ok(Self { target, anchor });
58 }
59 }
60 }
61}