Auto-escape some markdown syntax in markdown labels#13887
Auto-escape some markdown syntax in markdown labels#13887lukasmasuch merged 2 commits intodevelopfrom
Conversation
Escape markdown syntax patterns in labels that would otherwise be stripped, leaving empty content. The fix adds backslash escapes before markdown list markers (-, +, *), headings (#), blockquotes (>), and ordered list markers (1., 1), etc.) when they appear at the start of a line followed by whitespace. Also includes comprehensive unit tests covering escaped patterns, non-escaped patterns, and edge cases like pre-escaped text and emphasis markdown.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ PR preview is ready!
|
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #7359 where widget labels containing markdown syntax characters (-, +, *, #, >, 1.) would render as empty because the markdown parser interpreted them as list markers, headings, or blockquotes that are then stripped from labels.
Changes:
- Added escaping logic in
StreamlitMarkdown.tsxto escape markdown syntax patterns whenisLabelis true - Added comprehensive unit tests covering escaped patterns, non-escaped patterns, edge cases, and emphasis markdown
- Added E2E tests for button labels with "+" and "1. Something" to verify the fix works end-to-end
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.tsx | Implements markdown syntax escaping for labels using two regex patterns: one for unordered lists/headings/blockquotes, one for ordered lists |
| frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.test.tsx | Adds 175 test cases covering escaped patterns (-, +, *, #, >, 1.), non-escaped patterns (mid-word hyphens, hashtags, decimals), pre-escaped text, and emphasis markdown; updates existing test expectations to reflect the new escaping behavior |
| e2e_playwright/st_button_test.py | Adds E2E test to verify markdown syntax characters are displayed literally in button labels |
| e2e_playwright/st_button.py | Adds test buttons with "+" and "1. Something" labels to test app |
frontend/lib/src/components/shared/StreamlitMarkdown/StreamlitMarkdown.test.tsx
Outdated
Show resolved
Hide resolved
…Markdown.test.tsx Co-authored-by: Copilot <[email protected]>
SummaryThis PR fixes issue #7359 where widget labels containing markdown syntax characters ( The fix adds regex-based escaping of markdown syntax patterns in Changed files:
Code QualityThe implementation is clean and well-structured:
Minor observations:
Test CoverageUnit tests (113 lines added): Comprehensive and well-organized:
E2E tests (12 lines added): Appropriately lightweight:
Backwards CompatibilityThis is a backwards-compatible bug fix. The behavioral change only affects labels that previously had their content incorrectly stripped:
The only theoretical concern would be users intentionally relying on markdown stripping in labels (e.g., using Security & Risk
AccessibilityThis change improves accessibility by ensuring widget labels display their intended text content. Previously, labels like No new interactive elements or ARIA attributes are introduced, so no additional accessibility concerns apply. Recommendations
VerdictAPPROVED: Clean, well-tested bug fix that correctly escapes markdown syntax characters in widget labels to prevent them from being stripped, resolving #7359 without breaking existing functionality. This is an automated AI review by |
Describe your changes
This PR fixes issue #7359 where widget labels containing markdown syntax characters (-, +, *, #, >, 1.) would render as empty labels because the markdown parser was interpreting them as list markers, headings, or blockquotes which are then stripped for labels.
The fix escapes these markdown syntax patterns when
isLabelis true, converting them to literal text by adding backslash escapes before markdown is processed. The escaping only applies to patterns followed by whitespace or end of line (e.g., "- item" is escaped but "not-a-list" is not).GitHub Issue Link (if applicable)
Fixes #7359
Testing Plan
Co-authored-by: sea-turt1e [email protected]
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.