@@ -71,9 +71,16 @@ pub fn strip_fn_arg_types(arg_list: &str) -> String {
7171/// Format a docstring for HTML
7272pub fn format_doc ( docstring : & str ) -> String {
7373 let mut newdoc = docstring. replace ( '<' , "<" ) . replace ( '>' , ">" ) ;
74+
75+ // Remove code block markers entirely (```rust, ```python, ```, etc.)
76+ // These are handled at the line level in format_doc_lines
7477 newdoc = newdoc
75- . replace ( "```rust" , "<code>" )
76- . replace ( "```" , "</code>" ) ;
78+ . replace ( "```rust" , "" )
79+ . replace ( "```python" , "" )
80+ . replace ( "```c" , "" )
81+ . replace ( "```cpp" , "" )
82+ . replace ( "```json" , "" )
83+ . replace ( "```" , "" ) ;
7784
7885 // Replace inline code marks
7986 let mut processed = String :: new ( ) ;
@@ -104,16 +111,39 @@ pub fn format_doc(docstring: &str) -> String {
104111
105112/// Format multi-line documentation for HTML output
106113/// Each line becomes a separate paragraph with proper HTML escaping
114+ /// - Removes ``` code block markers
115+ /// - Converts empty lines to <br/> for proper spacing
107116pub fn format_doc_lines ( doc_lines : & [ String ] ) -> String {
108117 if doc_lines. is_empty ( ) {
109118 return String :: new ( ) ;
110119 }
111120
112- doc_lines
113- . iter ( )
114- . map ( |line| format_doc ( line) )
115- . collect :: < Vec < _ > > ( )
116- . join ( "\n " )
121+ let mut in_code_block = false ;
122+ let mut result = Vec :: new ( ) ;
123+
124+ for line in doc_lines {
125+ let trimmed = line. trim ( ) ;
126+
127+ // Skip code block markers (``` or ```rust, ```python, etc.)
128+ if trimmed. starts_with ( "```" ) {
129+ in_code_block = !in_code_block;
130+ continue ;
131+ }
132+
133+ // Skip lines inside code blocks
134+ if in_code_block {
135+ continue ;
136+ }
137+
138+ // Convert empty lines to <br/> for proper spacing
139+ if trimmed. is_empty ( ) {
140+ result. push ( "<br/>" . to_string ( ) ) ;
141+ } else {
142+ result. push ( format_doc ( line) ) ;
143+ }
144+ }
145+
146+ result. join ( "\n " )
117147}
118148
119149/// Join documentation lines into a single string for display
0 commit comments