diff --git a/src/engines/postsearch/github.rs b/src/engines/postsearch/github.rs index d631592..42b8de9 100644 --- a/src/engines/postsearch/github.rs +++ b/src/engines/postsearch/github.rs @@ -1,11 +1,11 @@ use scraper::{Html, Selector}; use url::Url; -use crate::engines::{Response, CLIENT}; +use crate::engines::{answer::regex, Response, CLIENT}; pub fn request(response: &Response) -> Option { for search_result in response.search_results.iter().take(8) { - if search_result.url.starts_with("https://github.com/") { + if regex!(r"^https:\/\/github\.com\/[\w-]+\/[\w.-]+$").is_match(&search_result.url) { return Some(CLIENT.get(search_result.url.as_str())); } } @@ -43,6 +43,8 @@ pub fn parse_response(body: &str) -> Option { let mut readme_html = ammonia::Builder::default() .link_rel(None) + .add_allowed_classes("div", &["markdown-alert"]) + .add_allowed_classes("p", &["markdown-alert-title"]) .url_relative(ammonia::UrlRelative::RewriteWithBase( Url::parse("https://github.com").unwrap(), )) diff --git a/src/web/assets/style.css b/src/web/assets/style.css index ad32d4c..a18532d 100644 --- a/src/web/assets/style.css +++ b/src/web/assets/style.css @@ -268,6 +268,13 @@ h1 { font-weight: normal; font-size: 0.8em; } +.infobox-github-readme .markdown-alert { + padding-left: 0.5em; + border-left: 0.25em solid #234; +} +.infobox-github-readme .markdown-alert-title { + font-weight: bold; +} .postsearch-infobox p { margin-bottom: 1em; }