Drop RefCell from IdMap in markdown rendering
This commit is contained in:
parent
c250b5fd03
commit
1aa0964b54
6 changed files with 22 additions and 31 deletions
|
@ -6,8 +6,6 @@ use crate::syntax::feature_gate::UnstableFeatures;
|
|||
use crate::syntax::edition::Edition;
|
||||
use crate::html::markdown::{IdMap, ErrorCodes, Markdown, Playground};
|
||||
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ExternalHtml {
|
||||
/// Content that will be included inline in the <head> section of a
|
||||
|
@ -35,7 +33,7 @@ impl ExternalHtml {
|
|||
.and_then(|(ih, bc)|
|
||||
load_external_files(md_before_content, diag)
|
||||
.map(|m_bc| (ih,
|
||||
format!("{}{}", bc, Markdown(&m_bc, &[], RefCell::new(id_map),
|
||||
format!("{}{}", bc, Markdown(&m_bc, &[], id_map,
|
||||
codes, edition, playground).to_string())))
|
||||
)
|
||||
.and_then(|(ih, bc)|
|
||||
|
@ -45,7 +43,7 @@ impl ExternalHtml {
|
|||
.and_then(|(ih, bc, ac)|
|
||||
load_external_files(md_after_content, diag)
|
||||
.map(|m_ac| (ih, bc,
|
||||
format!("{}{}", ac, Markdown(&m_ac, &[], RefCell::new(id_map),
|
||||
format!("{}{}", ac, Markdown(&m_ac, &[], id_map,
|
||||
codes, edition, playground).to_string())))
|
||||
)
|
||||
.map(|(ih, bc, ac)|
|
||||
|
|
|
@ -9,12 +9,10 @@
|
|||
//!
|
||||
//! use syntax::edition::Edition;
|
||||
//! use rustdoc::html::markdown::{IdMap, Markdown, ErrorCodes};
|
||||
//! use std::cell::RefCell;
|
||||
//!
|
||||
//! let s = "My *markdown* _text_";
|
||||
//! let mut id_map = IdMap::new();
|
||||
//! let md = Markdown(s, &[], RefCell::new(&mut id_map),
|
||||
//! ErrorCodes::Yes, Edition::Edition2015, None);
|
||||
//! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None);
|
||||
//! let html = md.to_string();
|
||||
//! // ... something using html
|
||||
//! ```
|
||||
|
@ -51,7 +49,7 @@ pub struct Markdown<'a>(
|
|||
/// A list of link replacements.
|
||||
pub &'a [(String, String)],
|
||||
/// The current list of used header IDs.
|
||||
pub RefCell<&'a mut IdMap>,
|
||||
pub &'a mut IdMap,
|
||||
/// Whether to allow the use of explicit error codes in doctest lang strings.
|
||||
pub ErrorCodes,
|
||||
/// Default edition to use when parsing doctests (to add a `fn main`).
|
||||
|
@ -61,7 +59,7 @@ pub struct Markdown<'a>(
|
|||
/// A tuple struct like `Markdown` that renders the markdown with a table of contents.
|
||||
pub struct MarkdownWithToc<'a>(
|
||||
pub &'a str,
|
||||
pub RefCell<&'a mut IdMap>,
|
||||
pub &'a mut IdMap,
|
||||
pub ErrorCodes,
|
||||
pub Edition,
|
||||
pub &'a Option<Playground>,
|
||||
|
@ -69,7 +67,7 @@ pub struct MarkdownWithToc<'a>(
|
|||
/// A tuple struct like `Markdown` that renders the markdown escaping HTML tags.
|
||||
pub struct MarkdownHtml<'a>(
|
||||
pub &'a str,
|
||||
pub RefCell<&'a mut IdMap>,
|
||||
pub &'a mut IdMap,
|
||||
pub ErrorCodes,
|
||||
pub Edition,
|
||||
pub &'a Option<Playground>,
|
||||
|
@ -690,8 +688,7 @@ impl LangString {
|
|||
|
||||
impl Markdown<'_> {
|
||||
pub fn to_string(self) -> String {
|
||||
let Markdown(md, links, ids, codes, edition, playground) = self;
|
||||
let mut ids = ids.borrow_mut();
|
||||
let Markdown(md, links, mut ids, codes, edition, playground) = self;
|
||||
|
||||
// This is actually common enough to special-case
|
||||
if md.is_empty() { return String::new(); }
|
||||
|
@ -719,8 +716,7 @@ impl Markdown<'_> {
|
|||
|
||||
impl MarkdownWithToc<'_> {
|
||||
pub fn to_string(self) -> String {
|
||||
let MarkdownWithToc(md, ref ids, codes, edition, playground) = self;
|
||||
let mut ids = ids.borrow_mut();
|
||||
let MarkdownWithToc(md, mut ids, codes, edition, playground) = self;
|
||||
|
||||
let p = Parser::new_ext(md, opts());
|
||||
|
||||
|
@ -741,8 +737,7 @@ impl MarkdownWithToc<'_> {
|
|||
|
||||
impl MarkdownHtml<'_> {
|
||||
pub fn to_string(self) -> String {
|
||||
let MarkdownHtml(md, ref ids, codes, edition, playground) = self;
|
||||
let mut ids = ids.borrow_mut();
|
||||
let MarkdownHtml(md, mut ids, codes, edition, playground) = self;
|
||||
|
||||
// This is actually common enough to special-case
|
||||
if md.is_empty() { return String::new(); }
|
||||
|
|
|
@ -73,8 +73,8 @@ fn test_lang_string_parse() {
|
|||
fn test_header() {
|
||||
fn t(input: &str, expect: &str) {
|
||||
let mut map = IdMap::new();
|
||||
let output = Markdown(input, &[], RefCell::new(&mut map),
|
||||
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
|
||||
let output = Markdown(
|
||||
input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
|
||||
assert_eq!(output, expect, "original: {}", input);
|
||||
}
|
||||
|
||||
|
@ -96,8 +96,8 @@ 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, &[], RefCell::new(map),
|
||||
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
|
||||
let output = Markdown(input, &[], map,
|
||||
ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
|
||||
assert_eq!(output, expect, "original: {}", input);
|
||||
}
|
||||
|
||||
|
@ -134,8 +134,8 @@ fn test_plain_summary_line() {
|
|||
fn test_markdown_html_escape() {
|
||||
fn t(input: &str, expect: &str) {
|
||||
let mut idmap = IdMap::new();
|
||||
let output = MarkdownHtml(input, RefCell::new(&mut idmap),
|
||||
ErrorCodes::Yes, DEFAULT_EDITION).to_string();
|
||||
let output = MarkdownHtml(input, &mut idmap,
|
||||
ErrorCodes::Yes, DEFAULT_EDITION, &None).to_string();
|
||||
assert_eq!(output, expect, "original: {}", input);
|
||||
}
|
||||
|
||||
|
|
|
@ -2595,7 +2595,7 @@ fn render_markdown(w: &mut fmt::Formatter<'_>,
|
|||
write!(w, "<div class='docblock{}'>{}{}</div>",
|
||||
if is_hidden { " hidden" } else { "" },
|
||||
prefix,
|
||||
Markdown(md_text, &links, RefCell::new(&mut ids),
|
||||
Markdown(md_text, &links, &mut ids,
|
||||
cx.codes, cx.edition, &cx.playground).to_string())
|
||||
}
|
||||
|
||||
|
@ -2961,8 +2961,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
|
|||
|
||||
if let Some(note) = note {
|
||||
let mut ids = cx.id_map.borrow_mut();
|
||||
let html = MarkdownHtml(
|
||||
¬e, RefCell::new(&mut ids), error_codes, cx.edition, &cx.playground);
|
||||
let html = MarkdownHtml(¬e, &mut ids, error_codes, cx.edition, &cx.playground);
|
||||
message.push_str(&format!(": {}", html.to_string()));
|
||||
}
|
||||
stability.push(format!("<div class='stab deprecated'>{}</div>", message));
|
||||
|
@ -3013,7 +3012,7 @@ fn short_stability(item: &clean::Item, cx: &Context) -> Vec<String> {
|
|||
message,
|
||||
MarkdownHtml(
|
||||
&unstable_reason,
|
||||
RefCell::new(&mut ids),
|
||||
&mut ids,
|
||||
error_codes,
|
||||
cx.edition,
|
||||
&cx.playground,
|
||||
|
@ -4247,7 +4246,7 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt
|
|||
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
|
||||
let mut ids = cx.id_map.borrow_mut();
|
||||
write!(w, "<div class='docblock'>{}</div>",
|
||||
Markdown(&*dox, &i.impl_item.links(), RefCell::new(&mut ids),
|
||||
Markdown(&*dox, &i.impl_item.links(), &mut ids,
|
||||
cx.codes, cx.edition, &cx.playground).to_string())?;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use std::path::PathBuf;
|
||||
use std::cell::RefCell;
|
||||
|
||||
use errors;
|
||||
use testing;
|
||||
|
@ -83,9 +82,9 @@ pub fn render(
|
|||
let mut ids = IdMap::new();
|
||||
let error_codes = ErrorCodes::from(UnstableFeatures::from_environment().is_nightly_build());
|
||||
let text = if !options.markdown_no_toc {
|
||||
MarkdownWithToc(text, RefCell::new(&mut ids), error_codes, edition, &playground).to_string()
|
||||
MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).to_string()
|
||||
} else {
|
||||
Markdown(text, &[], RefCell::new(&mut ids), error_codes, edition, &playground).to_string()
|
||||
Markdown(text, &[], &mut ids, error_codes, edition, &playground).to_string()
|
||||
};
|
||||
|
||||
let err = write!(
|
||||
|
|
|
@ -100,7 +100,7 @@ impl Formatter for HTMLFormatter {
|
|||
url: String::from("https://play.rust-lang.org/"),
|
||||
};
|
||||
write!(output, "{}",
|
||||
Markdown(desc, &[], RefCell::new(&mut id_map),
|
||||
Markdown(desc, &[], &mut id_map,
|
||||
ErrorCodes::Yes, DEFAULT_EDITION, &Some(playground)).to_string())?
|
||||
},
|
||||
None => write!(output, "<p>No description.</p>\n")?,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue