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:
|
build:
|
||||||
name: Build
|
name: Build
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
permissions:
|
||||||
matrix:
|
packages: write
|
||||||
arch: [amd64, arm64]
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Entire Repository
|
- name: Checkout Entire Repository
|
||||||
uses: actions/checkout@v4
|
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() {
|
render() {
|
||||||
this.wrapper = document.createElement('div')
|
this.wrapper = document.createElement('div')
|
||||||
this.wrapper.classList.add('cdx-block')
|
this.wrapper.classList.add('cdx-block')
|
||||||
@@ -36,10 +57,6 @@ export class Markdown {
|
|||||||
this.parseContent(event)
|
this.parseContent(event)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.wrapper.addEventListener('paste', (event) =>
|
|
||||||
this.handlePaste(event)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.wrapper
|
return this.wrapper
|
||||||
@@ -101,19 +118,6 @@ export class Markdown {
|
|||||||
this.api.caret.focus(true)
|
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) {
|
save(blockContent) {
|
||||||
return {
|
return {
|
||||||
text: blockContent.innerHTML,
|
text: blockContent.innerHTML,
|
||||||
|
|||||||
Reference in New Issue
Block a user