fix: update paragraph menu item task list error (#1330)

* fix: update paragraph menu item `task list` error

* Update exportStyleHTML api

* Update escapeText, because Safari do not support ?>! in reg
This commit is contained in:
Ran Luo 2019-09-11 11:33:25 +08:00 committed by GitHub
parent c52431cb92
commit a4f5269beb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View File

@ -157,7 +157,11 @@ const paragraphCtrl = ContentState => {
setTimeout(() => {
this.updateTaskListItem(listItemParagraph, listType)
this.partialRender()
this.muya.dispatchSelectionChange()
this.muya.dispatchSelectionFormats()
this.muya.dispatchChange()
})
return false
} else {
this.updateList(paragraph, listType, undefined, block)
}
@ -189,6 +193,8 @@ const paragraphCtrl = ContentState => {
})
}
}
return true
}
ContentState.prototype.handleLooseListItem = function () {
@ -447,6 +453,7 @@ const paragraphCtrl = ContentState => {
const { start, end } = this.cursor
const block = this.getBlock(start.key)
const { text } = block
let needDispatchChange = true
switch (paraType) {
case 'front-matter': {
@ -456,7 +463,7 @@ const paragraphCtrl = ContentState => {
case 'ul-bullet':
case 'ul-task':
case 'ol-order': {
this.handleListMenu(paraType, insertMode)
needDispatchChange = this.handleListMenu(paraType, insertMode)
break
}
case 'loose-list-item': {
@ -601,9 +608,11 @@ const paragraphCtrl = ContentState => {
this.partialRender()
}
this.muya.dispatchSelectionChange()
this.muya.dispatchSelectionFormats()
this.muya.dispatchChange()
if (needDispatchChange) {
this.muya.dispatchSelectionChange()
this.muya.dispatchSelectionFormats()
this.muya.dispatchChange()
}
}
ContentState.prototype.insertParagraph = function (location, text = '', outMost = false) {

View File

@ -139,9 +139,9 @@ class Muya {
return this.contentState.history.clearHistory()
}
exportStyledHTML (title = '', printOptimization = false) {
exportStyledHTML (title = '', printOptimization = false, extraCss = '') {
const { markdown } = this
return new ExportHtml(markdown, this).generate(title, printOptimization)
return new ExportHtml(markdown, this).generate(title, printOptimization, extraCss)
}
exportHtml () {

View File

@ -258,7 +258,7 @@ class ExportMarkdown {
const tHeader = table.children[0]
const tBody = table.children[1]
const escapeText = str => {
return str.replace(/(?<!\\)\|/g, '\\|')
return str.replace(/([^\\])\|/g, '$1\\|')
}
tableData.push(tHeader.children[0].children.map(th => escapeText(th.text).trim()))