From 42e46992696791d33b4fa38a432fb96d218ced7c Mon Sep 17 00:00:00 2001 From: matthewlipski Date: Fri, 13 Sep 2024 00:30:49 +0200 Subject: [PATCH 1/4] Added props data attributes to lossy HTML --- .../__snapshots__/complex/misc/external.html | 2 +- .../customParagraph/styled/external.html | 2 +- .../__snapshots__/file/basic/external.html | 2 +- .../__snapshots__/file/nested/external.html | 2 +- .../file/noCaption/external.html | 2 +- .../__snapshots__/file/noName/external.html | 2 +- .../fontSize/basic/external.html | 2 +- .../hardbreak/basic/external.html | 2 +- .../hardbreak/between-links/external.html | 2 +- .../__snapshots__/hardbreak/end/external.html | 2 +- .../hardbreak/link/external.html | 2 +- .../hardbreak/multiple/external.html | 2 +- .../hardbreak/only/external.html | 2 +- .../hardbreak/start/external.html | 2 +- .../hardbreak/styles/external.html | 2 +- .../__snapshots__/image/basic/external.html | 2 +- .../__snapshots__/image/nested/external.html | 2 +- .../image/noCaption/external.html | 2 +- .../__snapshots__/image/noName/external.html | 2 +- .../image/noPreview/external.html | 2 +- .../__snapshots__/link/adjacent/external.html | 2 +- .../__snapshots__/link/basic/external.html | 2 +- .../__snapshots__/link/styled/external.html | 2 +- .../__snapshots__/mention/basic/external.html | 2 +- .../paragraph/basic/external.html | 2 +- .../paragraph/empty/external.html | 2 +- .../paragraph/lineBreaks/external.html | 2 +- .../paragraph/nested/external.html | 2 +- .../paragraph/styled/external.html | 2 +- .../simpleCustomParagraph/basic/external.html | 2 +- .../nested/external.html | 2 +- .../styled/external.html | 2 +- .../simpleImage/basic/external.html | 2 +- .../simpleImage/button/external.html | 2 +- .../simpleImage/nested/external.html | 2 +- .../simpleImage/noCaption/external.html | 2 +- .../simpleImage/noName/external.html | 2 +- .../simpleImage/noPreview/external.html | 2 +- .../__snapshots__/small/basic/external.html | 2 +- .../__snapshots__/tag/basic/external.html | 2 +- .../selectionLeavesBlockChildren.html | 2 +- .../selectionSpansBlocksChildren.html | 2 +- .../selectionWithinBlockChildren.html | 2 +- .../html/util/simplifyBlocksRehypePlugin.ts | 54 ++++++++++++++++++- 44 files changed, 95 insertions(+), 45 deletions(-) diff --git a/packages/core/src/api/exporters/html/__snapshots__/complex/misc/external.html b/packages/core/src/api/exporters/html/__snapshots__/complex/misc/external.html index c6f43c11b1..859d5c7a7e 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/complex/misc/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/complex/misc/external.html @@ -1 +1 @@ -

Heading 2

Paragraph

\ No newline at end of file +

Heading 2

Paragraph

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html b/packages/core/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html index 1930c65a95..d56197b21a 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/customParagraph/styled/external.html @@ -1 +1 @@ -

Hello World

\ No newline at end of file +

Hello World

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/file/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/file/basic/external.html index 3c59ab678d..2fef8bae04 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/file/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/file/basic/external.html @@ -1 +1 @@ -
example

Caption

\ No newline at end of file +
example

Caption

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/file/nested/external.html b/packages/core/src/api/exporters/html/__snapshots__/file/nested/external.html index b108f11ead..76ff9df2a3 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/file/nested/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/file/nested/external.html @@ -1 +1 @@ -
example

Caption

example

Caption

\ No newline at end of file +
example

Caption

example

Caption

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/file/noCaption/external.html b/packages/core/src/api/exporters/html/__snapshots__/file/noCaption/external.html index fdda900023..e1c8211b39 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/file/noCaption/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/file/noCaption/external.html @@ -1 +1 @@ -example \ No newline at end of file +example \ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/file/noName/external.html b/packages/core/src/api/exporters/html/__snapshots__/file/noName/external.html index 10ae0e8aac..b29226235b 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/file/noName/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/file/noName/external.html @@ -1 +1 @@ -
exampleURL

