diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-04-01 13:52:57 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-04-01 13:52:57 +0200 |
commit | 4943f3d29c513f6d1e283cfffc30b78d9728902b (patch) | |
tree | 1e4c8c5e2246ce9a8908583e4486c8d8ac2b45db | |
parent | 30c93d5de455c494c7be3a37571cfcd9688560fe (diff) |
4chan: fix link in quote
-rw-r--r-- | src/NetUtils.cpp | 2 | ||||
-rw-r--r-- | src/Program.cpp | 2 | ||||
-rw-r--r-- | src/plugins/Fourchan.cpp | 109 |
3 files changed, 70 insertions, 43 deletions
diff --git a/src/NetUtils.cpp b/src/NetUtils.cpp index 2dab2b8..70f2f32 100644 --- a/src/NetUtils.cpp +++ b/src/NetUtils.cpp @@ -248,6 +248,8 @@ namespace QuickMedia { --url_length; else if(prev_char == ')' && parentheses_depth != 0) --url_length; + else if(prev_char < 32) + --url_length; if(url_length > 0) ranges.push_back({url_start, url_length}); } diff --git a/src/Program.cpp b/src/Program.cpp index 5e54971..0929a34 100644 --- a/src/Program.cpp +++ b/src/Program.cpp @@ -441,7 +441,7 @@ int exec_program_async(const char **args, pid_t *result_process_id) { setsid(); signal(SIGHUP, SIG_IGN); - // Daemonize child to make the parent the init process which will reap the zombie child + // Daemonize child to make the init process the parent which will reap the zombie child pid_t second_child = vfork(); if(second_child == 0) { // child execvp(args[0], (char* const*)args); diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index aa941d5..87c6364 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -145,6 +145,7 @@ namespace QuickMedia { TEXT, QUOTE, // >, Set for span QUOTE_CONTINUE, // Set for span + QUOTE_END, QUOTELINK, // >>POSTNO, Set for a DEADLINK, // Set for span CROSSBOARD_LINK, // Set for a @@ -208,8 +209,14 @@ namespace QuickMedia { case HTML_PARSE_TAG_END: { if(!parse_userdata->html_node.empty()) { const NodeType node_type = tag_name_to_node_type(html_parser->tag_name); - if(node_type != (NodeType)-1) + if(node_type == parse_userdata->html_node.top().node_type) { + if(node_type == NodeType::SPAN) { + CommentPiece comment_piece; + comment_piece.type = CommentPiece::Type::QUOTE_END; + parse_userdata->callback(comment_piece); + } parse_userdata->html_node.pop(); + } } break; } @@ -254,7 +261,7 @@ namespace QuickMedia { } case NodeType::SPAN: { if(html_node.klass == "quote") { - comment_piece.type = html_node.output_count ? CommentPiece::Type::QUOTE : CommentPiece::Type::QUOTE_CONTINUE; + comment_piece.type = html_node.output_count == 0 ? CommentPiece::Type::QUOTE : CommentPiece::Type::QUOTE_CONTINUE; } else if(html_node.klass == "deadlink") { comment_piece.type = CommentPiece::Type::DEADLINK; } else { @@ -293,50 +300,68 @@ namespace QuickMedia { static std::string html_to_text(const char *html_source, size_t size, std::unordered_map<int64_t, size_t> &comment_by_postno, BodyItems &result_items, size_t body_item_index) { std::string comment_text; - extract_comment_pieces(html_source, size, - [&comment_text, &comment_by_postno, &result_items, body_item_index](const CommentPiece &cp) { - switch(cp.type) { - case CommentPiece::Type::TEXT: - comment_text += std::move(cp.text); - break; - case CommentPiece::Type::QUOTE: - comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(120, 153, 34), FORMATTED_TEXT_FLAG_COLOR); - break; - case CommentPiece::Type::QUOTE_CONTINUE: - comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(120, 153, 34), FORMATTED_TEXT_FLAG_COLOR); - break; - case CommentPiece::Type::QUOTELINK: { - auto it = comment_by_postno.find(cp.quote_postnumber); - if(it == comment_by_postno.end()) { - // TODO: Link this quote to a 4chan archive that still has the quoted comment (if available) - comment_text += Text::formatted_text(std::move(cp.text) + " (DEAD)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); - } else { - static_cast<ImageBoardBodyItemData*>(result_items[body_item_index]->extra.get())->replies_to.push_back(it->second); - static_cast<ImageBoardBodyItemData*>(result_items[it->second]->extra.get())->replies.push_back(body_item_index); - result_items[it->second]->add_reaction(">>" + std::to_string(static_cast<ImageBoardBodyItemData*>(result_items[body_item_index]->extra.get())->post_id), nullptr, get_theme().replies_text_color); - if(it->second == 0) - comment_text += Text::formatted_text(std::move(cp.text) + " (OP)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); - else - comment_text += Text::formatted_text(std::move(cp.text), get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); - } - break; + std::string pending_quote; + + extract_comment_pieces(html_source, size, [&](const CommentPiece &cp) { + if(!pending_quote.empty() && cp.type != CommentPiece::Type::QUOTE_CONTINUE) { + comment_text += Text::formatted_text(std::move(pending_quote), mgl::Color(120, 153, 34), FORMATTED_TEXT_FLAG_COLOR); + pending_quote.clear(); + } + + switch(cp.type) { + case CommentPiece::Type::TEXT: + comment_text += std::move(cp.text); + break; + case CommentPiece::Type::QUOTE: + pending_quote = std::move(cp.text); + break; + case CommentPiece::Type::QUOTE_CONTINUE: + pending_quote.append(cp.text.begin(), cp.text.end()); + break; + case CommentPiece::Type::QUOTE_END: + if(!pending_quote.empty()) { + comment_text += Text::formatted_text(std::move(pending_quote), mgl::Color(120, 153, 34), FORMATTED_TEXT_FLAG_COLOR); + pending_quote.clear(); } - case CommentPiece::Type::DEADLINK: + break; + case CommentPiece::Type::QUOTELINK: { + auto it = comment_by_postno.find(cp.quote_postnumber); + if(it == comment_by_postno.end()) { // TODO: Link this quote to a 4chan archive that still has the quoted comment (if available) comment_text += Text::formatted_text(std::move(cp.text) + " (DEAD)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); - break; - case CommentPiece::Type::CROSSBOARD_LINK: - // TODO: Link this to another thread and allow navigating to it - comment_text += Text::formatted_text(std::move(cp.text) + " (Cross-thread)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); - break; - case CommentPiece::Type::CODEBLOCK: - // TODO: Use a different colored background - if(!comment_text.empty() && comment_text.back() != '\n') - comment_text += '\n'; - comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(255, 255, 255, 255), FORMATTED_TEXT_FLAG_CODE); - break; + } else { + static_cast<ImageBoardBodyItemData*>(result_items[body_item_index]->extra.get())->replies_to.push_back(it->second); + static_cast<ImageBoardBodyItemData*>(result_items[it->second]->extra.get())->replies.push_back(body_item_index); + result_items[it->second]->add_reaction(">>" + std::to_string(static_cast<ImageBoardBodyItemData*>(result_items[body_item_index]->extra.get())->post_id), nullptr, get_theme().replies_text_color); + if(it->second == 0) + comment_text += Text::formatted_text(std::move(cp.text) + " (OP)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); + else + comment_text += Text::formatted_text(std::move(cp.text), get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); + } + break; } - }); + case CommentPiece::Type::DEADLINK: + // TODO: Link this quote to a 4chan archive that still has the quoted comment (if available) + comment_text += Text::formatted_text(std::move(cp.text) + " (DEAD)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); + break; + case CommentPiece::Type::CROSSBOARD_LINK: + // TODO: Link this to another thread and allow navigating to it + comment_text += Text::formatted_text(std::move(cp.text) + " (Cross-thread)", get_theme().attention_alert_text_color, FORMATTED_TEXT_FLAG_COLOR); + break; + case CommentPiece::Type::CODEBLOCK: + // TODO: Use a different colored background + if(!comment_text.empty() && comment_text.back() != '\n') + comment_text += '\n'; + comment_text += Text::formatted_text(std::move(cp.text), mgl::Color(255, 255, 255, 255), FORMATTED_TEXT_FLAG_CODE); + break; + } + }); + + if(!pending_quote.empty()) { + comment_text += Text::formatted_text(std::move(pending_quote), mgl::Color(120, 153, 34), FORMATTED_TEXT_FLAG_COLOR); + pending_quote.clear(); + } + return comment_text; } |