Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ydresponse: fix web reference parse #44

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions src/formatters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,33 @@ Felix ['fi:liks] 费利克斯
<span color="purple">公正评论</span>;<span color="purple">公允评论</span>;<span color="purple">合理评论</span>;<span color="purple">公正的评论</span>
* <span color="goldenrod">conditional comment</span>
<span color="purple">条件注释</span>
"#,
result
);
}

#[test]
fn test_explain_html_3() {
let result = format!(
"\n{}\n",
Client::new()
.lookup_word("暂时", false)
.unwrap()
.explain(&HtmlFormatter::new(false))
);
assert_eq!(
r#"
<u>暂时</u> [<span color="goldenrod">zàn shí</span>] for the time being
<span color="navy"> Word Explanation:</span>
* for the time being
* for the moment
<span color="navy"> Web Reference:</span>
* <span color="goldenrod">暂时的</span>
<span color="purple">科技 temporary</span>;<span color="purple">interim</span>;<span color="purple">provisional</span>;<span color="purple">科技 temporal</span>
* <span color="goldenrod">今天暂时停止</span>
<span color="purple">Groundhog Day</span>;<span color="purple">Groundhog Day Phil Connors</span>;<span color="purple">The Groundhug Day</span>
* <span color="goldenrod">暂时性</span>
<span color="purple">Temporary</span>;<span color="purple">caducity</span>;<span color="purple">transiency</span>;<span color="purple">transient</span>
"#,
result
);
Expand Down
20 changes: 14 additions & 6 deletions src/ydresponse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,13 @@ impl YdResponse {
});
});
html.select(&value).for_each(|x| {
x.text().for_each(|x| {
values.push(x.split(" ; ").map(|x| x.to_string()).collect::<Vec<_>>());
});
let v = x
.text()
.collect::<String>()
.split(" ; ")
.map(|x| x.trim().to_string())
.collect::<Vec<_>>();
values.push(v);
});

let mut webs = vec![];
Expand Down Expand Up @@ -301,9 +305,13 @@ impl YdResponse {
});
});
html.select(&value).for_each(|x| {
x.text().for_each(|x| {
values.push(x.split(" ; ").map(|x| x.to_string()).collect::<Vec<_>>());
});
let v = x
.text()
.collect::<String>()
.split(" ; ")
.map(|x| x.trim().to_string())
.collect::<Vec<_>>();
values.push(v);
});

let mut webs = vec![];
Expand Down
Loading