Caption

\ No newline at end of file +
exampleURL

Caption

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/fontSize/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/fontSize/basic/external.html index bc3cb38f5c..f6e857fdfe 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/fontSize/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/fontSize/basic/external.html @@ -1 +1 @@ -

This is text with a custom fontSize

\ No newline at end of file +

This is text with a custom fontSize

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html index d9af93c752..e64f4a3a23 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/basic/external.html @@ -1 +1 @@ -

Text1
Text2

\ No newline at end of file +

Text1
Text2

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html index bb3c90b25c..ccc63111c8 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/between-links/external.html @@ -1 +1 @@ -

Link1
Link2

\ No newline at end of file +

Link1
Link2

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/end/external.html b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/end/external.html index 755d65be05..dac217f275 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/end/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/end/external.html @@ -1 +1 @@ -

Text1

\ No newline at end of file +

Text1

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/link/external.html b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/link/external.html index 70d35a5d8c..5e3a2e2cc4 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/link/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/link/external.html @@ -1 +1 @@ -

Link1
Link1

\ No newline at end of file +

Link1
Link1

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html index db553727c0..89dd31150d 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/multiple/external.html @@ -1 +1 @@ -

Text1
Text2
Text3

\ No newline at end of file +

Text1
Text2
Text3

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/only/external.html b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/only/external.html index 82093bacd3..1d98fbbf16 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/only/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/only/external.html @@ -1 +1 @@ -


\ No newline at end of file +


\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/start/external.html b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/start/external.html index 550b2b88d2..3504d3778d 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/start/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/start/external.html @@ -1 +1 @@ -


Text1

\ No newline at end of file +


Text1

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html index 193b4d61aa..e2e96c2cfe 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/hardbreak/styles/external.html @@ -1 +1 @@ -

Text1
Text2

\ No newline at end of file +

Text1
Text2

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/image/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/image/basic/external.html index bdd29c83d4..9295cf8f38 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/image/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/image/basic/external.html @@ -1 +1 @@ -
example
Caption
\ No newline at end of file +
example
Caption
\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/image/nested/external.html b/packages/core/src/api/exporters/html/__snapshots__/image/nested/external.html index e06baeed6d..9c87fef63d 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/image/nested/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/image/nested/external.html @@ -1 +1 @@ -
Caption
Caption
Caption
Caption
\ No newline at end of file +
Caption
Caption
Caption
Caption
\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/image/noCaption/external.html b/packages/core/src/api/exporters/html/__snapshots__/image/noCaption/external.html index 01db39dbf1..22408bfc12 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/image/noCaption/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/image/noCaption/external.html @@ -1 +1 @@ -example \ No newline at end of file +example \ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/image/noName/external.html b/packages/core/src/api/exporters/html/__snapshots__/image/noName/external.html index 8e7317b66d..df180bf54e 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/image/noName/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/image/noName/external.html @@ -1 +1 @@ -
Caption
Caption
\ No newline at end of file +
Caption
Caption
\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/image/noPreview/external.html b/packages/core/src/api/exporters/html/__snapshots__/image/noPreview/external.html index 3c59ab678d..591a3abb43 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/image/noPreview/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/image/noPreview/external.html @@ -1 +1 @@ -
example

Caption

\ No newline at end of file +
example

Caption

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/link/adjacent/external.html b/packages/core/src/api/exporters/html/__snapshots__/link/adjacent/external.html index 8876f46341..849c727028 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/link/adjacent/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/link/adjacent/external.html @@ -1 +1 @@ -

WebsiteWebsite2

\ No newline at end of file +

WebsiteWebsite2

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/link/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/link/basic/external.html index 1b68f7c926..3873eaa8ba 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/link/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/link/basic/external.html @@ -1 +1 @@ -

Website

\ No newline at end of file +

Website

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/link/styled/external.html b/packages/core/src/api/exporters/html/__snapshots__/link/styled/external.html index 36a369a5e4..3304968a98 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/link/styled/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/link/styled/external.html @@ -1 +1 @@ -

Website

\ No newline at end of file +

Website

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/mention/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/mention/basic/external.html index ac270828c3..967b6d2fd7 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/mention/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/mention/basic/external.html @@ -1 +1 @@ -

