diff options
author | bors <bors@rust-lang.org> | 2013-05-26 09:35:00 -0700 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2013-05-26 09:35:00 -0700 |
commit | 1f8c4b096da8d7c6436038730fa4a862e1ac91f5 (patch) | |
tree | 9781e1af8bebeb9c49457e386462846d6f044357 | |
parent | f254d119eab514c91fbd6590fba821ec7a0bfd7f (diff) | |
parent | d89a6ceb1b36e7460afece5b3392c8f24f7ef6ce (diff) | |
download | rust-1f8c4b096da8d7c6436038730fa4a862e1ac91f5.tar.gz |
auto merge of #6700 : ben0x539/rust/nestvariantdocs, r=thestinger
This indents all but the first line of multi-line annotations for individual enum variants with four spaces so that pandoc will recognize everything as belonging to the same list item.
Since that introduces `<p>` tags for some list items, I've gone ahead and inserted blank lines after each list item so that consistently get `<p>` tags for all `<li>`s documenting variants. It's a bit less compact now but still tolerable, I think.
-rw-r--r-- | src/librustdoc/markdown_pass.rs | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/librustdoc/markdown_pass.rs b/src/librustdoc/markdown_pass.rs index c6f5dbefb6a..97de4627d6b 100644 --- a/src/librustdoc/markdown_pass.rs +++ b/src/librustdoc/markdown_pass.rs @@ -451,9 +451,13 @@ fn write_variants( fn write_variant(ctxt: &Ctxt, doc: doc::VariantDoc) { assert!(doc.sig.is_some()); let sig = (&doc.sig).get(); + + // space out list items so they all end up within paragraph elements + ctxt.w.put_line(~""); + match copy doc.desc { Some(desc) => { - ctxt.w.put_line(fmt!("* `%s` - %s", sig, desc)); + ctxt.w.put_line(list_item_indent(fmt!("* `%s` - %s", sig, desc))); } None => { ctxt.w.put_line(fmt!("* `%s`", sig)); @@ -461,6 +465,18 @@ fn write_variant(ctxt: &Ctxt, doc: doc::VariantDoc) { } } +fn list_item_indent(item: &str) -> ~str { + let mut indented = ~[]; + for str::each_line_any(item) |line| { + indented.push(line); + } + + // separate markdown elements within `*` lists must be indented by four + // spaces, or they will escape the list context. indenting everything + // seems fine though. + str::connect_slices(indented, "\n ") +} + fn write_trait(ctxt: &Ctxt, doc: doc::TraitDoc) { write_common(ctxt, doc.desc(), doc.sections()); write_methods(ctxt, doc.methods); @@ -807,7 +823,9 @@ mod test { assert!(str::contains( markdown, "\n\n#### Variants\n\ + \n\ \n* `b` - test\ + \n\ \n* `c` - test\n\n")); } @@ -817,7 +835,24 @@ mod test { assert!(str::contains( markdown, "\n\n#### Variants\n\ + \n\ \n* `b`\ + \n\ + \n* `c`\n\n")); + } + + #[test] + fn should_write_variant_list_with_indent() { + let markdown = render( + ~"enum a { #[doc = \"line 1\\n\\nline 2\"] b, c }"); + assert!(str::contains( + markdown, + "\n\n#### Variants\n\ + \n\ + \n* `b` - line 1\ + \n \ + \n line 2\ + \n\ \n* `c`\n\n")); } @@ -827,7 +862,9 @@ mod test { assert!(str::contains( markdown, "\n\n#### Variants\n\ + \n\ \n* `b(int)`\ + \n\ \n* `c(int)` - a\n\n")); } |