When iframe code is pasted, inject it into the editor
This commit is contained in:
parent
3a8968bdf1
commit
41a78ea09c
|
@ -99,9 +99,6 @@ function RichEditContract(props: { contract: Contract; isAdmin?: boolean }) {
|
|||
.setContent(contract.description)
|
||||
.focus('end')
|
||||
.insertContent(`<p>${editTimestamp()}</p>`)
|
||||
.insertContent(
|
||||
`<iframe src="https://manifold.markets/embed/Austin/how-many-upvotes-will-the-new-versi" frameborder="0"></iframe>`
|
||||
)
|
||||
.run()
|
||||
}}
|
||||
>
|
||||
|
|
|
@ -71,12 +71,20 @@ export function useTextEditor(props: {
|
|||
(file) => file.type.startsWith('image')
|
||||
)
|
||||
|
||||
if (!imageFiles.length) {
|
||||
return // if no files pasted, use default paste handler
|
||||
}
|
||||
|
||||
if (imageFiles.length) {
|
||||
event.preventDefault()
|
||||
upload.mutate(imageFiles)
|
||||
}
|
||||
|
||||
// If the pasted content is iframe code, directly inject it
|
||||
const text = event.clipboardData?.getData('text/plain').trim() ?? ''
|
||||
const isValidIframe = /^<iframe.*<\/iframe>$/.test(text)
|
||||
if (isValidIframe) {
|
||||
editor.chain().insertContent(text).run()
|
||||
return true // Prevent the code from getting pasted as text
|
||||
}
|
||||
|
||||
return // Otherwise, use default paste handler
|
||||
},
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user