Add GenerateHTML demo for React
This commit is contained in:
15
demos/src/GuideContent/GenerateHTML/React/index.html
Normal file
15
demos/src/GuideContent/GenerateHTML/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/GenerateHTML", source);
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
51
demos/src/GuideContent/GenerateHTML/React/index.jsx
Normal file
51
demos/src/GuideContent/GenerateHTML/React/index.jsx
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import React, { useMemo } from 'react'
|
||||||
|
// Option 1: Browser + server-side
|
||||||
|
import { generateHTML } from '@tiptap/html'
|
||||||
|
// Option 2: Browser-only (lightweight)
|
||||||
|
// import { generateHTML } 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 json = {
|
||||||
|
type: 'doc',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'paragraph',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
text: 'Example ',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'text',
|
||||||
|
marks: [
|
||||||
|
{
|
||||||
|
type: 'bold',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
text: 'Text',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
export default () => {
|
||||||
|
const output = useMemo(() => {
|
||||||
|
return generateHTML(json, [
|
||||||
|
Document,
|
||||||
|
Paragraph,
|
||||||
|
Text,
|
||||||
|
Bold,
|
||||||
|
// other extensions …
|
||||||
|
])
|
||||||
|
}, [json])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<pre>
|
||||||
|
<code>{output}</code>
|
||||||
|
</pre>
|
||||||
|
)
|
||||||
|
}
|
||||||
7
demos/src/GuideContent/GenerateHTML/React/index.spec.js
Normal file
7
demos/src/GuideContent/GenerateHTML/React/index.spec.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
context('/src/GuideContent/GenerateHTML/React/', () => {
|
||||||
|
before(() => {
|
||||||
|
cy.visit('/src/GuideContent/GenerateHTML/React/')
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO: Write tests
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user