I enjoy working with @Matthew

+

I enjoy working with @Matthew

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/paragraph/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/paragraph/basic/external.html index 76bbb30e4d..38addeaada 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/paragraph/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/paragraph/basic/external.html @@ -1 +1 @@ -

Paragraph

\ No newline at end of file +

Paragraph

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/paragraph/empty/external.html b/packages/core/src/api/exporters/html/__snapshots__/paragraph/empty/external.html index c659260f6e..540135ad6a 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/paragraph/empty/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/paragraph/empty/external.html @@ -1 +1 @@ -

\ No newline at end of file +

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/paragraph/lineBreaks/external.html b/packages/core/src/api/exporters/html/__snapshots__/paragraph/lineBreaks/external.html index e27c98babb..02b91a8da0 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/paragraph/lineBreaks/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/paragraph/lineBreaks/external.html @@ -1 +1 @@ -

Line 1
Line 2

\ No newline at end of file +

Line 1
Line 2

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/paragraph/nested/external.html b/packages/core/src/api/exporters/html/__snapshots__/paragraph/nested/external.html index 9dc893acc1..9490db41f4 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/paragraph/nested/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/paragraph/nested/external.html @@ -1 +1 @@ -

Paragraph

Nested Paragraph 1

Nested Paragraph 2

\ No newline at end of file +

Paragraph

Nested Paragraph 1

Nested Paragraph 2

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/paragraph/styled/external.html b/packages/core/src/api/exporters/html/__snapshots__/paragraph/styled/external.html index 49d98e41d3..402117f50b 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/paragraph/styled/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/paragraph/styled/external.html @@ -1 +1 @@ -

Plain Red Text Blue Background Mixed Colors

\ No newline at end of file +

Plain Red Text Blue Background Mixed Colors

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html index 92ba7801cb..eff23b23a3 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/basic/external.html @@ -1 +1 @@ -

Custom Paragraph

\ No newline at end of file +

Custom Paragraph

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html index 8ca20343ba..7f3f7817a5 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/nested/external.html @@ -1 +1 @@ -

Custom Paragraph

Nested Custom Paragraph 1

Nested Custom Paragraph 2

\ No newline at end of file +

Custom Paragraph

Nested Custom Paragraph 1

Nested Custom Paragraph 2

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html index 684688bb9d..639e0a20bd 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleCustomParagraph/styled/external.html @@ -1 +1 @@ -

Plain Red Text Blue Background Mixed Colors

\ No newline at end of file +

Plain Red Text Blue Background Mixed Colors

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html index 8b6ce77739..8e3e0c06f3 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/basic/external.html @@ -1 +1 @@ -
example

Caption

\ No newline at end of file +
example

Caption

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/button/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/button/external.html index 5628e8c3fb..b8f59a9535 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/button/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/button/external.html @@ -1 +1 @@ -

Add image

\ No newline at end of file +

Add image

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html index 0d7a242de1..ce8234ecaf 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/nested/external.html @@ -1 +1 @@ -
example

Caption

example

Caption

\ No newline at end of file +
example

Caption

example

Caption

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html index 4d41622ab6..3c5930a041 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noCaption/external.html @@ -1 +1 @@ -
example

\ No newline at end of file +
example

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html index f502279fc9..c8869da27f 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noName/external.html @@ -1 +1 @@ -
Caption

Caption

\ No newline at end of file +
Caption

Caption

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html index 6aa85bf79d..7ad0086924 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/simpleImage/noPreview/external.html @@ -1 +1 @@ -

example

Caption

\ No newline at end of file +

example

Caption

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/small/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/small/basic/external.html index 50ef98b2ce..8bfcd2ed1d 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/small/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/small/basic/external.html @@ -1 +1 @@ -

This is a small text

\ No newline at end of file +

This is a small text

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots__/tag/basic/external.html b/packages/core/src/api/exporters/html/__snapshots__/tag/basic/external.html index c243b63eb2..d6e63c9cec 100644 --- a/packages/core/src/api/exporters/html/__snapshots__/tag/basic/external.html +++ b/packages/core/src/api/exporters/html/__snapshots__/tag/basic/external.html @@ -1 +1 @@ -

I love #BlockNote

