From 3e204040c9a9fec810112933d0d81cecbd268943 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Sun, 12 Apr 2026 16:43:23 +0800 Subject: feat: implement HTTP redirect support, URL search formatting, image alt text rendering, and improved terminal cursor management --- src/render/renderer.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/render') diff --git a/src/render/renderer.cc b/src/render/renderer.cc index 1af40f1..2b690ca 100644 --- a/src/render/renderer.cc +++ b/src/render/renderer.cc @@ -83,11 +83,14 @@ void render_node( const parser::DomNode& node, // NOLINT(misc-no-recursion) const bool is_header = ( base_tag == "h1" || base_tag == "h2" || base_tag == "h3" || base_tag == "h4" ); const bool is_link = ( base_tag == "a" ); + const bool is_list_item = ( base_tag == "li" ); if ( is_header ) { output += "\n\n\033[1;31m"; } else if ( is_link ) { - output += "\033[4;34m"; // 【核心修复】:必须是 output += ,绝对不能用 std::cout + output += "\033[4;34m"; + } else if ( is_list_item ) { + output += "\n • "; } else if ( base_tag == "p" || base_tag == "div" || is_header ) { if ( !output.empty() && output.back() != '\n' ) { output += "\n"; @@ -112,6 +115,17 @@ void render_node( const parser::DomNode& node, // NOLINT(misc-no-recursion) if ( base_tag == "h1" || base_tag == "p" || base_tag == "div" ) { output += "\n"; } + + if ( base_tag == "img" ) { + std::size_t alt_pos = node.tag_name.find( "alt=\"" ); + if ( alt_pos != std::string::npos ) { + alt_pos += 5; + const std::size_t alt_end = node.tag_name.find( '"', alt_pos ); + output += " \033[90m[Image: " + node.tag_name.substr( alt_pos, alt_end - alt_pos ) + "]\033[0m "; + } else { + output += " \033[90m[IMAGE]\033[0m "; + } + } } } // namespace -- cgit v1.2.3