Add GenerateJSON demo for React

This commit is contained in:
svenadlung 2021-11-16 20:32:38 +01:00
parent d6286e5d5c
commit d8ce6fdafd
3 changed files with 51 additions and 0 deletions

View 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/GenerateJSON", source);
</script>
</body>
</html>

View File

@ -0,0 +1,29 @@
import React, { useMemo } from 'react'
// Option 1: Browser + server-side
import { generateJSON } from '@tiptap/html'
// Option 2: Browser-only (lightweight)
// import { generateJSON } from '@tiptap/core'
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import Bold from '@tiptap/extension-bold'
const html = '<p>Example <strong>Text</strong></p>'
export default () => {
const output = useMemo(() => {
return generateJSON(html, [
Document,
Paragraph,
Text,
Bold,
// other extensions
])
}, [html])
return (
<pre>
<code>{JSON.stringify(output, null, 2)}</code>
</pre>
)
}

View File

@ -0,0 +1,7 @@
context('/src/GuideContent/GenerateJSON/React/', () => {
before(() => {
cy.visit('/src/GuideContent/GenerateJSON/React/')
})
// TODO: Write tests
})