-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Markdown length-limited summary implementation #88173
Refactor Markdown length-limited summary implementation #88173
Conversation
c42090c
to
37a800c
Compare
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
39ef8ea
Compare
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. |
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). |
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)
This comment has been minimized.
This comment has been minimized.
988c49b
to
c4a9b75
Compare
This comment has been minimized.
This comment has been minimized.
c4a9b75
to
4a75607
Compare
This comment has been minimized.
This comment has been minimized.
b5a082d
to
84fd81b
Compare
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.
I'll push up a fix for the test failures tomorrow. |
84fd81b
to
4478ecc
Compare
Ok, CI passed, this should be ready for a new review! |
Thanks! @bors: r+ |
📌 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
HtmlWithLimit
that manages the length-limiting logic and a functionmarkdown_summary_with_limit()
that renders Markdown to HTML using thestruct.
r? @GuillaumeGomez