\ No newline at end of file +

I love #BlockNote

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionLeavesBlockChildren.html b/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionLeavesBlockChildren.html index f3d8d4b716..5bad4edb45 100644 --- a/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionLeavesBlockChildren.html +++ b/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionLeavesBlockChildren.html @@ -1 +1 @@ -

Nested Paragraph 1

Nested Paragraph 2

Nested Paragraph 3

Paragraph 2

\ No newline at end of file +

Nested Paragraph 1

Nested Paragraph 2

Nested Paragraph 3

Paragraph 2

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionSpansBlocksChildren.html b/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionSpansBlocksChildren.html index 0af1f2e912..5a94207829 100644 --- a/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionSpansBlocksChildren.html +++ b/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionSpansBlocksChildren.html @@ -1 +1 @@ -

Nested Paragraph 1

Nested Paragraph 2

Nested Paragraph 3

Paragraph 2

Nested Paragraph 1

Nested Paragraph 2

Nested Paragraph 3

\ No newline at end of file +

Nested Paragraph 1

Nested Paragraph 2

Nested Paragraph 3

Paragraph 2

Nested Paragraph 1

Nested Paragraph 2

Nested Paragraph 3

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionWithinBlockChildren.html b/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionWithinBlockChildren.html index 584994b802..8bb03060e1 100644 --- a/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionWithinBlockChildren.html +++ b/packages/core/src/api/exporters/html/__snapshots_fragment_edge_cases__/selectionWithinBlockChildren.html @@ -1 +1 @@ -

Nested Paragraph 1

Nested Paragraph 2

Nested Paragraph 3

\ No newline at end of file +

Nested Paragraph 1

Nested Paragraph 2

Nested Paragraph 3

