-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathindex.jsx
More file actions
104 lines (79 loc) · 3.06 KB
/
index.jsx
File metadata and controls
104 lines (79 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import Image from '@tiptap/extension-image'
import { TableKit } from '@tiptap/extension-table'
import { Markdown } from '@tiptap/markdown'
import { EditorContent, useEditor } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'
const markdown = `# Markdown parsing demo
This document demonstrates which Markdown constructs are parsed and preserved when using the @tiptap/markdown extension together with the editor's registered extensions.
## Headings
### H3 example
Headings (H1, H2, H3...) are preserved when ${'`'}StarterKit${'`'} is enabled.
## Lists
- Unordered list item A
- Unordered list item B
- Nested item B.1
1. Ordered item 1
2. Ordered item 2
## Code
Inline code works: ${'`'}const x = 1${'`'}
Code block example:
${'```'}js
function greet(name) {
return ${'`'}Hello, ${'${'}name${'}'}!${'`'}
}
${'```'}
## Table
| Name | Feature | Left Column | Center Column | Right Column |
| ---- | ------- | :---------- | :-----------: | -----------: |
| A | Headings |left|centered|$1,600|
| B | Lists |left|centered|$12|
| C | Markdown |left|centered|$1|
## Image (example)

## Notes
- The demo calls ${'`'}editor.commands.setContent(markdownText, { contentType: 'markdown' })${'`'} to parse Markdown.
- Supported constructs are preserved only if a matching extension is registered (e.g., tables require ${'`'}TableKit${'`'}, images require ${'`'}Image${'`'}).
- Unsupported constructs will be dropped/stripped from the resulting editor document.
Feel free to click "Parse Markdown" or upload a \`.md\` file to test parsing with your editor configuration.
`
export default () => {
const editor = useEditor({
extensions: [Markdown, StarterKit, Image, TableKit.configure({ table: { cellMinWidth: 150 } })],
content: `
<p>In this demo you can parse Markdown content into Tiptap on the client-side via <code>@tiptap/markdown</code>.</p>
<p>Click the button above or use your own markdown file to test it out.</p>
`,
})
return (
<>
<div class="control-group">
<div class="button-group">
<button onClick={() => editor.commands.setContent(markdown, { contentType: 'markdown' })}>
Parse Markdown
</button>
<input
type="file"
id="upload"
style={{ display: 'none' }}
fileaccept=".md,.markdown,text/markdown,text/md"
onChange={event => {
const file = event.target.files?.[0]
if (file) {
const reader = new FileReader()
reader.onload = e => {
const text = e.target?.result
if (typeof text === 'string') {
editor.commands.setContent(text, { contentType: 'markdown' })
}
}
reader.readAsText(file)
}
}}
/>
<button onClick={() => document.getElementById('upload')?.click()}>Select Markdown File</button>
</div>
</div>
<EditorContent editor={editor} />
</>
)
}