Skip to content

Commit 6518a0a

Browse files
author
Mukund Lakshman
committed
Change Markdown(...) to Markdown { ... }
1 parent 4a6aa6e commit 6518a0a

File tree

6 files changed

+108
-47
lines changed

6 files changed

+108
-47
lines changed

src/librustdoc/externalfiles.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,32 @@ impl ExternalHtml {
3939
let bc = format!(
4040
"{}{}",
4141
bc,
42-
Markdown(&m_bc, &[], id_map, codes, edition, playground, 0).into_string()
42+
Markdown {
43+
content: &m_bc,
44+
links: &[],
45+
ids: id_map,
46+
error_codes: codes,
47+
edition,
48+
playground,
49+
heading_level: 0
50+
}
51+
.into_string()
4352
);
4453
let ac = load_external_files(after_content, diag)?;
4554
let m_ac = load_external_files(md_after_content, diag)?;
4655
let ac = format!(
4756
"{}{}",
4857
ac,
49-
Markdown(&m_ac, &[], id_map, codes, edition, playground, 0).into_string()
58+
Markdown {
59+
content: &m_ac,
60+
links: &[],
61+
ids: id_map,
62+
error_codes: codes,
63+
edition,
64+
playground,
65+
heading_level: 0
66+
}
67+
.into_string()
5068
);
5169
Some(ExternalHtml { in_header: ih, before_content: bc, after_content: ac })
5270
}

