tiptap/demos/src/GuideContent/GenerateText/React/index.jsx
Nick Perez 6a53bb2699
Some checks failed
build / build (20) (push) Has been cancelled
Publish / Release (20) (push) Has been cancelled
build / test (20, map[name:Demos/Commands spec:./demos/src/Commands/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Examples spec:./demos/src/Examples/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Experiments spec:./demos/src/Experiments/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Extensions spec:./demos/src/Extensions/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/GuideContent spec:./demos/src/GuideContent/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/GuideGettingStarted spec:./demos/src/GuideGettingStarted/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Marks spec:./demos/src/Marks/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Demos/Nodes spec:./demos/src/Nodes/**/*.spec.{js,ts}]) (push) Has been cancelled
build / test (20, map[name:Integration spec:./tests/cypress/integration/**/*.spec.{js,ts}]) (push) Has been cancelled
build / release (20) (push) Has been cancelled
feat(static-renderer): add @tiptap/static-renderer to enable static rendering of content (#5528)
2025-01-06 14:00:38 +01:00

63 lines
1.2 KiB
JavaScript

import { generateText } from '@tiptap/core'
import Document from '@tiptap/extension-document'
import HardBreak from '@tiptap/extension-hard-break'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import React, { useMemo } from 'react'
const json = {
type: 'doc',
content: [
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'This is a paragraph.',
},
],
},
{
type: 'paragraph',
content: [
{
type: 'text',
text: 'Here is another paragraph …',
},
{
type: 'hardBreak',
},
{
type: 'text',
text: '… with an hard break.',
},
],
},
],
}
export default () => {
const output = useMemo(() => {
return generateText(
json,
[
Document,
Paragraph,
Text,
HardBreak,
// other extensions …
],
{
// define a custom block separator if you want to
blockSeparator: '\n\n',
},
)
}, [])
return (
<pre>
<code>{output}</code>
</pre>
)
}