Skip to content

fix(render): 修复发送的文本中的错误换行 - #237

Merged
molanp merged 1 commit into
mainfrom
fix/render-space
Aug 8, 2026
Merged

fix(render): 修复发送的文本中的错误换行#237
molanp merged 1 commit into
mainfrom
fix/render-space

Conversation

@molanp

@molanp molanp commented Aug 8, 2026

Copy link
Copy Markdown
Member

移除文本缓冲区连接时换行操作,同时修正了平台名称显示样式中的大小写转换问题

Summary by Sourcery

调整消息输出中的文本渲染和平台名称显示。

错误修复:

  • 通过在连接缓冲片段时不插入换行符,防止渲染文本中出现非预期的换行。
  • 通过移除模板中强制大写的样式,保留平台显示名称的原始大小写形式。
Original summary in English

Summary by Sourcery

Adjust text rendering and platform name display in message output.

Bug Fixes:

  • Prevent unintended line breaks in rendered text by concatenating buffered segments without inserting newline characters.
  • Preserve the original casing of platform display names by removing forced uppercase styling in the template.

移除文本缓冲区连接时换行操作,同时修正了平台名称显示样式中的大小写转换问题
@molanp molanp added the bug Something isn't working label Aug 8, 2026
@sourcery-ai

sourcery-ai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor
审阅者指南(在小型 PR 上折叠)

审阅者指南

此 PR 调整了文本渲染行为:在刷新缓冲文本时移除非预期的换行插入,并更新平台名称标签样式,使其保留原始大小写,而不再强制转换为全大写。

在 build_nodes 中更新后的缓冲文本刷新序列图

sequenceDiagram
    participant Parser as build_nodes
    participant Buffer as text_buffer
    participant Flush as flush_text
    participant Output as nodes

    Parser->>Buffer: accumulate text fragments
    Parser->>Flush: flush_text()
    activate Flush
    Flush->>Buffer: check if non_empty
    alt buffer_non_empty
        Flush->>Flush: text = "".join(text_buffer)
        Flush->>Output: append f"{author_name}:{text}"
        Flush->>Buffer: text_buffer = []
    else buffer_empty
        Flush->>Flush: [do_nothing]
    end
    deactivate Flush
Loading

文件级变更

变更 详情 文件
更改缓冲文本刷新逻辑,使文本块在拼接时直接连接,而不插入换行符或裁剪空白字符。
  • 将对 text_buffer 使用换行连接的拼接方式替换为直接字符串拼接。
  • 在刷新缓冲文本时移除对前后空白的去除操作。
  • 保持节点构造逻辑不变,使作者姓名和文本仍然组合为一个字符串。
src/nonebot_plugin_parser_lite/render/__init__.py
更新平台显示标签样式,不再强制转换为大写,保留原始 display_name 的大小写形式。
  • 从平台名称的 span 中移除强制转换为大写的文本变换工具类。
  • 保留平台名称标签的其他视觉样式,例如字体大小、字重、颜色和字间距。
src/nonebot_plugin_parser_lite/render/templates/macros.jinja

提示与命令

与 Sourcery 交互

  • 触发新审阅: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 从审阅评论生成 GitHub issue: 通过回复审阅评论让 Sourcery 根据该评论创建一个 issue。你也可以在审阅评论下回复 @sourcery-ai issue 来创建相应的 issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题的任意位置写入 @sourcery-ai,即可在任意时间生成标题。也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文的任意位置写入 @sourcery-ai summary,即可在你想要的确切位置生成 PR 摘要。也可以在 Pull Request 中评论 @sourcery-ai summary 来在任意时间(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。如果你已经处理完所有评论且不再希望看到它们,这将非常有用。
  • 忽略所有 Sourcery 审阅: 在 Pull Request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审阅。特别适用于你希望从一次全新的审阅开始——别忘了再评论 @sourcery-ai review 以触发新的审阅!

自定义你的体验

访问你的 控制面板 以:

  • 启用或禁用审阅功能,例如 Sourcery 生成的 Pull Request 摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、删除或编辑自定义审阅说明。
  • 调整其他审阅设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR adjusts text rendering behavior by removing unintended newline insertion when flushing buffered text, and updates the platform name label style to preserve its original casing instead of forcing uppercase.

Sequence diagram for updated buffered text flushing in build_nodes

sequenceDiagram
    participant Parser as build_nodes
    participant Buffer as text_buffer
    participant Flush as flush_text
    participant Output as nodes

    Parser->>Buffer: accumulate text fragments
    Parser->>Flush: flush_text()
    activate Flush
    Flush->>Buffer: check if non_empty
    alt buffer_non_empty
        Flush->>Flush: text = "".join(text_buffer)
        Flush->>Output: append f"{author_name}:{text}"
        Flush->>Buffer: text_buffer = []
    else buffer_empty
        Flush->>Flush: [do_nothing]
    end
    deactivate Flush
Loading

File-Level Changes

Change Details Files
Change buffered text flush logic so that text chunks are concatenated directly without inserting newlines or trimming whitespace.
  • Replace newline-joined concatenation of text_buffer with direct string concatenation.
  • Remove stripping of leading/trailing whitespace when flushing buffered text.
  • Keep node construction logic the same so author name and text are still combined into a single string.
src/nonebot_plugin_parser_lite/render/__init__.py
Update platform display label styling to no longer force uppercase, preserving the original display_name casing.
  • Remove the uppercase text-transform utility from the platform name span.
  • Retain other visual styles such as font size, weight, color, and letter spacing for the platform name label.
src/nonebot_plugin_parser_lite/render/templates/macros.jinja

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨,我在这里留下了一些整体性的反馈:

  • flush_text 中,移除换行连接和 strip() 会改变空白字符和换行符的处理方式;请考虑 text_buffer 中的首尾空格,或者缓冲片段之间缺少分隔符,是否会在最终渲染输出中导致意料之外的格式问题。
  • 从平台名称的 span 中移除 uppercase 会改变与其他平台标签的视觉一致性;如果只有某些平台需要保持大写样式,建议通过数据或条件类来控制,而不是在全局范围内统一添加或移除该类。
给 AI 代理的提示
请根据本次代码评审中的评论进行改进:

## 总体评论
-`flush_text` 中,移除换行连接和 `strip()` 会改变空白字符和换行符的处理方式;请考虑 `text_buffer` 中的首尾空格,或者缓冲片段之间缺少分隔符,是否会在最终渲染输出中导致意料之外的格式问题。
- 从平台名称的 span 中移除 `uppercase` 会改变与其他平台标签的视觉一致性;如果只有某些平台需要保持大写样式,建议通过数据或条件类来控制,而不是在全局范围内统一添加或移除该类。

Sourcery 对开源项目免费——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • In flush_text, removing the newline join and strip() changes how whitespace and line breaks are handled; consider whether leading/trailing spaces in text_buffer or missing separators between buffered segments could result in unintended formatting in the rendered output.
  • The removal of uppercase from the platform name span will change visual consistency with other platform labels; if only certain platforms should retain uppercase styling, consider handling this via data or conditional classes rather than applying/removing the class globally.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `flush_text`, removing the newline join and `strip()` changes how whitespace and line breaks are handled; consider whether leading/trailing spaces in `text_buffer` or missing separators between buffered segments could result in unintended formatting in the rendered output.
- The removal of `uppercase` from the platform name span will change visual consistency with other platform labels; if only certain platforms should retain uppercase styling, consider handling this via data or conditional classes rather than applying/removing the class globally.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@molanp
molanp merged commit 096d18e into main Aug 8, 2026
8 checks passed
@molanp
molanp deleted the fix/render-space branch August 8, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant