Skip to content
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

Merged
merged 7 commits into from
Aug 29, 2021

Commits on Aug 19, 2021

  1. Refactor Markdown length-limited summary implementation

    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.
    camelid committed Aug 19, 2021
    Configuration menu
    Copy the full SHA
    39ef8ea View commit details
    Browse the repository at this point in the history

Commits on Aug 21, 2021

  1. Clarify wording in docs

    camelid authored Aug 21, 2021
    Configuration menu
    Copy the full SHA
    09f0876 View commit details
    Browse the repository at this point in the history
  2. Use the length limit as the initial capacity

    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)
    camelid committed Aug 21, 2021
    Configuration menu
    Copy the full SHA
    74147b8 View commit details
    Browse the repository at this point in the history

Commits on Aug 22, 2021

  1. Use write!

    camelid committed Aug 22, 2021
    Configuration menu
    Copy the full SHA
    d18936a View commit details
    Browse the repository at this point in the history

Commits on Aug 26, 2021

  1. Add tests for HtmlWithLimit

    camelid committed Aug 26, 2021
    Configuration menu
    Copy the full SHA
    f8ca576 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    d932e62 View commit details
    Browse the repository at this point in the history
  3. Don't panic if close_tag() is called without tags to close

    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 committed Aug 26, 2021
    Configuration menu
    Copy the full SHA
    4478ecc View commit details
    Browse the repository at this point in the history