diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-08-10 18:07:07 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-08-11 10:36:46 -0400 |
| commit | dbad77ffdd59e54b3f496cfbdb7909a6bbd03031 (patch) | |
| tree | 4c3e555d63d45547abb221ceca33ba345586bbd5 /src/librustdoc/html | |
| parent | ade8b02828de9653e6aca122f1a0f6d8c48ad29b (diff) | |
| download | rust-dbad77ffdd59e54b3f496cfbdb7909a6bbd03031.tar.gz rust-dbad77ffdd59e54b3f496cfbdb7909a6bbd03031.zip | |
Remove thread-local for playground config
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 203 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 29 |
2 files changed, 130 insertions, 102 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index ef52ce62875..73233a2289c 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -17,7 +17,7 @@ //! let s = "My *markdown* _text_"; //! let mut id_map = IdMap::new(); //! let html = format!("{}", Markdown(s, &[], RefCell::new(&mut id_map), -//! ErrorCodes::Yes, Edition::Edition2015)); +//! ErrorCodes::Yes, Edition::Edition2015, None)); //! // ... something using html //! ``` @@ -59,6 +59,7 @@ pub struct Markdown<'a>( pub ErrorCodes, /// Default edition to use when parsing doctests (to add a `fn main`). pub Edition, + pub &'a Option<Playground>, ); /// A tuple struct like `Markdown` that renders the markdown with a table of contents. pub struct MarkdownWithToc<'a>( @@ -66,9 +67,16 @@ pub struct MarkdownWithToc<'a>( pub RefCell<&'a mut IdMap>, pub ErrorCodes, pub Edition, + pub &'a Option<Playground>, ); /// 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 ErrorCodes, pub Edition); +pub struct MarkdownHtml<'a>( + pub &'a str, + pub RefCell<&'a mut IdMap>, + pub ErrorCodes, + pub Edition, + pub &'a Option<Playground>, +); /// A tuple struct like `Markdown` that renders only the first paragraph. pub struct MarkdownSummaryLine<'a>(pub &'a str, pub &'a [(String, String)]); @@ -155,30 +163,39 @@ fn slugify(c: char) -> Option<char> { } } -// Information about the playground if a URL has been specified, containing an -// optional crate name and the URL. -thread_local!(pub static PLAYGROUND: RefCell<Option<(Option<String>, String)>> = { - RefCell::new(None) -}); +#[derive(Clone, Debug)] +pub struct Playground { + pub crate_name: Option<String>, + pub url: String, +} /// Adds syntax highlighting and playground Run buttons to Rust code blocks. -struct CodeBlocks<'a, I: Iterator<Item = Event<'a>>> { +struct CodeBlocks<'p, 'a, I: Iterator<Item = Event<'a>>> { inner: I, check_error_codes: ErrorCodes, edition: Edition, + // Information about the playground if a URL has been specified, containing an + // optional crate name and the URL. + playground: &'p Option<Playground>, } -impl<'a, I: Iterator<Item = Event<'a>>> CodeBlocks<'a, I> { - fn new(iter: I, error_codes: ErrorCodes, edition: Edition) -> Self { +impl<'p, 'a, I: Iterator<Item = Event<'a>>> CodeBlocks<'p, 'a, I> { + fn new( + iter: I, + error_codes: ErrorCodes, + edition: Edition, + playground: &'p Option<Playground>, + ) -> Self { CodeBlocks { inner: iter, check_error_codes: error_codes, edition, + playground, } } } -impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> { +impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> { type Item = Event<'a>; fn next(&mut self) -> Option<Self::Item> { @@ -213,86 +230,86 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'a, I> { } let lines = origtext.lines().filter_map(|l| map_line(l).for_html()); let text = lines.collect::<Vec<Cow<'_, str>>>().join("\n"); - PLAYGROUND.with(|play| { - // insert newline to clearly separate it from the - // previous block so we can shorten the html output - let mut s = String::from("\n"); - let playground_button = play.borrow().as_ref().and_then(|&(ref krate, ref url)| { - if url.is_empty() { - return None; - } - let test = origtext.lines() - .map(|l| map_line(l).for_code()) - .collect::<Vec<Cow<'_, str>>>().join("\n"); - let krate = krate.as_ref().map(|s| &**s); - let (test, _) = test::make_test(&test, krate, false, - &Default::default(), edition); - let channel = if test.contains("#