fixed body text boundary truncation
This commit is contained in:
parent
d514dd5a1c
commit
d9b0eef4df
@ -38,7 +38,7 @@ pub struct Config {
|
|||||||
/// follow redirects
|
/// follow redirects
|
||||||
pub follow: bool,
|
pub follow: bool,
|
||||||
|
|
||||||
#[clap(long = "body")]
|
#[clap(default_value_t = 0, long = "body")]
|
||||||
/// read n bytes of the response document body
|
/// read n bytes of the response document body
|
||||||
pub bodysize: usize,
|
pub bodysize: usize,
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,16 @@ pub fn get_title(body: &String) -> String {
|
|||||||
pub fn read_body(body: &String, lim: usize) -> String {
|
pub fn read_body(body: &String, lim: usize) -> String {
|
||||||
let document = Document::from(body.as_str());
|
let document = Document::from(body.as_str());
|
||||||
|
|
||||||
let mut text = String::new();
|
let mut bodytext = document.find(Name("body")).next().map(|n| n.text()).unwrap_or_else(|| "".to_string());
|
||||||
for tag in document.find(Name("body")) {
|
|
||||||
text.push_str(&tag.text());
|
bodytext = fmtwhitespace(bodytext);
|
||||||
|
if bodytext.len() > lim {
|
||||||
|
bodytext = bodytext
|
||||||
|
.char_indices()
|
||||||
|
.take_while(|(i, _)| *i < lim)
|
||||||
|
.map(|(_, c)| c)
|
||||||
|
.collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
text = fmtwhitespace(text);
|
parsebody(bodytext)
|
||||||
if text.len() > lim {
|
|
||||||
text.truncate(lim);
|
|
||||||
}
|
|
||||||
|
|
||||||
parsebody(text)
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user