mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
Add GenerateText demo for React
This commit is contained in:
parent
152b0d328e
commit
d6286e5d5c
15
demos/src/GuideContent/GenerateText/React/index.html
Normal file
15
demos/src/GuideContent/GenerateText/React/index.html
Normal file
@ -0,0 +1,15 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module">
|
||||
import setup from "../../../../setup/react.ts";
|
||||
import source from "@source";
|
||||
setup("GuideContent/GenerateText", source);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
62
demos/src/GuideContent/GenerateText/React/index.jsx
Normal file
62
demos/src/GuideContent/GenerateText/React/index.jsx
Normal file
@ -0,0 +1,62 @@
|
||||
import React, { useMemo } from 'react'
|
||||
import { generateText } from '@tiptap/core'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import HardBreak from '@tiptap/extension-hard-break'
|
||||
|
||||
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',
|
||||
},
|
||||
)
|
||||
}, [json])
|
||||
|
||||
return (
|
||||
<pre>
|
||||
<code>{output}</code>
|
||||
</pre>
|
||||
)
|
||||
}
|
7
demos/src/GuideContent/GenerateText/React/index.spec.js
Normal file
7
demos/src/GuideContent/GenerateText/React/index.spec.js
Normal file
@ -0,0 +1,7 @@
|
||||
context('/src/GuideContent/GenerateText/React/', () => {
|
||||
before(() => {
|
||||
cy.visit('/src/GuideContent/GenerateText/React/')
|
||||
})
|
||||
|
||||
// TODO: Write tests
|
||||
})
|
Loading…
Reference in New Issue
Block a user