docx_rs/documents/elements/
instr_hyperlink.rs1use serde::Serialize;
2
3#[derive(Serialize, Debug, Clone, PartialEq, Default)]
5#[cfg_attr(feature = "wasm", derive(ts_rs::TS))]
6#[cfg_attr(feature = "wasm", ts(export))]
7#[serde(rename_all = "camelCase")]
8pub struct InstrHyperlink {
9 pub target: String,
10 pub anchor: bool,
12}
13
14impl InstrHyperlink {
15 pub fn new(target: impl Into<String>) -> Self {
16 Self {
17 target: target.into(),
18 ..Default::default()
19 }
20 }
21}
22
23impl std::str::FromStr for InstrHyperlink {
30 type Err = ();
31
32 fn from_str(instr: &str) -> Result<Self, Self::Err> {
33 let mut s = instr.split(' ');
34 let mut target = "".to_string();
35 let mut anchor = false;
36 loop {
37 if let Some(i) = s.next() {
38 match i {
39 "\\l" => {
40 anchor = true;
41 }
42 "\\m" => {
43 }
45 "\\n" => {
46 }
48 "\\o" => {
49 let _ = s.next();
51 }
52 "\\t" => {
53 let _ = s.next();
55 }
56 _ => {
57 target = i.replace(""", "").replace('\"', "").to_string();
58 }
59 }
60 } else {
61 if target.is_empty() {
63 return Err(());
64 }
65 return Ok(Self { target, anchor });
66 }
67 }
68 }
69}