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
use std::{path::Path, sync::Arc};
use anyhow::Result;
use wild_doc_script::{IncludeAdaptor, Vars};
use crate::r#const::*;
use super::Parser;
impl<I: IncludeAdaptor + Send> Parser<I> {
pub(super) async fn get_include_content(
&mut self,
attr: Vars,
with_parse: bool,
) -> Result<Vec<u8>> {
if let Some(src) = attr.get(&*SRC) {
let src = src.as_string();
let (xml, filename) = self
.include_adaptor
.lock()
.include(Path::new(src.as_str()))
.map_or_else(
|| {
let mut r = (None, Arc::clone(&_BLANK));
if let Some(substitute) = attr.get(&*SUBSTITUTE) {
let substitute = substitute.as_string();
if let Some(xml) = self
.include_adaptor
.lock()
.include(Path::new(substitute.as_str()))
{
r = (Some(xml), substitute);
}
}
r
},
|xml| (Some(xml), src),
);
if let Some(xml) = xml {
if !xml.is_empty() {
return Ok(if with_parse {
self.include_stack.push(filename);
let mut pos = 0;
let r = self.parse(xml.as_slice(), &mut pos).await?;
self.include_stack.pop();
r
} else {
xml.as_ref().clone()
});
}
}
}
Ok(b"".to_vec())
}
}