Skip to content

fix(agents): normalize single newlines to markdown paragraphs in quiz content#441

Merged
pancacake merged 1 commit into
HKUDS:devfrom
wedone:fix/quiz-question-paragraph-spacing
May 12, 2026
Merged

fix(agents): normalize single newlines to markdown paragraphs in quiz content#441
pancacake merged 1 commit into
HKUDS:devfrom
wedone:fix/quiz-question-paragraph-spacing

Conversation

@wedone

@wedone wedone commented May 4, 2026

Copy link
Copy Markdown
Contributor

Description

Fix quiz question content not rendering with proper paragraph spacing in the web UI.

LLMs often emit single \n characters between logical paragraphs in question, correct_answer, and explanation fields (e.g. (1)… (2)…). In Markdown, a single newline is treated as a soft-break and rendered as a space, causing react-markdown to collapse everything into one dense <p> block.

This PR adds _normalize_markdown_paragraphs() to the Generator class so that isolated single newlines are converted to \n\n paragraph breaks before the payload is returned. Structural markers (lists, code fences, tables, headings) are preserved to avoid breaking intentional formatting.

Related Issues

  • Related to quiz content readability in the web UI

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services
  • tools
  • utils
  • web (Frontend) — indirectly fixes rendering
  • docs (Documentation)
  • scripts
  • tests
  • Other: ...

Checklist

  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary).
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

File changed: deeptutor/agents/question/agents/generator.py

Summary of changes:

  • Added _normalize_markdown_paragraphs() static method
  • Applied paragraph normalization to question, correct_answer, and explanation fields in _normalize_payload_shape()

Before fix (raw LLM output):

已知平面向量 $\boldsymbol{a}=(n,2)$...
(1)若 $\boldsymbol{a} \perp \boldsymbol{b}$,求...
(2)若 $\boldsymbol{a}$ 与 $\boldsymbol{b}$ 的夹角为锐角...

→ Renders as one dense block with no paragraph breaks.

After fix (normalized):

已知平面向量 $\boldsymbol{a}=(n,2)$...

(1)若 $\boldsymbol{a} \perp \boldsymbol{b}$,求...

(2)若 $\boldsymbol{a}$ 与 $\boldsymbol{b}$ 的夹角为锐角...

→ Each sub-question renders as a separate <p> element, significantly improving readability.

Rebased onto: v1.3.7 (latest upstream main)

… content

LLMs often emit single \\n characters between logical paragraphs in
question / answer / explanation fields. In markdown this renders as a
soft-break, causing the front-end to collapse everything into one dense
block.

Add _normalize_markdown_paragraphs() to Generator so that isolated
single newlines are turned into \\n\\n paragraph breaks before the
payload is returned. Structural markers (lists, code fences, tables,
headings) are preserved to avoid breaking intentional formatting.

Fixes quiz questions appearing without paragraph spacing in the web UI.
@wedone wedone force-pushed the fix/quiz-question-paragraph-spacing branch from a079af0 to 6ca722c Compare May 4, 2026 09:00
@wedone wedone changed the base branch from main to dev May 6, 2026 14:46
@pancacake pancacake merged commit b9dc14c into HKUDS:dev May 12, 2026
7 checks passed
@wedone wedone deleted the fix/quiz-question-paragraph-spacing branch June 11, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants