Merge pull request #1206 from pateljannat/issues-57
fix: markdown embed and paste issue
This commit is contained in:
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -10,9 +10,9 @@ jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
arch: [amd64, arm64]
|
||||
permissions:
|
||||
packages: write
|
||||
|
||||
steps:
|
||||
- name: Checkout Entire Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
@@ -18,6 +18,27 @@ export class Markdown {
|
||||
}
|
||||
}
|
||||
|
||||
onPaste(event) {
|
||||
const data = {
|
||||
text: event.detail.data.innerHTML,
|
||||
}
|
||||
|
||||
this.data = data
|
||||
|
||||
window.requestAnimationFrame(() => {
|
||||
if (!this.wrapper) {
|
||||
return
|
||||
}
|
||||
this.wrapper.innerHTML = this.data.text || ''
|
||||
})
|
||||
}
|
||||
|
||||
static get pasteConfig() {
|
||||
return {
|
||||
tags: ['P'],
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
this.wrapper = document.createElement('div')
|
||||
this.wrapper.classList.add('cdx-block')
|
||||
@@ -36,10 +57,6 @@ export class Markdown {
|
||||
this.parseContent(event)
|
||||
}
|
||||
})
|
||||
|
||||
this.wrapper.addEventListener('paste', (event) =>
|
||||
this.handlePaste(event)
|
||||
)
|
||||
}
|
||||
|
||||
return this.wrapper
|
||||
@@ -101,19 +118,6 @@ export class Markdown {
|
||||
this.api.caret.focus(true)
|
||||
}
|
||||
|
||||
handlePaste(event) {
|
||||
event.preventDefault()
|
||||
|
||||
const clipboardData = event.clipboardData || window.clipboardData
|
||||
const pastedText = clipboardData.getData('text/plain')
|
||||
const sanitizedText = this.processPastedContent(pastedText)
|
||||
document.execCommand('insertText', false, sanitizedText)
|
||||
}
|
||||
|
||||
processPastedContent(text) {
|
||||
return text.trim()
|
||||
}
|
||||
|
||||
save(blockContent) {
|
||||
return {
|
||||
text: blockContent.innerHTML,
|
||||
|
||||
Reference in New Issue
Block a user