Add normalizeHtmlIndentation prop to prevent indented HTML tags fro…
#264
+430
−11
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.
The second
Description
Description
When rendering AI-generated HTML content with nested tags (e.g., from streaming socket data), indented HTML tags with 4+ leading spaces are incorrectly parsed as code blocks by the Markdown parser.
This occurs because the Markdown specification treats lines starting with 4+ spaces as indented code blocks. While this behavior is correct for Markdown syntax, it causes issues when rendering HTML content that uses indentation for readability.
Problem Scenario
In streaming scenarios where HTML content is generated incrementally, nested tags are often indented with 4+ spaces for better readability. However, when such content is parsed by Streamdown, the indented HTML tags after blank lines are mistakenly treated as code blocks instead of HTML elements.
Example
HTML content like this:
Title One
Type of Change
Related Issues
Fixes #
Closes #
Related to #
Changes Made
normalizeHtmlIndentationprop - When enabled, removes excessive indentation (4+ spaces) before HTML tagsnormalizeHtmlIndentation()utility function - Exported for manual preprocessingTesting
Test Coverage
-Added 20 new unit tests in normalize-html-indentation.test.tsx covering:
Utility function edge cases (empty strings, non-HTML content, various HTML structures)
Streamdown component behavior with the new prop enabled/disabled
HTML block merging scenarios with nested tags, void elements, and self-closing tags
-All 541 existing tests continue to pass
-No breaking changes to existing functionality
Screenshots/Demos
Before (without normalizeHtmlIndentation):
Indented HTML tags after blank lines are rendered as code blocks.
After (with normalizeHtmlIndentation={true}):
All HTML tags are correctly rendered as HTML elements.
Checklist
pnpm changeset)Changeset
Additional Notes