-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: unexpected renderText() for contentful nodes (#3410)
- Loading branch information
Showing
2 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { generateText, Node, NodeConfig } from '@tiptap/core' | ||
import Document from '@tiptap/extension-document' | ||
import Paragraph from '@tiptap/extension-paragraph' | ||
import Text from '@tiptap/extension-text' | ||
|
||
describe(generateText.name, () => { | ||
it('generates Text from JSON without an editor instance', () => { | ||
const json = { | ||
type: 'doc', | ||
content: [{ | ||
type: 'paragraph', | ||
content: [ | ||
{ | ||
type: 'custom-node-default-renderer', | ||
content: [ | ||
{ | ||
type: 'text', | ||
text: 'Example One', | ||
}, | ||
], | ||
}, | ||
{ | ||
type: 'text', | ||
text: ' ', | ||
}, | ||
{ | ||
type: 'custom-node-custom-renderer', | ||
content: [ | ||
{ | ||
type: 'text', | ||
text: 'Example Two', | ||
}, | ||
], | ||
}, | ||
], | ||
}], | ||
} | ||
|
||
const contentfulInlineNode = (name: string, config?: Partial<NodeConfig>) => Node.create({ | ||
name, | ||
group: 'inline', | ||
inline: true, | ||
content: 'text*', | ||
parseHTML() { | ||
return [{ tag: name }] | ||
}, | ||
...config, | ||
}) | ||
|
||
const text = generateText(json, [ | ||
Document, | ||
Paragraph, | ||
Text, | ||
contentfulInlineNode('custom-node-default-renderer'), | ||
contentfulInlineNode('custom-node-custom-renderer', { | ||
renderText({ node }) { | ||
return `~${node.textContent}~` | ||
}, | ||
}), | ||
]) | ||
|
||
expect(text).to.eq('Example One ~Example Two~') | ||
}) | ||
}) |