Change Markdown(...)
to Markdown { ... }
This commit is contained in:
parent
4a6aa6e406
commit
6518a0a8b9
@ -39,14 +39,32 @@ impl ExternalHtml {
|
||||
let bc = format!(
|
||||
"{}{}",
|
||||
bc,
|
||||
Markdown(&m_bc, &[], id_map, codes, edition, playground, 0).into_string()
|
||||
Markdown {
|
||||
content: &m_bc,
|
||||
links: &[],
|
||||
ids: id_map,
|
||||
error_codes: codes,
|
||||
edition,
|
||||
playground,
|
||||
heading_level: 0
|
||||
}
|
||||
.into_string()
|
||||
);
|
||||
let ac = load_external_files(after_content, diag)?;
|
||||
let m_ac = load_external_files(md_after_content, diag)?;
|
||||
let ac = format!(
|
||||
"{}{}",
|
||||
ac,
|
||||
Markdown(&m_ac, &[], id_map, codes, edition, playground, 0).into_string()
|
||||
Markdown {
|
||||
content: &m_ac,
|
||||
links: &[],
|
||||
ids: id_map,
|
||||
error_codes: codes,
|
||||
edition,
|
||||
playground,
|
||||
heading_level: 0
|
||||
}
|
||||
.into_string()
|
||||
);
|
||||
Some(ExternalHtml { in_header: ih, before_content: bc, after_content: ac })
|
||||
}
|
||||
|
@ -12,7 +12,15 @@
|
||||
//!
|
||||
//! let s = "My *markdown* _text_";
|
||||
//! let mut id_map = IdMap::new();
|
||||
//! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None, 0);
|
||||
//! let md = Markdown {
|
||||
//! content: s,
|
||||
//! links: &[],
|
||||
//! ids: &mut id_map,
|
||||
//! error_codes: ErrorCodes::Yes,
|
||||
//! edition: Edition::Edition2015,
|
||||
//! playground: &None,
|
||||
//! heading_level: 0
|
||||
//! };
|
||||
//! let html = md.into_string();
|
||||
//! // ... something using html
|
||||
//! ```
|
||||
@ -69,19 +77,21 @@ pub(crate) fn summary_opts() -> Options {
|
||||
|
||||
/// When `to_string` is called, this struct will emit the HTML corresponding to
|
||||
/// the rendered version of the contained markdown string.
|
||||
pub struct Markdown<'a>(
|
||||
pub &'a str,
|
||||
pub struct Markdown<'a> {
|
||||
pub content: &'a str,
|
||||
/// A list of link replacements.
|
||||
pub &'a [RenderedLink],
|
||||
pub links: &'a [RenderedLink],
|
||||
/// The current list of used header IDs.
|
||||
pub &'a mut IdMap,
|
||||
pub ids: &'a mut IdMap,
|
||||
/// Whether to allow the use of explicit error codes in doctest lang strings.
|
||||
pub ErrorCodes,
|
||||
pub error_codes: ErrorCodes,
|
||||
/// Default edition to use when parsing doctests (to add a `fn main`).
|
||||
pub Edition,
|
||||
pub &'a Option<Playground>,
|
||||
pub u32,
|
||||
);
|
||||
pub edition: Edition,
|
||||
pub playground: &'a Option<Playground>,
|
||||
/// Offset at which we render headings.
|
||||
/// E.g. if `heading_level: 1`, then `# something` renders an `<h2>` instead of `<h1>`
|
||||
pub heading_level: u32,
|
||||
}
|
||||
/// A tuple struct like `Markdown` that renders the markdown with a table of contents.
|
||||
crate struct MarkdownWithToc<'a>(
|
||||
crate &'a str,
|
||||
@ -1010,7 +1020,15 @@ impl LangString {
|
||||
|
||||
impl Markdown<'_> {
|
||||
pub fn into_string(self) -> String {
|
||||
let Markdown(md, links, mut ids, codes, edition, playground, level) = self;
|
||||
let Markdown {
|
||||
content: md,
|
||||
links,
|
||||
mut ids,
|
||||
error_codes: codes,
|
||||
edition,
|
||||
playground,
|
||||
heading_level,
|
||||
} = self;
|
||||
|
||||
// This is actually common enough to special-case
|
||||
if md.is_empty() {
|
||||
@ -1031,7 +1049,7 @@ impl Markdown<'_> {
|
||||
|
||||
let mut s = String::with_capacity(md.len() * 3 / 2);
|
||||
|
||||
let p = HeadingLinks::new(p, None, &mut ids, level);
|
||||
let p = HeadingLinks::new(p, None, &mut ids, heading_level);
|
||||
let p = Footnotes::new(p);
|
||||
let p = LinkReplacer::new(p.map(|(ev, _)| ev), links);
|
||||
let p = TableWrapper::new(p);
|
||||
|
@ -147,8 +147,16 @@ fn test_lang_string_tokenizer() {
|
||||
fn test_header() {
|
||||
fn t(input: &str, expect: &str) {
|
||||
let mut map = IdMap::new();
|
||||
let output = Markdown(input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0)
|
||||
.into_string();
|
||||
let output = Markdown {
|
||||
content: input,
|
||||
links: &[],
|
||||
ids: &mut map,
|
||||
error_codes: ErrorCodes::Yes,
|
||||
edition: DEFAULT_EDITION,
|
||||
playground: &None,
|
||||
heading_level: 0,
|
||||
}
|
||||
.into_string();
|
||||
assert_eq!(output, expect, "original: {}", input);
|
||||
}
|
||||
|
||||
@ -181,8 +189,16 @@ fn test_header() {
|
||||
fn test_header_ids_multiple_blocks() {
|
||||
let mut map = IdMap::new();
|
||||
fn t(map: &mut IdMap, input: &str, expect: &str) {
|
||||
let output =
|
||||
Markdown(input, &[], map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0).into_string();
|
||||
let output = Markdown {
|
||||
content: input,
|
||||
links: &[],
|
||||
ids: map,
|
||||
error_codes: ErrorCodes::Yes,
|
||||
edition: DEFAULT_EDITION,
|
||||
playground: &None,
|
||||
heading_level: 0,
|
||||
}
|
||||
.into_string();
|
||||
assert_eq!(output, expect, "original: {}", input);
|
||||
}
|
||||
|
||||
|
@ -498,21 +498,21 @@ fn render_markdown(
|
||||
cx: &Context<'_>,
|
||||
md_text: &str,
|
||||
links: Vec<RenderedLink>,
|
||||
level: u32,
|
||||
heading_level: u32,
|
||||
) {
|
||||
let mut ids = cx.id_map.borrow_mut();
|
||||
write!(
|
||||
w,
|
||||
"<div class=\"docblock\">{}</div>",
|
||||
Markdown(
|
||||
md_text,
|
||||
&links,
|
||||
&mut ids,
|
||||
cx.shared.codes,
|
||||
cx.shared.edition(),
|
||||
&cx.shared.playground,
|
||||
level
|
||||
)
|
||||
Markdown {
|
||||
content: md_text,
|
||||
links: &links,
|
||||
ids: &mut ids,
|
||||
error_codes: cx.shared.codes,
|
||||
edition: cx.shared.edition(),
|
||||
playground: &cx.shared.playground,
|
||||
heading_level,
|
||||
}
|
||||
.into_string()
|
||||
)
|
||||
}
|
||||
@ -1596,15 +1596,15 @@ fn render_impl(
|
||||
write!(
|
||||
w,
|
||||
"<div class=\"docblock\">{}</div>",
|
||||
Markdown(
|
||||
&*dox,
|
||||
&i.impl_item.links(cx),
|
||||
&mut ids,
|
||||
cx.shared.codes,
|
||||
cx.shared.edition(),
|
||||
&cx.shared.playground,
|
||||
0
|
||||
)
|
||||
Markdown {
|
||||
content: &*dox,
|
||||
links: &i.impl_item.links(cx),
|
||||
ids: &mut ids,
|
||||
error_codes: cx.shared.codes,
|
||||
edition: cx.shared.edition(),
|
||||
playground: &cx.shared.playground,
|
||||
heading_level: 0
|
||||
}
|
||||
.into_string()
|
||||
);
|
||||
}
|
||||
|
@ -70,7 +70,16 @@ crate fn render<P: AsRef<Path>>(
|
||||
let text = if !options.markdown_no_toc {
|
||||
MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).into_string()
|
||||
} else {
|
||||
Markdown(text, &[], &mut ids, error_codes, edition, &playground, 0).into_string()
|
||||
Markdown {
|
||||
content: text,
|
||||
links: &[],
|
||||
ids: &mut ids,
|
||||
error_codes,
|
||||
edition,
|
||||
playground: &playground,
|
||||
heading_level: 0,
|
||||
}
|
||||
.into_string()
|
||||
};
|
||||
|
||||
let err = write!(
|
||||
|
@ -119,15 +119,15 @@ impl Formatter for HTMLFormatter {
|
||||
write!(
|
||||
output,
|
||||
"{}",
|
||||
Markdown(
|
||||
desc,
|
||||
&[],
|
||||
&mut id_map,
|
||||
ErrorCodes::Yes,
|
||||
DEFAULT_EDITION,
|
||||
&Some(playground),
|
||||
0
|
||||
)
|
||||
Markdown {
|
||||
content: desc,
|
||||
links: &[],
|
||||
ids: &mut id_map,
|
||||
error_codes: ErrorCodes::Yes,
|
||||
edition: DEFAULT_EDITION,
|
||||
playground: &Some(playground),
|
||||
heading_level: 0
|
||||
}
|
||||
.into_string()
|
||||
)?
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user