]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #41049 - GuillaumeGomez:rustdoc-ordered-list, r=frewsxcv
authorCorey Farwell <coreyf@rwell.org>
Wed, 5 Apr 2017 16:44:36 +0000 (12:44 -0400)
committerGitHub <noreply@github.com>
Wed, 5 Apr 2017 16:44:36 +0000 (12:44 -0400)
Handle ordered lists as well

Part of #40912.

r? @rust-lang/docs

src/librustdoc/html/markdown.rs
src/test/rustdoc/test-lists.rs [new file with mode: 0644]

index 0b098fb14f1904c2f43a8879ab061d8a8cbe10d3..245a3946a3709c31f8c5e0c759d927e037504d7d 100644 (file)
@@ -427,12 +427,15 @@ fn list_item(parser: &mut ParserWrapper, buffer: &mut String,
                     looper(parser, &mut content, Some(x), toc_builder, shorter, &mut None);
                 }
             }
+            if shorter.is_compact() {
+                break
+            }
         }
         buffer.push_str(&format!("<li>{}</li>", content));
     }
 
     fn list(parser: &mut ParserWrapper, buffer: &mut String, toc_builder: &mut Option<TocBuilder>,
-            shorter: MarkdownOutputStyle) {
+            shorter: MarkdownOutputStyle, is_sorted_list: bool) {
         debug!("List");
         let mut content = String::new();
         while let Some(event) = parser.next() {
@@ -445,8 +448,13 @@ fn list(parser: &mut ParserWrapper, buffer: &mut String, toc_builder: &mut Optio
                     looper(parser, &mut content, Some(x), toc_builder, shorter, &mut None);
                 }
             }
+            if shorter.is_compact() {
+                break
+            }
         }
-        buffer.push_str(&format!("<ul>{}</ul>", content));
+        buffer.push_str(&format!("<{0}>{1}</{0}>",
+                                 if is_sorted_list { "ol" } else { "ul" },
+                                 content));
     }
 
     fn emphasis(parser: &mut ParserWrapper, buffer: &mut String,
@@ -516,8 +524,8 @@ fn looper<'a>(parser: &'a mut ParserWrapper, buffer: &mut String, next_event: Op
                 Event::Start(Tag::BlockQuote) => {
                     blockquote(parser, buffer, toc_builder, shorter);
                 }
-                Event::Start(Tag::List(_)) => {
-                    list(parser, buffer, toc_builder, shorter);
+                Event::Start(Tag::List(x)) => {
+                    list(parser, buffer, toc_builder, shorter, x.is_some());
                 }
                 Event::Start(Tag::Emphasis) => {
                     emphasis(parser, buffer, toc_builder, shorter, id);
diff --git a/src/test/rustdoc/test-lists.rs b/src/test/rustdoc/test-lists.rs
new file mode 100644 (file)
index 0000000..71a826a
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name = "foo"]
+
+// ignore-tidy-linelength
+
+// @has foo/fn.f.html
+// @has - "<pre class='rust fn'>pub fn f()</pre><div class='docblock'><ol><li>list<ol><li>fooooo</li><li>x</li></ol></li><li>foo</li></ol>"
+/// 1. list
+///     1. fooooo
+///     2. x
+/// 2. foo
+pub fn f() {}
+
+// @has foo/fn.foo2.html
+// @has - "<pre class='rust fn'>pub fn foo2()</pre><div class='docblock'><ul><li>normal list<ul><li><p>sub list</p></li><li><p>new elem still same elem</p><p>and again same elem!</p></li></ul></li><li>new big elem</li></ul>"
+/// * normal list
+///     * sub list
+///     * new elem
+///       still same elem
+///
+///       and again same elem!
+/// * new big elem
+pub fn foo2() {}
\ No newline at end of file