Repository navigation
fix(qqofficial): prevent display-math clipping in lists - #10477
Open
Linyesantan wants to merge 3 commits into
Open
Linyesantan wants to merge 3 commits into
Linyesantan wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/platform/sources/qqofficial/qq_markdown_math.py" line_range="143" />
<code_context>
+ if index in starts:
+ line = line[starts[index].prefix :]
+ elif columns and index not in math_lines:
+ line = _dedent_container(line, columns)
+ if (index in starts or (columns and index in item_starts)) and (
+ output and output[-1].strip()
</code_context>
<issue_to_address>
**List structure is lost**
When a list item contains lifted display math followed by a paragraph, nested list, or sibling item, `_dedent_container` removes the full ancestor indentation from later lines, so content that belongs to the original list is rendered at the wrong level and the reply loses its list structure.
Preserve each later line’s relative list indentation when lifting the display math.
</issue_to_address>
### Comment 2
<location path="astrbot/core/platform/sources/qqofficial/qq_markdown_math.py" line_range="9" />
<code_context>
+
+from markdown_it import MarkdownIt
+
+_LIST_MARKER = re.compile(r"^[ \t]*(?:[-+*]|\d{1,9}[.)])[ \t]+")
+_MATH_START = re.compile(
+ r"^[ \t]*(?:(?:[-+*]|\d{1,9}[.)])[ \t]+)?(?P<delimiter>\$\$|\\\[)"
</code_context>
<issue_to_address>
**Quoted list equations remain clipped**
When a list containing display math is nested inside a blockquote, `_LIST_MARKER.match` and `_MATH_START.match` reject blockquote-prefixed lines, so the list item or math opening is not recognized and `normalize_qq_list_math` leaves the equation unchanged; QQ clips it.
Recognize blockquote prefixes when identifying list markers and display-math openings.
Also at `astrbot/core/platform/sources/qqofficial/qq_markdown_math.py:77-78`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: astrbot/core/platform/sources/qqofficial/qq_markdown_math.py:143, astrbot/core/platform/sources/qqofficial/qq_markdown_math.py:9
QQ rejects a C2C stream frame above ~4 KB of UTF-8 (流式消息分片过长,请拆分发送). The final list-math relayout resends the whole answer as one reset frame, so long answers were dropped after the first frames. Split stream frames on line boundaries under a 3000-byte budget, keep the cursor in step, and make sure the final frame still ends with a newline after relayout. Verified live: a 9.7 KB answer streamed as 10 accepted frames into one card.
…ay math Reopen the list items a lifted equation closes so later paragraphs, nested lists and sibling items keep their depth, and recognize blockquote-prefixed list math.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
QQ's native Markdown renderer can clip the right edge of display equations inside list items even after horizontal scrolling reaches its limit. This change promotes those equations to top-level blocks so the complete formula remains reachable.
Modifications
Normalize standalone
$$...$$and\[...\]equations inside lists, preserving TeX content and protecting code examples. Adjust subsequent list content indentation using the original Markdown structure.Preserve streaming deltas and apply the corrected layout as a final update to the same card. A replacement snapshot uses
reset=trueand restartsindexat1, as required by the QQ API.Add parser and native sender regressions, including every split boundary, multiple streamed updates, an empty final delta, and consecutive responses.
Declare
markdown-it-pyin both runtime dependency files andmdit-py-pluginsin the development dependencies for independent math parsing assertions.This is not a breaking change.
Verification steps and test results
Send a native QQ Markdown message containing a long equation inside a list, for example:
For C2C streaming, allow several intermediate updates before completing the response.
Scroll the equation fully to the right. The final term should be visible, and the reply should appear once.
Focused regressions on the upstream checkout:
The warning in the focused suite is the existing Python 3.12
audioopdeprecation warning. A broader QQ test run with thread warnings treated as errors encountered an existingaiosqliteworker / closed-event-loop problem, also reproduced on the unmodified upstream commit28a10c1.The installed AstrBot 4.28.2 sender was also verified against the real QQ API with three deltas and a final replacement:
The phone user confirmed that the formula ends are fully visible and the reply is not duplicated. The helper in this PR matches the implementation used for that live verification.
Checklist
requirements.txtandpyproject.toml; the test dependency is in the development group.Summary by Sourcery
Prevent QQ Markdown display equations in lists from being clipped while keeping streaming responses intact and delivering corrected final cards.
Bug Fixes:
Enhancements:
Build:
Tests: