-
-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Less data loss in external HTML #1605
Open
matthewlipski
wants to merge
6
commits into
unit-tests-setup
Choose a base branch
from
lossy-html-fixes
base: unit-tests-setup
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
# Conflicts: # pnpm-lock.yaml # tests/package.json
…d text color mark
@blocknote/ariakit
@blocknote/code-block
@blocknote/core
@blocknote/mantine
@blocknote/react
@blocknote/server-util
@blocknote/shadcn
@blocknote/xl-docx-exporter
@blocknote/xl-multi-column
@blocknote/xl-odt-exporter
@blocknote/xl-pdf-exporter
commit: |
9 tasks
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.
Converting to lossy HTML and back
This PR re-adds
data-*
attributes to external HTML, so that you can export blocks to HTML, then re-import them, and only lose block nesting (which is still preserved for list items). In addition, some bugs have been fixed which also prevented props from being parsed properly from external HTML.I've also added a bunch of test cases for this, which you can find in
If we decide we don't want to re-add the
data-*
attributes in order to not clutter the external HTML, we can revert the changes inserializeBlocksExternalHTML
(and the snapshot changes caused by those changes), and the tests + other fixes will still be worth keeping. Just note that some of the new tests will now fail since we won't be able to read props like text/background color.Also, the
data-*
attributes are not the "ideal" solution (hence why we may not want to keep that change in this PR). Ideally, we would implementtoExternalHTML
for inline content and styles (this is the rabbit hole I went down last week), so that we can serialize things we would normally just put indata-*
attributes to a more native HTML equivalent (e.g.style: color: red;
for text color). However, this is a lot of work to implement, so better to leave it for the future.Importing external HTML
This PR also adds additional parsing cases for the following:
color
stylesspan
s with inlinecolor
stylesbackground-color
stylesspan
s with inlinebackground-color
stylestext-alignment
stylesstart
attributeTest cases have also been added for these, along with tests for parsing other styles in various formats. For example, the tests now make sure that bold marks are read from
font-weight: bold
inline styles as well asb
andstrong
tags. You can find these tests inThis is for cases when markup data is stored in HTML-native tags/attributes/inline styles that aren't used in BlockNote's internal HTML.
Unsolved issues
Block prop parsing
Text color, background color, and text alignment props are still not parsed from external HTML properly. This is because the parsing for these is done in TipTap extensions, which the
DOMParser
doesn't see.To fix this, we need to get rid of the extensions and add the TipTap attributes from these nodes to the necessary nodes in their node specs. I was making quite some progress with this, but ran into issues adding color props to
tableCell
nodes.List item nesting
Converting nested list items to lossy HTML and back does not preserve nesting. This is a bigger issue, as it stems from us needing to convert single elements into both
blockContainer
andblockContent
nodes. This is because data is split across these 2 nodes (e.g. theblockContainer
stores the block ID while theblockContent
stores text alignment), but gets merged into a single element when serializing to external HTML.I managed to get parsing a single element into both nodes working by adding
consuming: false
to theblockContainer
parse rule, and making it parse any element with thedata-node-type="blockContainer"
ordata-node-type="blockOuter" attributes. This works fine for other elements like
ps and
h1s, but
lielements can be nested, and making them get parsed as
blockContainer`s breaks the nesting.It might be possible to get around this by storing the
blockContainer
attributes on theli
element and theblockContent
attributes on thep
element within it when serializing the blocks. However, I didn't have that much time to play around with it.