Fix links enclosed in parenthesis

https://pixwhile.zangetsu.kaizoku.cyou/artworks/107901929
This commit is contained in:
blankie 2023-05-08 17:48:39 +07:00
parent 8de4af2972
commit 9259f7c198
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 13 additions and 5 deletions

View File

@ -125,17 +125,25 @@ static inline std::vector<blankie::html::Node> parse_description_line(const http
std::smatch sm;
while (std::regex_search(str, sm, blankie::murl::full_url_regex)) {
if (sm.prefix().length()) {
nodes.push_back(sm.prefix());
std::string prefix = sm.prefix();
std::string url_str = sm.str(0);
std::string suffix = sm.suffix();
if (prefix.ends_with('(') && url_str.ends_with(')')) {
url_str.pop_back();
suffix.insert(0, 1, ')');
}
if (!prefix.empty()) {
nodes.push_back(std::move(prefix));
}
blankie::murl::Url url(sm.str(0));
std::string url_str = url.is_host_equal("pixiv.net") || url.is_host_equal("www.pixiv.net")
blankie::murl::Url url(std::move(url_str));
url_str = url.is_host_equal("pixiv.net") || url.is_host_equal("www.pixiv.net")
? proxy_pixiv_url(req, config, std::move(url))
: url.to_string();
nodes.push_back(Element("a", {{"href", url_str}}, {url_str}));
str = sm.suffix();
str = std::move(suffix);
}
if (!str.empty()) {
nodes.push_back(std::move(str));