Fix getMarkdown() returning instead of empty string#7497
Conversation
Fixes issue where getMarkdown() returns ' ' when the editor is empty, instead of returning an empty string as expected. This behavior was inconsistent with getText() which correctly returns an empty string. Changes: - Added isEmptyOutput() helper method to detect empty documents - Modified serialize() to check if output is only whitespace entities - Empty documents now return empty string, preserving blank lines between content - Added comprehensive tests for empty document and blank line preservation All existing functionality for blank line preservation remains intact. https://claude.ai/code/session_013q4GkzGgcDFg6oc4LwYo6y
🦋 Changeset detectedLatest commit: 6f583fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 72 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for tiptap-embed ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where getMarkdown() was returning the HTML entity instead of an empty string when the editor contains an empty document. The fix adds logic to detect when the serialized markdown output represents an empty document and returns an empty string in those cases, while preserving the entities used to maintain blank lines between paragraphs with actual content.
Changes:
- Added a new private method
isEmptyOutput()to detect empty markdown output consisting only of whitespace entities - Modified
serialize()method to check for empty output and return empty string when appropriate - Added two test cases to verify empty document handling and blank line preservation
- Added a changeset for the fix
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/markdown/src/MarkdownManager.ts | Added isEmptyOutput() helper method and integrated it into serialize() to detect and handle empty document output |
| packages/markdown/tests/manager.spec.ts | Added tests for empty document serialization and blank line preservation between paragraphs |
| .changeset/fix-empty-document-markdown.md | Added changeset documenting the bug fix for release notes |
Simplified serialize() method by removing redundant array/single-node branches. The renderNodes() method already handles both cases internally, making the conditional check unnecessary. This addresses Copilot review feedback about code duplication. https://claude.ai/code/session_013q4GkzGgcDFg6oc4LwYo6y
Fixed formatting issues to comply with project prettier configuration. https://claude.ai/code/session_013q4GkzGgcDFg6oc4LwYo6y
@tiptap/core
@tiptap/extension-audio
@tiptap/extension-blockquote
@tiptap/extension-bold
@tiptap/extension-bullet-list
@tiptap/extension-bubble-menu
@tiptap/extension-code
@tiptap/extension-code-block
@tiptap/extension-code-block-lowlight
@tiptap/extension-collaboration
@tiptap/extension-collaboration-caret
@tiptap/extension-color
@tiptap/extension-details
@tiptap/extension-document
@tiptap/extension-drag-handle-react
@tiptap/extension-drag-handle
@tiptap/extension-drag-handle-vue-2
@tiptap/extension-drag-handle-vue-3
@tiptap/extension-file-handler
@tiptap/extension-emoji
@tiptap/extension-floating-menu
@tiptap/extension-font-family
@tiptap/extension-hard-break
@tiptap/extension-heading
@tiptap/extension-highlight
@tiptap/extension-image
@tiptap/extension-horizontal-rule
@tiptap/extension-invisible-characters
@tiptap/extension-italic
@tiptap/extension-link
@tiptap/extension-list
@tiptap/extension-mathematics
@tiptap/extension-mention
@tiptap/extension-node-range
@tiptap/extension-ordered-list
@tiptap/extension-paragraph
@tiptap/extension-strike
@tiptap/extension-subscript
@tiptap/extension-superscript
@tiptap/extension-table
@tiptap/extension-table-of-contents
@tiptap/extension-text-align
@tiptap/extension-text
@tiptap/extension-text-style
@tiptap/extension-twitch
@tiptap/extension-underline
@tiptap/extension-typography
@tiptap/extension-unique-id
@tiptap/extension-youtube
@tiptap/html
@tiptap/extensions
@tiptap/markdown
@tiptap/react
@tiptap/starter-kit
@tiptap/pm
@tiptap/suggestion
@tiptap/static-renderer
@tiptap/vue-2
@tiptap/vue-3
@tiptap/extension-dropcursor
@tiptap/extension-character-count
@tiptap/extension-focus
@tiptap/extension-gapcursor
@tiptap/extension-history
@tiptap/extension-list-item
@tiptap/extension-list-keymap
@tiptap/extension-placeholder
@tiptap/extension-table-cell
@tiptap/extension-table-header
@tiptap/extension-task-item
@tiptap/extension-table-row
@tiptap/extension-task-list
commit: |
Changes Overview
Fixed
getMarkdown()returning instead of empty string when the editor is empty, ensuring consistent behavior with other output methods likegetText().Implementation Approach
Modified the
MarkdownManager.serialize()method to detect when the serialized output contains only whitespace entities ( or non-breaking space characters) and return an empty string in those cases.Added a private helper method
isEmptyOutput()that: entities and Unicode non-breaking spacesThis approach preserves the existing blank-line preservation functionality (where
is intentionally used between content paragraphs) while fixing the empty document case.Testing Done
Added comprehensive test coverage in
packages/markdown/__tests__/manager.spec.ts: Example test case:
Verification Steps
editor.getMarkdown()""(empty string) instead of getMarkdown()returns empty stringAdditional Notes
renderMarkdownimplementation remains unchanged when editor is empty #7495Checklist
Related Issues
Fixes #7495