mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
Add GenerateJSON demo for React
This commit is contained in:
parent
d6286e5d5c
commit
d8ce6fdafd
15
demos/src/GuideContent/GenerateJSON/React/index.html
Normal file
15
demos/src/GuideContent/GenerateJSON/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/GenerateJSON", source);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
29
demos/src/GuideContent/GenerateJSON/React/index.jsx
Normal file
29
demos/src/GuideContent/GenerateJSON/React/index.jsx
Normal 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>
|
||||
)
|
||||
}
|
7
demos/src/GuideContent/GenerateJSON/React/index.spec.js
Normal file
7
demos/src/GuideContent/GenerateJSON/React/index.spec.js
Normal file
@ -0,0 +1,7 @@
|
||||
context('/src/GuideContent/GenerateJSON/React/', () => {
|
||||
before(() => {
|
||||
cy.visit('/src/GuideContent/GenerateJSON/React/')
|
||||
})
|
||||
|
||||
// TODO: Write tests
|
||||
})
|
Loading…
Reference in New Issue
Block a user