@@ -117,13 +117,19 @@ fn write_fn(
117
117
fn write_sig ( ctxt : ctxt , sig : option < str > ) {
118
118
alt sig {
119
119
some( sig) {
120
- ctxt. w . write_line ( # fmt ( " %s" , sig) ) ;
120
+ ctxt. w . write_line ( code_block_indent ( sig) ) ;
121
121
ctxt. w . write_line ( "" ) ;
122
122
}
123
123
none { fail "unimplemented" }
124
124
}
125
125
}
126
126
127
+ fn code_block_indent ( s : str ) -> str {
128
+ let lines = str:: lines_any ( s) ;
129
+ let indented = vec:: map ( lines, { |line| #fmt ( " %s" , line) } ) ;
130
+ str:: connect ( indented, "\n " )
131
+ }
132
+
127
133
#[ test]
128
134
fn should_write_the_function_signature ( ) {
129
135
let markdown = test:: render ( "#[doc = \" f\" ] fn a() { }" ) ;
@@ -136,6 +142,23 @@ fn should_insert_blank_line_after_fn_signature() {
136
142
assert str:: contains ( markdown, "fn a()\n \n " ) ;
137
143
}
138
144
145
+ #[ test]
146
+ fn should_correctly_indent_fn_signature ( ) {
147
+ let doc = test:: create_doc ( "fn a() { }" ) ;
148
+ let doc = ~{
149
+ topmod : ~{
150
+ fns : doc:: fnlist ( [ ~{
151
+ sig: some ( "line 1\n line 2" )
152
+ with * doc. topmod . fns [ 0 ]
153
+ } ] )
154
+ with * doc. topmod
155
+ }
156
+ with * doc
157
+ } ;
158
+ let markdown = test:: write_markdown_str ( doc) ;
159
+ assert str:: contains ( markdown, " line 1\n line 2" ) ;
160
+ }
161
+
139
162
fn write_brief (
140
163
ctxt : ctxt ,
141
164
brief : option < str >
@@ -280,6 +303,13 @@ fn should_write_return_description_on_same_line_as_type() {
280
303
#[ cfg( test) ]
281
304
mod test {
282
305
fn render ( source : str ) -> str {
306
+ let doc = create_doc ( source) ;
307
+ let markdown = write_markdown_str ( doc) ;
308
+ #debug ( "markdown: %s" , markdown) ;
309
+ markdown
310
+ }
311
+
312
+ fn create_doc ( source : str ) -> doc:: cratedoc {
283
313
let srv = astsrv:: mk_srv_from_str ( source) ;
284
314
let doc = extract:: from_srv ( srv, "" ) ;
285
315
#debug ( "doc (extract): %?" , doc) ;
@@ -289,9 +319,7 @@ mod test {
289
319
#debug ( "doc (path): %?" , doc) ;
290
320
let doc = attr_pass:: mk_pass ( ) ( srv, doc) ;
291
321
#debug ( "doc (attr): %?" , doc) ;
292
- let markdown = write_markdown_str ( doc) ;
293
- #debug ( "markdown: %s" , markdown) ;
294
- markdown
322
+ doc
295
323
}
296
324
297
325
fn write_markdown_str (
0 commit comments