mirror of
https://github.com/marktext/marktext.git
synced 2025-05-16 17:00:30 +08:00
feat: support copy rich text (#904)
* feat: support copy rich text * update changelog
This commit is contained in:
parent
6203eb2759
commit
ef59a74380
2
.github/CHANGELOG.md
vendored
2
.github/CHANGELOG.md
vendored
@ -61,6 +61,7 @@ foo<section>bar</section>zar
|
|||||||
- Hide titlebar control buttons in custom titlebar style
|
- Hide titlebar control buttons in custom titlebar style
|
||||||
- Corrected hamburger menu offset
|
- Corrected hamburger menu offset
|
||||||
- Optimization of inline html displa, now you can nest other inline syntax in inline html(#849)
|
- Optimization of inline html displa, now you can nest other inline syntax in inline html(#849)
|
||||||
|
- Use CmdOrCtrl + C/V to copy rich text to `word`(Windows) or `page`(macOS) (#885)
|
||||||
|
|
||||||
**:beetle:Bug fix**
|
**:beetle:Bug fix**
|
||||||
|
|
||||||
@ -115,6 +116,7 @@ foo<section>bar</section>zar
|
|||||||
- Fixed source code mode to preview switching
|
- Fixed source code mode to preview switching
|
||||||
- Mark Text didn't remove highlight when I delete the markdown symbol like * or `. (#893)
|
- Mark Text didn't remove highlight when I delete the markdown symbol like * or `. (#893)
|
||||||
- After delete ``` at the beginning to paragraph by backspace, then type other text foo, the color will be strange, if you type 1. bar. error happened. (#892)
|
- After delete ``` at the beginning to paragraph by backspace, then type other text foo, the color will be strange, if you type 1. bar. error happened. (#892)
|
||||||
|
- Fix highlight error in code block (#545 #890)
|
||||||
|
|
||||||
### 0.13.65
|
### 0.13.65
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import selection from '../selection'
|
|||||||
import { CLASS_OR_ID } from '../config'
|
import { CLASS_OR_ID } from '../config'
|
||||||
import { getSanitizeHtml } from '../utils/exportHtml'
|
import { getSanitizeHtml } from '../utils/exportHtml'
|
||||||
import ExportMarkdown from '../utils/exportMarkdown'
|
import ExportMarkdown from '../utils/exportMarkdown'
|
||||||
|
import marked from '../parser/marked'
|
||||||
|
|
||||||
const copyCutCtrl = ContentState => {
|
const copyCutCtrl = ContentState => {
|
||||||
ContentState.prototype.cutHandler = function () {
|
ContentState.prototype.cutHandler = function () {
|
||||||
@ -125,9 +126,9 @@ const copyCutCtrl = ContentState => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const htmlData = wrapper.innerHTML
|
let htmlData = wrapper.innerHTML
|
||||||
const textData = this.htmlToMarkdown(htmlData)
|
const textData = this.htmlToMarkdown(htmlData)
|
||||||
|
htmlData = marked(textData)
|
||||||
return { html: htmlData, text: textData }
|
return { html: htmlData, text: textData }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ const pasteCtrl = ContentState => {
|
|||||||
return this.pasteHandler(event, type)
|
return this.pasteHandler(event, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
const appendHtml = () => {
|
const appendHtml = (text) => {
|
||||||
startBlock.text = startBlock.text.substring(0, start.offset) + text + startBlock.text.substring(start.offset)
|
startBlock.text = startBlock.text.substring(0, start.offset) + text + startBlock.text.substring(start.offset)
|
||||||
const { key } = start
|
const { key } = start
|
||||||
const offset = start.offset + text.length
|
const offset = start.offset + text.length
|
||||||
@ -179,30 +179,67 @@ const pasteCtrl = ContentState => {
|
|||||||
|
|
||||||
// handle copyAsHtml
|
// handle copyAsHtml
|
||||||
if (copyType === 'copyAsHtml') {
|
if (copyType === 'copyAsHtml') {
|
||||||
|
// already handle code block above
|
||||||
|
if (startBlock.type === 'span' && startBlock.nextSibling) {
|
||||||
|
const afterParagraph = this.createBlock('p')
|
||||||
|
let temp = startBlock
|
||||||
|
const removeCache = []
|
||||||
|
while (temp.nextSibling) {
|
||||||
|
temp = this.getBlock(temp.nextSibling)
|
||||||
|
this.appendChild(afterParagraph, temp)
|
||||||
|
removeCache.push(temp)
|
||||||
|
}
|
||||||
|
removeCache.forEach(b => this.removeBlock(b))
|
||||||
|
this.insertAfter(afterParagraph, parent)
|
||||||
|
startBlock.nextSibling = null
|
||||||
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'normal': {
|
case 'normal': {
|
||||||
if (startBlock.type === 'span' && this.isOnlyChild(startBlock) && !startBlock.text) {
|
const htmlBlock = this.createBlock('p')
|
||||||
this.codeBlockUpdate(startBlock, text.trim(), 'html')
|
const lines = text.trim().split(LINE_BREAKS_REG).map(line => this.createBlock('span', line))
|
||||||
} else {
|
for (const line of lines) {
|
||||||
appendHtml()
|
this.appendChild(htmlBlock, line)
|
||||||
}
|
}
|
||||||
|
if (startBlock.type === 'span') {
|
||||||
|
this.insertAfter(htmlBlock, parent)
|
||||||
|
} else {
|
||||||
|
this.insertAfter(htmlBlock, startBlock)
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
startBlock.type === 'span' && startBlock.text.length === 0 && this.isOnlyChild(startBlock)
|
||||||
|
) {
|
||||||
|
this.removeBlock(parent)
|
||||||
|
}
|
||||||
|
// handler heading
|
||||||
|
if (startBlock.text.length === 0 && startBlock.type !== 'span') {
|
||||||
|
this.removeBlock(startBlock)
|
||||||
|
}
|
||||||
|
this.insertHtmlBlock(htmlBlock)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'pasteAsPlainText': {
|
case 'pasteAsPlainText': {
|
||||||
if (startBlock.type === 'span') {
|
const lines = text.trim().split(LINE_BREAKS_REG)
|
||||||
const lines = text.trim().split(LINE_BREAKS_REG).map(line => this.createBlock('span', line))
|
let htmlBlock = null
|
||||||
for (const line of lines) {
|
|
||||||
this.appendChild(parent, line)
|
if (!startBlock.text || lines.length > 1) {
|
||||||
}
|
htmlBlock = this.createBlock('p')
|
||||||
const lastLine = lines[lines.length - 1]
|
;(startBlock.text ? lines.slice(1) : lines).map(line => this.createBlock('span', line))
|
||||||
const { key } = lastLine
|
.forEach(l => {
|
||||||
const offset = lastLine.text.length
|
this.appendChild(htmlBlock, l)
|
||||||
this.cursor = {
|
})
|
||||||
start: { key, offset },
|
}
|
||||||
end: { key, offset }
|
if (htmlBlock) {
|
||||||
|
if (startBlock.type === 'span') {
|
||||||
|
this.insertAfter(htmlBlock, parent)
|
||||||
|
} else {
|
||||||
|
this.insertAfter(htmlBlock, startBlock)
|
||||||
}
|
}
|
||||||
|
this.insertHtmlBlock(htmlBlock)
|
||||||
|
}
|
||||||
|
if (startBlock.text) {
|
||||||
|
appendHtml(lines[0])
|
||||||
} else {
|
} else {
|
||||||
appendHtml()
|
this.removeBlock(startBlock.type === 'span' ? parent : startBlock)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user