aboutsummaryrefslogtreecommitdiff
path: root/src/render/renderer.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-04-12 16:43:23 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-04-12 16:43:23 +0800
commit3e204040c9a9fec810112933d0d81cecbd268943 (patch)
tree9098886ae3fdda61f1815503eb4706190d5b2350 /src/render/renderer.cc
parentc6d7e532c4e010f55ab8c6b7cfd8b36d44779725 (diff)
downloadrwebbrowser-3e204040c9a9fec810112933d0d81cecbd268943.tar.gz
rwebbrowser-3e204040c9a9fec810112933d0d81cecbd268943.tar.xz
feat: implement HTTP redirect support, URL search formatting, image alt text rendering, and improved terminal cursor management
Diffstat (limited to 'src/render/renderer.cc')
-rw-r--r--src/render/renderer.cc16
1 files changed, 15 insertions, 1 deletions
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