Uh oh!
There was an error while loading. Please reload this page.
Refactor Markdown length-limited summary implementation - #88173
Conversation
c42090c to
37a800cCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
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.
37a800c to
39ef8eaCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
GuillaumeGomez
commented
Aug 20, 2021
Overall, looks pretty nice. Please add tests to ensure it works as expected. Also, not sure to see the added value of Last point: we used to create the string with a capacity whereas you don't anymore. |
camelid
commented
Aug 20, 2021
Will do. 👍
The value is that it allows automatically stopping the iteration, and it communicates the intent better than Or are you referring to the feature gate? Note that
See #88173 (comment). |
GuillaumeGomez
commented
Aug 20, 2021
No, I meant |
The length limit turns out to be a surprisingly good heuristic for initial allocation size. See here for more details [1]. [1]: rust-lang#88173 (comment)
Uh oh!
There was an error while loading. Please reload this page.
This comment has been minimized.
This comment has been minimized.
988c49b to
c4a9b75Compare
This comment has been minimized.
This comment has been minimized.
c4a9b75 to
4a75607Compare
This comment has been minimized.
This comment has been minimized.
b5a082d to
84fd81bCompare
This comment has been minimized.
This comment has been minimized.
This can happen when a tag is opened after the length limit is reached; the tag will not end up being added to `unclosed_tags` because the queue will never be flushed. So, now, if the `unclosed_tags` stack is empty, `close_tag()` does nothing. This change fixes a panic in the `limit_0` unit test.
camelid
commented
Aug 26, 2021
I'll push up a fix for the test failures tomorrow. |
84fd81b to
4478eccComparecamelid
commented
Aug 28, 2021
Ok, CI passed, this should be ready for a new review! |
GuillaumeGomez
commented
Aug 29, 2021
Thanks! @bors: r+ |
bors
commented
Aug 29, 2021
📌 Commit 4478ecc has been approved by |
…laumeGomez Rollup of 13 pull requests Successful merges: - rust-lang#80543 (Notify when an `I-prioritize` issue is closed or reopened) - rust-lang#83251 (Suggestion for call on immutable binding of mutable type) - rust-lang#85534 (add rustc-demangle assertion on mangled symbol) - rust-lang#88173 (Refactor Markdown length-limited summary implementation) - rust-lang#88349 (Add const and static TAIT tests) - rust-lang#88357 (add unsized coercion test) - rust-lang#88381 (Handle stack_t.ss_sp type change for DragonFlyBSD) - rust-lang#88387 (Remove vestigial rustfix tests.) - rust-lang#88396 (Bump vulnerable crates) - rust-lang#88407 (Fix formatting in release notes from 52a9883) - rust-lang#88411 (Remove `Session.if_let_suggestions`) - rust-lang#88417 (RELEASES.md: fix broken link) - rust-lang#88419 (Fix code blocks color in Ayu theme) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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
HtmlWithLimitthat manages the length-limiting logic and a functionmarkdown_summary_with_limit()that renders Markdown to HTML using thestruct.
r? @GuillaumeGomez