Skip to content

Commit 8c29876

Browse files
authored
Rollup merge of rust-lang#41049 - GuillaumeGomez:rustdoc-ordered-list, r=frewsxcv
Handle ordered lists as well Part of rust-lang#40912. r? @rust-lang/docs
2 parents 5697b90 + b02cb19 commit 8c29876

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

src/librustdoc/html/markdown.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,15 @@ pub fn render(w: &mut fmt::Formatter,
427427
looper(parser, &mut content, Some(x), toc_builder, shorter, &mut None);
428428
}
429429
}
430+
if shorter.is_compact() {
431+
break
432+
}
430433
}
431434
buffer.push_str(&format!("<li>{}</li>", content));
432435
}
433436

434437
fn list(parser: &mut ParserWrapper, buffer: &mut String, toc_builder: &mut Option<TocBuilder>,
435-
shorter: MarkdownOutputStyle) {
438+
shorter: MarkdownOutputStyle, is_sorted_list: bool) {
436439
debug!("List");
437440
let mut content = String::new();
438441
while let Some(event) = parser.next() {
@@ -445,8 +448,13 @@ pub fn render(w: &mut fmt::Formatter,
445448
looper(parser, &mut content, Some(x), toc_builder, shorter, &mut None);
446449
}
447450
}
451+
if shorter.is_compact() {
452+
break
453+
}
448454
}
449-
buffer.push_str(&format!("<ul>{}</ul>", content));
455+
buffer.push_str(&format!("<{0}>{1}</{0}>",
456+
if is_sorted_list { "ol" } else { "ul" },
457+
content));
450458
}
451459

452460
fn emphasis(parser: &mut ParserWrapper, buffer: &mut String,
@@ -516,8 +524,8 @@ pub fn render(w: &mut fmt::Formatter,
516524
Event::Start(Tag::BlockQuote) => {
517525
blockquote(parser, buffer, toc_builder, shorter);
518526
}
519-
Event::Start(Tag::List(_)) => {
520-
list(parser, buffer, toc_builder, shorter);
527+
Event::Start(Tag::List(x)) => {
528+
list(parser, buffer, toc_builder, shorter, x.is_some());
521529
}
522530
Event::Start(Tag::Emphasis) => {
523531
emphasis(parser, buffer, toc_builder, shorter, id);

src/test/rustdoc/test-lists.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
// ignore-tidy-linelength
14+
15+
// @has foo/fn.f.html
16+
// @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>"
17+
/// 1. list
18+
/// 1. fooooo
19+
/// 2. x
20+
/// 2. foo
21+
pub fn f() {}
22+
23+
// @has foo/fn.foo2.html
24+
// @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>"
25+
/// * normal list
26+
/// * sub list
27+
/// * new elem
28+
/// still same elem
29+
///
30+
/// and again same elem!
31+
/// * new big elem
32+
pub fn foo2() {}

0 commit comments

Comments
 (0)