@@ -45,6 +45,8 @@ def render(self, node: Node, indent: int = 0, parent_style: Optional[Style] = No
4545 if node .tag in ["head" , "script" , "style" ]:
4646 return
4747
48+ is_block = tag in self .BLOCK_TAGS or tag in self .HEADING_TAGS or tag in self .LIST_TAGS or tag == "pre"
49+
4850 if tag in self .HEADING_TAGS :
4951 self .render_heading (node , tag , indent , parent_style )
5052 elif tag in self .BLOCK_TAGS :
@@ -60,6 +62,9 @@ def render(self, node: Node, indent: int = 0, parent_style: Optional[Style] = No
6062 else :
6163 # default fallback
6264 self .render_fallback (node , indent , parent_style )
65+
66+ if is_block :
67+ self .console .print ()
6368
6469 # ---------- style conversion ----------
6570 def to_rich_style (self , node : Node ) -> Optional [Style ]:
@@ -76,6 +81,8 @@ def to_rich_style(self, node: Node) -> Optional[Style]:
7681 color = None # Ignore CSS variables
7782 elif color == "inherit" :
7883 color = None # Handled by parent_style
84+ elif color == "transparent" :
85+ color = None # Ignore transparent color
7986 elif color .startswith ("rgba(" ):
8087 # Convert rgba(R, G, B, A) to rgb(R, G, B)
8188 try :
@@ -103,17 +110,14 @@ def render_heading(self, node: Node, tag: str, indent: int, parent_style: Option
103110 text_content = self .extract_text (node )
104111
105112 t = Text (text_content .upper (), style = style )
106- self .console .print ("\n " + " " * indent , end = "" )
107113 self .console .print (t , style = Style (bold = True ))
108114
109115 def render_block (self , node : Node , indent : int , parent_style : Optional [Style ] = None ):
110116 style = self .to_rich_style (node )
111117 if parent_style :
112118 style = parent_style + style
113- self .console .print ()
114119 for child in node .children :
115120 self .render (child , indent + 1 , parent_style = style )
116- self .console .print ()
117121
118122 def render_list (self , node : Node , tag : str , indent : int , parent_style : Optional [Style ] = None ):
119123 style = self .to_rich_style (node )
@@ -126,10 +130,10 @@ def render_list(self, node: Node, tag: str, indent: int, parent_style: Optional[
126130 self .render (child , indent + 1 , parent_style = style )
127131 self .list_depth -= 1
128132 elif tag == "li" :
129- bullet = "*" if self .list_depth == 0 else "-" * self .list_depth
130- text_content = self .extract_text (node )
133+ bullet = "*" if self .list_depth <= 1 else "-" * (self .list_depth - 1 )
131134 self .console .print (" " * indent + f"[bold]{ bullet } [/bold] " , end = "" )
132- self .console .print (Text (text_content , style = style ))
135+ for child in node .children :
136+ self .render (child , indent , parent_style = style )
133137
134138 def render_inline (self , node : Node , indent : int , parent_style : Optional [Style ] = None ):
135139 style = self .to_rich_style (node )
@@ -142,8 +146,7 @@ def render_text(self, node: Node, indent: int, parent_style: Optional[Style] = N
142146 style = self .to_rich_style (node )
143147 if parent_style :
144148 style = parent_style + style
145- if node .text .strip ():
146- self .console .print (Text (node .text , style = style ), end = "" )
149+ self .console .print (Text (node .text , style = style ), end = "" )
147150
148151 def render_code (self , node : Node , indent : int ):
149152 """Render <pre><code> blocks or inline code."""
0 commit comments