Preserve formatting when pasting - #62
Merged
janglad merged 5 commits intoSep 25, 2026
Merged
Conversation
This commit introduces functionality to preserve HTML block structure, inline marks, lists, and text alignment when pasting formatted HTML. Key changes include updates to the paste corpus to reflect these enhancements, as well as modifications to the DOM parsing and inline content handling to support text alignment properties. Additionally, tests have been added to ensure the correct preservation of marks and alignment during paste operations.
…ation This commit introduces several updates to the HTML parsing and sanitization processes. Key changes include the addition of a DOMParser fallback for environments lacking Object.hasOwn, improvements to inline stylesheet handling, and the restructuring of style resolution logic to better support class-based styles. Additionally, the size limit baseline for the @input/pen-interop package has been updated to reflect changes in the handling of safe stylesheet declarations and text alignment properties. These enhancements aim to ensure more consistent preservation of formatting during HTML imports and pastes.
Member
Author
|
bugbot run |
This commit updates the size limit baseline for the @input/pen-interop package to 118975 bytes, reflecting recent changes in the handling of safe stylesheet declarations. Additionally, it improves the parsing logic to ensure the preservation of the first rule after braceless at-rules in inline stylesheets. A new test has been added to verify this functionality, ensuring consistent formatting during HTML imports.
Member
Author
|
bugbot run |
This commit improves the handling of pasted HTML by ensuring that blank-line spacing and breaks are preserved in the resulting content structure. Key changes include updates to the inline content parsing logic and the addition of tests to verify the correct preservation of breaks and empty paragraphs during HTML imports. These enhancements aim to provide a more accurate representation of the original formatting when pasting content.
Member
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b471046. Configure here.
This commit enhances the formatting of the clipboard importer parsing test by restructuring the test data for better clarity. The changes include consistent indentation and formatting of the test cases, ensuring that the structure is more readable and maintainable. This refactor aims to improve the overall quality of the test suite.
janglad
requested review from
MatteoGauthier,
krijnrijshouwer and
noudadrichem
September 24, 2026 14:04
MatteoGauthier
approved these changes
Sep 25, 2026
noudadrichem
approved these changes
Sep 25, 2026
krijnrijshouwer
approved these changes
Sep 25, 2026
janglad
deleted the
fix/web-4052-pen-pasting-content-does-not-preserve-formatting
branch
September 25, 2026 08:45
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.
Before
Bullets, underline, ... lose formatting when pasting in from other rich text editors
Screen.Recording.2026-09-24.at.07.46.55.mov
After
Preserved. Tested with Apple Notes, Blocknote, Raycast notes
Screen.Recording.2026-09-24.at.15.15.36.mov
Summary
Fixes WEB-4052 by preserving common formatting when pasting HTML into Pen:
Keeps CSS support intentionally narrow:
.classandtag.classselectors with a closed set of formatting properties.Note
Medium Risk
Changes the security-sensitive HTML sanitize/import path with new CSS parsing and inlining, though scope is intentionally closed and heavily tested; bundle size for interop also increases materially.
Overview
Fixes WEB-4052 by improving HTML paste/import so block structure, spacing, lists, inline marks, and alignment survive typical rich-text clipboard payloads (including Apple Notes class-based CSS).
Sanitize + import: Before DOMPurify strips
<style>, the sanitizer inlines safe declarations from simple.class/tag.classrules onto matching elements; complex selectors and unsafe properties stay dropped. Inline styles now admit mark-bearingfont-weight,font-style, andtext-decoration*under the same closed filter.parseInlineContentmaps those styles (and explicit resets likefont-weight: normal) to Pen marks; lone block<br>becomes an empty paragraph while inline<br>becomes\n.domToBlocksmapstext-align/alignto a newtextAlignmentblock prop.Schema + renderers: Default text blocks gain optional
textAlignmentwith HTML export round-trip; DOM, React, and Vue apply it viaresolveBlockTextAlignment.Corpus/tests: Apple Notes fixture is hand-captured; Google Docs expectations now keep span bold/italic.
@input/pen-interopsize budget rises ~13% for the stylesheet pass. Specs (SEC3, interop, empty-blocks EM8) document the narrowed CSS behavior.Reviewed by Cursor Bugbot for commit b471046. Bugbot is set up for automated code reviews on this repo. Configure here.