@@ -143,12 +143,78 @@ impl<'a> DocBuild<'a> for Comment {
143
143
result. push ( b. nl ( ) ) ;
144
144
}
145
145
CommentType :: Block => {
146
- let lines: & Vec < & str > = & self . value . split ( '\n' ) . collect ( ) ;
147
- for ( i, line) in lines. iter ( ) . enumerate ( ) {
148
- result. push ( b. txt ( line. trim ( ) ) ) ;
146
+ let mut lines: Vec < & str > = self . value . split ( '\n' ) . collect ( ) ;
147
+
148
+ // JavaDoc formatting
149
+ if self . value . starts_with ( "/**" ) {
150
+ // Handle the first line that might contain both /** and content
151
+ if !lines. is_empty ( ) {
152
+ let first_line = lines[ 0 ] . trim ( ) ;
153
+ if first_line. len ( ) > 3 {
154
+ // Has content after /**
155
+ // Extract the content after /**
156
+ let content = first_line[ 3 ..] . trim ( ) ;
157
+ if !content. is_empty ( ) {
158
+ // Replace first line with just /**
159
+ lines[ 0 ] = "/**" ;
160
+ // Insert the content as a new second line
161
+ lines. insert ( 1 , content) ;
162
+ }
163
+ }
164
+ }
165
+
166
+ for ( i, line) in lines. iter ( ) . enumerate ( ) {
167
+ let trimmed = line. trim ( ) ;
168
+
169
+ if i == 0 {
170
+ // First line (/**) remains unchanged
171
+ result. push ( b. txt ( trimmed) ) ;
172
+ } else if i == lines. len ( ) - 1 {
173
+ if let Some ( before_end) = trimmed. strip_suffix ( "*/" ) {
174
+ let content = before_end. trim ( ) ;
175
+ if content. is_empty ( ) {
176
+ result. push ( b. txt ( " */" ) ) ;
177
+ } else {
178
+ result. push ( b. txt ( format ! ( " * {}" , content) ) ) ; // First line: Preserve content
179
+ result. push ( b. nl ( ) ) ; // Newline before closing */
180
+ result. push ( b. txt ( " */" ) ) ; // Second line: Properly close the comment
181
+ }
182
+ } else {
183
+ result. push ( b. txt ( " */" ) ) ; // Fallback (shouldn't happen in valid JavaDoc)
184
+ }
185
+ } else if trimmed. is_empty ( ) {
186
+ // Handle empty lines
187
+ result. push ( b. txt ( " *" ) ) ;
188
+ } else {
189
+ // Handle content lines
190
+ if let Some ( after_star) = trimmed. strip_prefix ( '*' ) {
191
+ // Line has a star - normalize to exactly one space
192
+ let content = after_star. trim_start ( ) ; // Remove all leading spaces
193
+ if content. is_empty ( ) {
194
+ // Just a star with no content
195
+ result. push ( b. txt ( " *" ) ) ;
196
+ } else {
197
+ // Star with content - add exactly one space
198
+ result. push ( b. txt ( format ! ( " * {}" , content) ) ) ;
199
+ }
200
+ } else {
201
+ // Line doesn't have a star, add standard formatting
202
+ result. push ( b. txt ( format ! ( " * {}" , trimmed) ) ) ;
203
+ }
204
+ }
205
+
206
+ if i < lines. len ( ) - 1 {
207
+ result. push ( b. nl ( ) ) ;
208
+ }
209
+ }
210
+ } else {
211
+ // Regular block comment (non-JavaDoc)
212
+ for ( i, line) in lines. iter ( ) . enumerate ( ) {
213
+ result. push ( b. txt ( line. trim ( ) ) ) ;
149
214
150
- if i < lines. len ( ) - 1 {
151
- result. push ( b. nl ( ) ) ;
215
+ if i < lines. len ( ) - 1 {
216
+ result. push ( b. nl ( ) ) ;
217
+ }
152
218
}
153
219
}
154
220
}
0 commit comments