Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle ordered lists as well #41049

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,15 @@ pub fn render(w: &mut fmt::Formatter,
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_ordered_list: bool) {
debug!("List");
let mut content = String::new();
while let Some(event) = parser.next() {
Expand All @@ -445,8 +448,13 @@ pub fn render(w: &mut fmt::Formatter,
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_ordered_list { "ol" } else { "ul" },
content));
}

fn emphasis(parser: &mut ParserWrapper, buffer: &mut String,
Expand Down Expand Up @@ -516,8 +524,8 @@ pub fn render(w: &mut fmt::Formatter,
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);
Expand Down
32 changes: 32 additions & 0 deletions src/test/rustdoc/test-lists.rs
Original file line number Diff line number Diff line change
@@ -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() {}