fix(tiptap): don't fail on node without content

This commit is contained in:
Colin Darie 2023-12-18 18:37:09 +01:00
parent 17a471e880
commit 45071b7bb6
No known key found for this signature in database
GPG key ID: 8C76CADD40253590
2 changed files with 13 additions and 0 deletions

View file

@ -44,6 +44,8 @@ class TiptapService
else
tags[id]
end
in { type: type } if ["paragraph", "title", "heading"].include?(type) && !node.key?(:content)
# noop
end
end

View file

@ -21,6 +21,9 @@ RSpec.describe TiptapService do
type: 'title',
content: [{ type: 'text', text: 'Title' }]
},
{
type: 'title' # remained empty in editor
},
{
type: 'paragraph',
attrs: { textAlign: 'right' },
@ -31,6 +34,10 @@ RSpec.describe TiptapService do
}
]
},
{
type: 'paragraph'
# no content, empty line
},
{
type: 'paragraph',
content: [
@ -70,6 +77,10 @@ RSpec.describe TiptapService do
attrs: { level: 3 },
content: [{ type: 'text', text: 'Heading 3' }]
},
{
type: 'heading',
attrs: { level: 3 } # remained empty in editor
},
{
type: 'bulletList',
content: [