fixes for docs.rs engine

This commit is contained in:
mat 2023-12-21 03:57:49 -06:00
parent 540d01981c
commit e35a840a5c
2 changed files with 11 additions and 9 deletions

View File

@ -48,14 +48,12 @@ pub fn parse_response(body: &str) -> Option<String> {
let doc_html = doc.inner_html(); let doc_html = doc.inner_html();
let doc_html = ammonia::Builder::default() let doc_html = ammonia::Builder::default()
.link_rel(None) .link_rel(None)
.url_relative(ammonia::UrlRelative::RewriteWithBase( .url_relative(ammonia::UrlRelative::RewriteWithBase(url.clone()))
Url::parse("https://docs.rs").unwrap(),
))
.clean(&doc_html) .clean(&doc_html)
.to_string(); .to_string();
Some(format!( Some(format!(
r#"<h2>Crate <a href="{url}">{title} {version}</a></h2> r#"<h2>Crate <a href="{url}">{title}</a> <span class="infobox-docs_rs-version">{version}</span></h2>
<div class="infobox-docs.rs-answer">{doc_html}</div>"#, <div class="infobox-docs.rs-answer">{doc_html}</div>"#,
url = html_escape::encode_quoted_attribute(&url.to_string()), url = html_escape::encode_quoted_attribute(&url.to_string()),
title = html_escape::encode_text(&title), title = html_escape::encode_text(&title),

View File

@ -222,18 +222,22 @@ h1 {
.infobox p { .infobox p {
margin: 0; margin: 0;
} }
.infobox-stackexchange-answer pre > code, .infobox pre {
.infobox-github-readme pre {
border: 1px solid #234; border: 1px solid #234;
padding: 0.5rem; padding: 0.5rem;
display: block; display: block;
}
.infobox pre > code {
font-weight: normal; font-weight: normal;
} }
.infobox-stackexchange-answer code, .infobox code {
.infobox-github-readme code {
font-weight: bold; font-weight: bold;
} }
.infobox-docs_rs-version {
opacity: 0.5;
font-weight: normal;
font-size: 0.8em;
}
.postsearch-infobox p { .postsearch-infobox p {
margin-bottom: 1em; margin-bottom: 1em;
white-space: pre-wrap;
} }