\ No newline at end of file diff --git a/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts b/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts index 70d2869a12..c75f30350b 100644 --- a/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +++ b/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts @@ -62,6 +62,32 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { return classNames?.includes("bn-block-group"); }) as HASTElement | undefined; + // Saves the data attributes of the block container, excluding the block + // ID and node type as we're removing the block structure. This means that + // only attributes for the block's props are saved. + const blockContainerDataAttributes = Object.fromEntries( + Object.entries(blockContainer.properties || {}).filter( + ([key]) => + key.startsWith("data") && key !== "dataId" && key !== "dataNodeType" + ) + ); + // Saves the data attributes of the block content, excluding the block + // content type as we're removing the block structure. This means that + // only attributes for the block's props are saved. + const blockContentDataAttributes = Object.fromEntries( + Object.entries(blockContent?.properties || {}).filter( + ([key]) => + key.startsWith("data") && + key !== "dataContentType" && + key !== "dataFileBlock" + ) + ); + // All the block's props as data attributes. + const blockPropsDataAttributes = { + ...blockContainerDataAttributes, + ...blockContentDataAttributes, + }; + // When the selection starts in a nested block, the Fragment from it omits // the `blockContent` node of the parent `blockContainer` if it's not also // included in the selection. This is because ProseMirror preserves the @@ -142,7 +168,19 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { // Lifts all children out of the current block, as only list items should allow nesting. tree.children.splice(i + 1, 0, ...blockGroup.children); // Replaces the block with only the content inside it. - tree.children[i] = blockContent.children[0]; + const content = blockContent.children[0] as HASTElement; + // Removes all BlockNote specific class names from the block content. + const className = + ((content.properties?.className as string[]) || []).filter( + (className) => !className.startsWith("bn-") + ) || []; + // Adds all the block's props as data attributes. + content.properties = { + ...content.properties, + ...blockPropsDataAttributes, + className: className.length > 0 ? className : undefined, + }; + tree.children[i] = content; // Updates the current index and number of child elements. const numElementsAdded = blockGroup.children.length; @@ -150,7 +188,19 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { numChildElements += numElementsAdded; } else { // Replaces the block with only the content inside it. - tree.children[i] = blockContent.children[0]; + const content = blockContent.children[0] as HASTElement; + // Removes all BlockNote specific class names from the block content. + const className = + ((content.properties?.className as string[]) || []).filter( + (className) => !className.startsWith("bn-") + ) || []; + // Adds all the block's props as data attributes. + content.properties = { + ...content.properties, + ...blockPropsDataAttributes, + className: className.length > 0 ? className : undefined, + }; + tree.children[i] = content; } } From bb42a96dc0381d22065ad6a21754f82ff257c026 Mon Sep 17 00:00:00 2001 From: matthewlipski Date: Fri, 13 Sep 2024 16:53:26 +0200 Subject: [PATCH 2/4] Reduced duplicate code --- .../html/util/simplifyBlocksRehypePlugin.ts | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts b/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts index c75f30350b..a4cfe195a2 100644 --- a/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +++ b/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts @@ -6,6 +6,23 @@ type SimplifyBlocksOptions = { unorderedListItemBlockTypes: Set; }; +function addAttributesAndRemoveClasses( + element: HASTElement, + attributes: Record +) { + // Removes all BlockNote specific class names. + const className = + ((element.properties?.className as string[]) || []).filter( + (className) => !className.startsWith("bn-") + ) || []; + // Adds all block props as data attributes. + element.properties = { + ...element.properties, + ...attributes, + className: className.length > 0 ? className : undefined, + }; +} + /** * Rehype plugin which converts the HTML output string rendered by BlockNote into a simplified structure which better * follows HTML standards. It does several things: @@ -169,17 +186,7 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { tree.children.splice(i + 1, 0, ...blockGroup.children); // Replaces the block with only the content inside it. const content = blockContent.children[0] as HASTElement; - // Removes all BlockNote specific class names from the block content. - const className = - ((content.properties?.className as string[]) || []).filter( - (className) => !className.startsWith("bn-") - ) || []; - // Adds all the block's props as data attributes. - content.properties = { - ...content.properties, - ...blockPropsDataAttributes, - className: className.length > 0 ? className : undefined, - }; + addAttributesAndRemoveClasses(content, blockPropsDataAttributes); tree.children[i] = content; // Updates the current index and number of child elements. @@ -189,17 +196,7 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { } else { // Replaces the block with only the content inside it. const content = blockContent.children[0] as HASTElement; - // Removes all BlockNote specific class names from the block content. - const className = - ((content.properties?.className as string[]) || []).filter( - (className) => !className.startsWith("bn-") - ) || []; - // Adds all the block's props as data attributes. - content.properties = { - ...content.properties, - ...blockPropsDataAttributes, - className: className.length > 0 ? className : undefined, - }; + addAttributesAndRemoveClasses(content, blockPropsDataAttributes); tree.children[i] = content; } } From 739f31688fa03af286e25f7ff1517f7364eb92c2 Mon Sep 17 00:00:00 2001 From: matthewlipski Date: Fri, 13 Sep 2024 17:14:58 +0200 Subject: [PATCH 3/4] Updated `data-` attributes to filter out and react snapshots --- .../src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts | 4 +++- .../react/src/test/__snapshots__/fontSize/basic/external.html | 2 +- .../react/src/test/__snapshots__/mention/basic/external.html | 2 +- .../__snapshots__/reactCustomParagraph/styled/external.html | 2 +- .../src/test/__snapshots__/reactFile/basic/external.html | 2 +- .../src/test/__snapshots__/reactFile/nested/external.html | 2 +- .../src/test/__snapshots__/reactFile/noCaption/external.html | 2 +- .../src/test/__snapshots__/reactFile/noName/external.html | 2 +- .../src/test/__snapshots__/reactImage/basic/external.html | 2 +- .../src/test/__snapshots__/reactImage/nested/external.html | 2 +- .../src/test/__snapshots__/reactImage/noCaption/external.html | 2 +- .../src/test/__snapshots__/reactImage/noName/external.html | 2 +- .../src/test/__snapshots__/reactImage/noPreview/external.html | 2 +- .../simpleReactCustomParagraph/styled/external.html | 2 +- .../react/src/test/__snapshots__/small/basic/external.html | 2 +- packages/react/src/test/__snapshots__/tag/basic/external.html | 2 +- 16 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts b/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts index a4cfe195a2..9847f5a398 100644 --- a/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts +++ b/packages/core/src/api/exporters/html/util/simplifyBlocksRehypePlugin.ts @@ -96,7 +96,9 @@ export function simplifyBlocks(options: SimplifyBlocksOptions) { ([key]) => key.startsWith("data") && key !== "dataContentType" && - key !== "dataFileBlock" + key !== "dataFileBlock" && + key !== "dataNodeViewWrapper" && + key !== "dataEditable" ) ); // All the block's props as data attributes. diff --git a/packages/react/src/test/__snapshots__/fontSize/basic/external.html b/packages/react/src/test/__snapshots__/fontSize/basic/external.html index 0271307b91..f10ad63bc8 100644 --- a/packages/react/src/test/__snapshots__/fontSize/basic/external.html +++ b/packages/react/src/test/__snapshots__/fontSize/basic/external.html @@ -1 +1 @@ -

