about summary refs log tree commit diff
path: root/src/librustdoc/html/markdown.rs
AgeCommit message (Collapse)AuthorLines
2021-10-04heading_level: u32 -> heading_offset: HeadingOffsetMukund Lakshman-13/+28
2021-10-04No need to default offset since we always override it.Mukund Lakshman-2/+2
2021-10-04Change `Markdown(...)` to `Markdown { ... }`Mukund Lakshman-12/+30
2021-10-04librustdoc: Use correct heading levels.Mukund Lakshman-8/+13
- Avoid multiple <h1>s on a page. - The <h#> tags should follow a semantic hierarchy. - Cap at h6 (no h7)
2021-09-26Preserve the whole LangSyntax when parsing doctestsJoshua Nelson-15/+8
Previously, only the raw string and the `is_ignore` field were preserved, which made it hard to recover anything else.
2021-09-10Rollup merge of #88742 - GuillaumeGomez:fix-table-in-docblocks, r=nbdd0121Manish Goregaokar-2/+41
Fix table in docblocks "Overwrite" of #88702. Instead of adding a z-index to the sidebar (which only hides the issue, doesn't fix it), I wrap `<table>` elements inside a `<div>` and limit all chidren of `.docblock` elements' width to prevent having the scrollbar on the whole doc block. ![Screenshot from 2021-09-08 15-11-24](https://user-images.githubusercontent.com/3050060/132515740-71796515-e74f-429f-ba98-2596bdbf781c.png) Thanks `@nbdd0121` for `overflow-x: auto;`. ;) r? `@notriddle`
2021-09-10Rollup merge of #88632 - camelid:md-opts, r=CraftSpiderManish Goregaokar-9/+14
Fix issues with Markdown summary options - Use `summary_opts()` for Markdown summaries - Enable all main body Markdown options for summaries
2021-09-08Wrap <table> elements into <div> to prevent breaking layout and widthGuillaume Gomez-2/+41
2021-09-08Auto merge of #87489 - bdalrhm:rustdoc-line-num, r=CraftSpiderbors-0/+6
`rustdoc`: compute correct line number for indented rust code blocks. This PR fixes a bug in `rustdoc` where it computes the wrong line number for indented rust code blocks (and subsequent blocks) it finds in markdown strings. To fix this issue, we decrement the line number if we find characters between the code block and the preceding line ending. I noticed this issue as I was trying to use `rustdoc` to extract examples from The Rust Reference and run them through the [Rust Model Checker](https://github.com/model-checking/rmc).
2021-09-03Enable all main body Markdown options for summariesNoah Lev-2/+6
This fixes odd renderings when these features are used in the first paragraph of documentation for an item. This is an extension of #87270.
2021-09-03Use `summary_opts()` for Markdown summariesNoah Lev-8/+9
It was accidentally changed to use `opts()` in #86451. I also renamed `opts()` to `main_body_opts()` to make this kind of accidental change less likely.
2021-08-29Rollup merge of #88173 - camelid:refactor-markdown-length-limit, ↵Guillaume Gomez-43/+28
r=GuillaumeGomez Refactor Markdown length-limited summary implementation This PR is a new approach to #79749. This PR refactors the implementation of `markdown_summary_with_limit()`, separating the logic of determining when the limit has been reached from the actual rendering process. The main advantage of the new approach is that it guarantees that all HTML tags are closed, whereas the previous implementation could generate tags that were never closed. It also ensures that no empty tags are generated (e.g., `<em></em>`). The new implementation consists of a general-purpose struct `HtmlWithLimit` that manages the length-limiting logic and a function `markdown_summary_with_limit()` that renders Markdown to HTML using the struct. r? `@GuillaumeGomez`
2021-08-21Use the length limit as the initial capacityNoah Lev-1/+0
The length limit turns out to be a surprisingly good heuristic for initial allocation size. See here for more details [1]. [1]: https://github.com/rust-lang/rust/pull/88173#discussion_r692531631
2021-08-19Refactor Markdown length-limited summary implementationNoah Lev-43/+29
This commit refactors the implementation of `markdown_summary_with_limit()`, separating the logic of determining when the limit has been reached from the actual rendering process. The main advantage of the new approach is that it guarantees that all HTML tags are closed, whereas the previous implementation could generate tags that were never closed. It also ensures that no empty tags are generated (e.g., `<em></em>`). The new implementation consists of a general-purpose struct `HtmlWithLimit` that manages the length-limiting logic and a function `markdown_summary_with_limit()` that renders Markdown to HTML using the struct.
2021-08-19[rustdoc] Wrap code blocks in <code> tagJakub Beránek-1/+1
2021-08-05Move extra arguments for highlight URL generation into a new ContextInfo ↵Guillaume Gomez-2/+0
struct for better readability
2021-08-05Add links on source types to go to definitionGuillaume Gomez-0/+3
2021-07-26Pass correct line number for indented code blocks.Abdalrhman Mohamed-0/+6
2021-07-26Rollup merge of #87444 - camelid:flatten-nested-format, r=jyn514Guillaume Gomez-2/+2
Flatten nested `format!` calls
2021-07-24Flatten nested `format!` callsNoah Lev-2/+2
2021-07-24Escape item search summariesNoah Lev-3/+2
I noticed that `Pin::new()`'s search summary looked off, and I realized that the reason is that it has inline code containing `Pin<P>`, which is not escaped and thus renders as a paragraph tag!
2021-07-21Don't render <table> in items' summaryGuillaume Gomez-4/+11
2021-07-15Fix misuse of rev attribute on <a> tagGuillaume Gomez-2/+1
2021-07-14Fix display for non-rust code blocksGuillaume Gomez-18/+33
2021-07-04Clean up rustdoc IDsGuillaume Gomez-4/+11
2021-06-18Resolve intra-doc links in summary descMichael Howell-4/+21
Before: ![rustdoc-intra-doc-link-summary-before](https://user-images.githubusercontent.com/1593513/122623069-9d995e80-d04f-11eb-8d46-ec2ec126bb5e.png) After: ![rustdoc-intra-doc-link-summary](https://user-images.githubusercontent.com/1593513/122623076-a4c06c80-d04f-11eb-967a-f5916871c34b.png)
2021-05-11Move global click handlers to per-element ones.Jacob Hoffman-Andrews-0/+1
In rustdoc's main.js, we had an onclick handler for the whole document that would dispatch to handlers for various elements. This change attaches the handlers to the elements that trigger them, instead. This simplfies the code and avoids reimplementing the browser's bubbling functionality. As part of this change, change from a class to an id for help button. Move the handlers and associated code for highlighting source lines into source-script.js (and factor out a shared regex).
2021-05-10Fix line number not being clickable on source pagesGuillaume Gomez-0/+1
2021-04-24Revert "rustdoc: Hide `#text` in doc-tests"David Hewitt-13/+6
This reverts commit af6c3201fc3d5ec2559836454ea4f43eec583fa2.
2021-04-22rustdoc: Hide `#text` in doc-testsJoshua Nelson-6/+13
Since `#![attr]` and `#[attr]` are the only valid syntax that start with `#`, we can just special case those two tokens.
2021-04-03Remove unneeded INITIAL_IDS constGuillaume Gomez-6/+9
2021-04-02Rollup merge of #83721 - GuillaumeGomez:copy-use, r=Nemo157Yuki Okushi-0/+1
Add a button to copy the "use statement" Fixes https://github.com/rust-lang/rust/issues/50239 When clicking on the button, it'll add the elements prepended by "use " and will end with a ";". So in the images below, I now have in my clipboard `use std::fs::OpenOptions;`. A screenshot of the newly added button: ![Screenshot from 2021-03-31 22-12-12](https://user-images.githubusercontent.com/3050060/113205430-90e64500-926e-11eb-8538-529829f611ec.png) A screenshot after it was clicked: ![Screenshot from 2021-03-31 22-15-31](https://user-images.githubusercontent.com/3050060/113205532-ad827d00-926e-11eb-893d-35f2f8f92696.png) r? `@Nemo157`
2021-03-31Add a button to copy the "use statement"Guillaume Gomez-0/+1
2021-03-28Point to disambiguator instead of whole linkCamelid-0/+1
And, now that we do that, we can remove the explanatory note since the error span should make it clear what the disambiguator is.
2021-03-21rustdoc: Replace pair of `Option`s with an enumCamelid-8/+11
They are never both `None` or both `Some`, so it makes more sense to use an enum so that we "make impossible states impossible".
2021-03-09Treat header as first paragraph for shortened markdown descriptionsMichael Howell-0/+1
"The Rust Standard LibraryThe Rust Standard Library is the …" is an awful description.
2021-03-05Don't unnecessarily clone some fields in `Context`Camelid-4/+0
There was no need to clone `id_map` because it was reset before each item was rendered. `deref_id_map` was not reset, but it was keyed by `DefId` and thus was unlikely to have collisions (at least for now). Now we just clone the fields that need to be cloned, and instead create fresh versions of the others.
2021-03-01Move lint machinery into a separate fileJoshua Nelson-1/+1
2021-03-01Rename rustdoc lints to be a tool lint instead of built-in.Joshua Nelson-2/+1
- Rename `broken_intra_doc_links` to `rustdoc::broken_intra_doc_links` - Ensure that the old lint names still work and give deprecation errors - Register lints even when running doctests Otherwise, all `rustdoc::` lints would be ignored. - Register all existing lints as removed This unfortunately doesn't work with `register_renamed` because tool lints have not yet been registered when rustc is running. For similar reasons, `check_backwards_compat` doesn't work either. Call `register_removed` directly instead. - Fix fallout + Rustdoc lints for compiler/ + Rustdoc lints for library/ Note that this does *not* suggest `rustdoc::broken_intra_doc_links` for `rustdoc::intra_doc_link_resolution_failure`, since there was no time when the latter was valid.
2021-02-26Auto merge of #78429 - casey:doctest-attribute-splitting, r=jyn514bors-3/+29
[librustdoc] Only split lang string on `,`, ` `, and `\t` Split markdown lang strings into tokens on `,`. The previous behavior was to split lang strings into tokens on any character that wasn't a `_`, `_`, or alphanumeric. This is a potentially breaking change, so please scrutinize! See discussion in #78344. I noticed some test cases that made me wonder if there might have been some reason for the original behavior: ``` t("{.no_run .example}", false, true, Ignore::None, true, false, false, false, v(), None); t("{.sh .should_panic}", true, false, Ignore::None, false, false, false, false, v(), None); t("{.example .rust}", false, false, Ignore::None, true, false, false, false, v(), None); t("{.test_harness .rust}", false, false, Ignore::None, true, true, false, false, v(), None); ``` It seemed pretty peculiar to specifically test lang strings in braces, with all the tokens prefixed by `.`. I did some digging, and it looks like the test cases were added way back in [this commit from 2014](https://github.com/rust-lang/rust/commit/3fef7a74ca9a) by `@skade.` It looks like they were added just to make sure that the splitting was permissive, and aren't testing that those strings in particular are accepted. Closes https://github.com/rust-lang/rust/issues/78344.
2021-02-23Rollup merge of #79423 - camelid:smart-punct, r=jyn514Dylan DPC-1/+2
Enable smart punctuation Closes #76690.
2021-02-20Cut off plain text descriptions after headersMichael Howell-0/+1
Before: The Rust Standard LibraryThe Rust Standard Library is the foundation of portable Rust software, a set of minimal and battle-tested shared abstractions for the broader Rust ecosystem. It offers core types, like `Vec<T>` and `Option<T>`, library-defined operations on language primitives, standard macros, I/O and multithreading, among many other things. After: The Rust Standard Library
2021-02-12[librustdoc] Reform lang string token splittingCasey Rodarmor-3/+29
Only split doctest lang strings on `,`, ` `, and `\t`. Additionally, to preserve backwards compatibility with pandoc-style langstrings, strip a surrounding `{}`, and remove leading `.`s from each token. Prior to this change, doctest lang strings were split on all non-alphanumeric characters except `-` or `_`, which limited future extensions to doctest lang string tokens, for example using `=` for key-value tokens. This is a breaking change, although it is not expected to be disruptive, because lang strings using separators other than `,` and ` ` are not very common
2021-02-07Enable smart punctuationCamelid-1/+2
2021-02-06Enable 'task list' markdown extensionJoshua Nelson-1/+4
- Add documentation about task lists
2021-01-30rustdoc tweakingbors-12/+17
* Reuse memory * simplify `next_def_id`, avoid multiple hashing and unnecessary lookups * remove `all_fake_def_ids`, use the global map instead (probably not a good step toward parallelization, though...) * convert `add_deref_target` to iterative implementation * use `ArrayVec` where we know the max number of elements * minor touchups here and there * avoid building temporary vectors that get appended to other vectors At most places I may or may not be doing the compiler's job is this PR.
2021-01-21Fix rustc::internal lints on rustdocJoshua Nelson-8/+8
2021-01-18Remove inline script tagsGuillaume Gomez-0/+2
2021-01-08Use target in `Deref` method section IDsJ. Ryan Stinnett-1/+0
There can now be multiple `Deref` method sections, so this adds the target type to the section ID to ensure they are unique.
2021-01-03Auto merge of #77859 - bugadani:no-duplicate-ref-link-error, r=jyn514bors-7/+17
Rustdoc: only report broken ref-style links once This PR assigns the markdown `LinkType` to each parsed link and passes this information into the link collector. If a link can't be resolved in `resolve_with_disambiguator`, the failure is cached for the link types where we only want to report the error once (namely `Shortcut` and `Reference`). Fixes #77681