src/librustdoc/html/markdown.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
//!
1313
//! let s = "My *markdown* _text_";
1414
//! let mut id_map = IdMap::new();
15-
//! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None, 0);
15+
//! let md = Markdown {
16+
//! content: s,
17+
//! links: &[],
18+
//! ids: &mut id_map,
19+
//! error_codes: ErrorCodes::Yes,
20+
//! edition: Edition::Edition2015,
21+
//! playground: &None,
22+
//! heading_level: 0
23+
//! };
1624
//! let html = md.into_string();
1725
//! // ... something using html
1826
//! ```
@@ -69,19 +77,21 @@ pub(crate) fn summary_opts() -> Options {
6977

7078
/// When `to_string` is called, this struct will emit the HTML corresponding to
7179
/// the rendered version of the contained markdown string.
72-
pub struct Markdown<'a>(
73-
pub &'a str,
80+
pub struct Markdown<'a> {
81+
pub content: &'a str,
7482
/// A list of link replacements.
75-
pub &'a [RenderedLink],
83+
pub links: &'a [RenderedLink],
7684
/// The current list of used header IDs.
77-
pub &'a mut IdMap,
85+
pub ids: &'a mut IdMap,
7886
/// Whether to allow the use of explicit error codes in doctest lang strings.
79-
pub ErrorCodes,
87+
pub error_codes: ErrorCodes,
8088
/// Default edition to use when parsing doctests (to add a `fn main`).
81-
pub Edition,
82-
pub &'a Option<Playground>,
83-
pub u32,
84-
);
89+
pub edition: Edition,
90+
pub playground: &'a Option<Playground>,
91+
/// Offset at which we render headings.
92+
/// E.g. if `heading_level: 1`, then `# something` renders an `<h2>` instead of `<h1>`
93+
pub heading_level: u32,
94+
}
8595
/// A tuple struct like `Markdown` that renders the markdown with a table of contents.
8696
crate struct MarkdownWithToc<'a>(
8797
crate &'a str,
@@ -1010,7 +1020,15 @@ impl LangString {
10101020

10111021
impl Markdown<'_> {
10121022
pub fn into_string(self) -> String {
1013-
let Markdown(md, links, mut ids, codes, edition, playground, level) = self;
1023+
let Markdown {
1024+
content: md,
1025+
links,
1026+
mut ids,
1027+
error_codes: codes,
1028+
edition,
1029+
playground,
1030+
heading_level,
1031+
} = self;
10141032

10151033
// This is actually common enough to special-case
10161034
if md.is_empty() {
@@ -1031,7 +1049,7 @@ impl Markdown<'_> {
10311049

10321050
let mut s = String::with_capacity(md.len() * 3 / 2);
10331051

1034-
let p = HeadingLinks::new(p, None, &mut ids, level);
1052+
let p = HeadingLinks::new(p, None, &mut ids, heading_level);
10351053
let p = Footnotes::new(p);
10361054
let p = LinkReplacer::new(p.map(|(ev, _)| ev), links);
10371055
let p = TableWrapper::new(p);

src/librustdoc/html/markdown/tests.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,16 @@ fn test_lang_string_tokenizer() {
147147
fn test_header() {
148148
fn t(input: &str, expect: &str) {
149149
let mut map = IdMap::new();
150-
let output = Markdown(input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0)
151-
.into_string();
150+
let output = Markdown {
151+
content: input,
152+
links: &[],
153+
ids: &mut map,
154+
error_codes: ErrorCodes::Yes,
155+
edition: DEFAULT_EDITION,
156+
playground: &None,
157+
heading_level: 0,
158+
}
159+
.into_string();
152160
assert_eq!(output, expect, "original: {}", input);
153161
}
154162

@@ -181,8 +189,16 @@ fn test_header() {
181189
fn test_header_ids_multiple_blocks() {
182190
let mut map = IdMap::new();
183191
fn t(map: &mut IdMap, input: &str, expect: &str) {
184-
let output =
185-
Markdown(input, &[], map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0).into_string();
192+
let output = Markdown {
193+
content: input,
194+
links: &[],
195+
ids: map,
196+
error_codes: ErrorCodes::Yes,
197+
edition: DEFAULT_EDITION,
198+
playground: &None,
199+
heading_level: 0,
200+
}
201+
.into_string();
186202
assert_eq!(output, expect, "original: {}", input);
187203
}
188204

src/librustdoc/html/render/mod.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,21 @@ fn render_markdown(
498498
cx: &Context<'_>,
499499
md_text: &str,
500500
links: Vec<RenderedLink>,
501-
level: u32,
501+
heading_level: u32,
502502
) {
503503
let mut ids = cx.id_map.borrow_mut();
504504
write!(
505505
w,
506506
"<div class=\"docblock\">{}</div>",
507-
Markdown(
508-
md_text,
509-
&links,
510-
&mut ids,
511-
cx.shared.codes,
512-
cx.shared.edition(),
513-
&cx.shared.playground,
514-
level
515-
)
507+
Markdown {
508+
content: md_text,
509+
links: &links,
510+
ids: &mut ids,
511+
error_codes: cx.shared.codes,
512+
edition: cx.shared.edition(),
513+
playground: &cx.shared.playground,
514+
heading_level,
515+
}
516516
.into_string()
517517
)
518518
}
@@ -1596,15 +1596,15 @@ fn render_impl(
15961596
write!(
15971597
w,
15981598
"<div class=\"docblock\">{}</div>",
1599-
Markdown(
1600-
&*dox,
1601-
&i.impl_item.links(cx),
1602-
&mut ids,
1603-
cx.shared.codes,
1604-
cx.shared.edition(),
1605-
&cx.shared.playground,
1606-
0
1607-
)
1599+
Markdown {
1600+
content: &*dox,
1601+
links: &i.impl_item.links(cx),
1602+
ids: &mut ids,
1603+
error_codes: cx.shared.codes,
1604+
edition: cx.shared.edition(),
1605+
playground: &cx.shared.playground,
1606+
heading_level: 0
1607+
}
16081608
.into_string()
16091609
);
16101610
}

src/librustdoc/markdown.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,16 @@ crate fn render<P: AsRef<Path>>(
7070
let text = if !options.markdown_no_toc {
7171
MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).into_string()
7272
} else {
73-
Markdown(text, &[], &mut ids, error_codes, edition, &playground, 0).into_string()
73+
Markdown {
74+
content: text,
75+
links: &[],
76+
ids: &mut ids,
77+
error_codes,
78+
edition,
79+
playground: &playground,
80+
heading_level: 0,
81+
}
82+
.into_string()
7483
};
7584

7685
let err = write!(

src/tools/error_index_generator/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,15 @@ impl Formatter for HTMLFormatter {
119119
write!(
120120
output,
121121
"{}",
122-
Markdown(
123-
desc,
124-
&[],
125-
&mut id_map,
126-
ErrorCodes::Yes,
127-
DEFAULT_EDITION,
128-
&Some(playground),
129-
0
130-
)
122+
Markdown {
123+
content: desc,
124+
links: &[],
125+
ids: &mut id_map,
126+
error_codes: ErrorCodes::Yes,
127+
edition: DEFAULT_EDITION,
128+
playground: &Some(playground),
129+
heading_level: 0
130+
}
131131
.into_string()
132132
)?
133133
}

0 commit comments

Comments
 (0)