This is text with a custom fontSize

\ No newline at end of file +

This is text with a custom fontSize

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/mention/basic/external.html b/packages/react/src/test/__snapshots__/mention/basic/external.html index ac270828c3..967b6d2fd7 100644 --- a/packages/react/src/test/__snapshots__/mention/basic/external.html +++ b/packages/react/src/test/__snapshots__/mention/basic/external.html @@ -1 +1 @@ -

I enjoy working with @Matthew

+

I enjoy working with @Matthew

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactCustomParagraph/styled/external.html b/packages/react/src/test/__snapshots__/reactCustomParagraph/styled/external.html index 2971f11056..bf4097c8e1 100644 --- a/packages/react/src/test/__snapshots__/reactCustomParagraph/styled/external.html +++ b/packages/react/src/test/__snapshots__/reactCustomParagraph/styled/external.html @@ -1 +1 @@ -

Hello World

\ No newline at end of file +

Hello World

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactFile/basic/external.html b/packages/react/src/test/__snapshots__/reactFile/basic/external.html index 3c59ab678d..2fef8bae04 100644 --- a/packages/react/src/test/__snapshots__/reactFile/basic/external.html +++ b/packages/react/src/test/__snapshots__/reactFile/basic/external.html @@ -1 +1 @@ -
example

Caption

\ No newline at end of file +
example

Caption

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactFile/nested/external.html b/packages/react/src/test/__snapshots__/reactFile/nested/external.html index b108f11ead..76ff9df2a3 100644 --- a/packages/react/src/test/__snapshots__/reactFile/nested/external.html +++ b/packages/react/src/test/__snapshots__/reactFile/nested/external.html @@ -1 +1 @@ -
example

Caption

example

Caption

\ No newline at end of file +
example

Caption

example

Caption

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactFile/noCaption/external.html b/packages/react/src/test/__snapshots__/reactFile/noCaption/external.html index fdda900023..e1c8211b39 100644 --- a/packages/react/src/test/__snapshots__/reactFile/noCaption/external.html +++ b/packages/react/src/test/__snapshots__/reactFile/noCaption/external.html @@ -1 +1 @@ -example \ No newline at end of file +example \ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactFile/noName/external.html b/packages/react/src/test/__snapshots__/reactFile/noName/external.html index 10ae0e8aac..b29226235b 100644 --- a/packages/react/src/test/__snapshots__/reactFile/noName/external.html +++ b/packages/react/src/test/__snapshots__/reactFile/noName/external.html @@ -1 +1 @@ -
exampleURL

Caption

\ No newline at end of file +
exampleURL

Caption

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactImage/basic/external.html b/packages/react/src/test/__snapshots__/reactImage/basic/external.html index bdd29c83d4..9295cf8f38 100644 --- a/packages/react/src/test/__snapshots__/reactImage/basic/external.html +++ b/packages/react/src/test/__snapshots__/reactImage/basic/external.html @@ -1 +1 @@ -
example
Caption
\ No newline at end of file +
example
Caption
\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactImage/nested/external.html b/packages/react/src/test/__snapshots__/reactImage/nested/external.html index cfb76b3736..18ff318b71 100644 --- a/packages/react/src/test/__snapshots__/reactImage/nested/external.html +++ b/packages/react/src/test/__snapshots__/reactImage/nested/external.html @@ -1 +1 @@ -
example
Caption
example
Caption
\ No newline at end of file +
example
Caption
example
Caption
\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactImage/noCaption/external.html b/packages/react/src/test/__snapshots__/reactImage/noCaption/external.html index 01db39dbf1..22408bfc12 100644 --- a/packages/react/src/test/__snapshots__/reactImage/noCaption/external.html +++ b/packages/react/src/test/__snapshots__/reactImage/noCaption/external.html @@ -1 +1 @@ -example \ No newline at end of file +example \ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactImage/noName/external.html b/packages/react/src/test/__snapshots__/reactImage/noName/external.html index 8e7317b66d..df180bf54e 100644 --- a/packages/react/src/test/__snapshots__/reactImage/noName/external.html +++ b/packages/react/src/test/__snapshots__/reactImage/noName/external.html @@ -1 +1 @@ -
Caption
Caption
\ No newline at end of file +
Caption
Caption
\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/reactImage/noPreview/external.html b/packages/react/src/test/__snapshots__/reactImage/noPreview/external.html index 3c59ab678d..591a3abb43 100644 --- a/packages/react/src/test/__snapshots__/reactImage/noPreview/external.html +++ b/packages/react/src/test/__snapshots__/reactImage/noPreview/external.html @@ -1 +1 @@ -
example

Caption

\ No newline at end of file +
example

Caption

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/simpleReactCustomParagraph/styled/external.html b/packages/react/src/test/__snapshots__/simpleReactCustomParagraph/styled/external.html index 970057fffe..9312451d94 100644 --- a/packages/react/src/test/__snapshots__/simpleReactCustomParagraph/styled/external.html +++ b/packages/react/src/test/__snapshots__/simpleReactCustomParagraph/styled/external.html @@ -1 +1 @@ -

Plain Red Text Blue Background Mixed Colors

\ No newline at end of file +

Plain Red Text Blue Background Mixed Colors

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/small/basic/external.html b/packages/react/src/test/__snapshots__/small/basic/external.html index 50ef98b2ce..8bfcd2ed1d 100644 --- a/packages/react/src/test/__snapshots__/small/basic/external.html +++ b/packages/react/src/test/__snapshots__/small/basic/external.html @@ -1 +1 @@ -

This is a small text

\ No newline at end of file +

This is a small text

\ No newline at end of file diff --git a/packages/react/src/test/__snapshots__/tag/basic/external.html b/packages/react/src/test/__snapshots__/tag/basic/external.html index c243b63eb2..d6e63c9cec 100644 --- a/packages/react/src/test/__snapshots__/tag/basic/external.html +++ b/packages/react/src/test/__snapshots__/tag/basic/external.html @@ -1 +1 @@ -

I love #BlockNote

\ No newline at end of file +

I love #BlockNote

\ No newline at end of file From 04dd983aed17334bb71bbc235481c792f5fc593e Mon Sep 17 00:00:00 2001 From: matthewlipski Date: Fri, 13 Sep 2024 17:24:35 +0200 Subject: [PATCH 4/4] Updated snapshots --- .../context/__snapshots__/ServerBlockNoteEditor.test.ts.snap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server-util/src/context/__snapshots__/ServerBlockNoteEditor.test.ts.snap b/packages/server-util/src/context/__snapshots__/ServerBlockNoteEditor.test.ts.snap index ded1aa89ef..4ce7b821a9 100644 --- a/packages/server-util/src/context/__snapshots__/ServerBlockNoteEditor.test.ts.snap +++ b/packages/server-util/src/context/__snapshots__/ServerBlockNoteEditor.test.ts.snap @@ -2,7 +2,7 @@ exports[`Test ServerBlockNoteEditor > converts to HTML (blocksToFullHTML) 1`] = `"

Heading 2

Paragraph

list item

"`; -exports[`Test ServerBlockNoteEditor > converts to and from HTML (blocksToHTMLLossy) 1`] = `"

Heading 2

Paragraph

  • list item

"`; +exports[`Test ServerBlockNoteEditor > converts to and from HTML (blocksToHTMLLossy) 1`] = `"

Heading 2

Paragraph

  • list item

"`; exports[`Test ServerBlockNoteEditor > converts to and from HTML (blocksToHTMLLossy) 2`] = ` [ @@ -30,7 +30,7 @@ exports[`Test ServerBlockNoteEditor > converts to and from HTML (blocksToHTMLLos "props": { "backgroundColor": "default", "level": 2, - "textAlignment": "left", + "textAlignment": "right", "textColor": "default", }, "type": "heading",