mirror of
https://github.com/marktext/marktext.git
synced 2025-05-21 11:20:54 +08:00
fix: empty blockquote issue (#1739)
This commit is contained in:
parent
fb8fca7b50
commit
1d69461502
@ -80,6 +80,7 @@ const importRegister = ContentState => {
|
|||||||
|
|
||||||
const { trimUnnecessaryCodeBlockEmptyLines, footnote } = this.muya.options
|
const { trimUnnecessaryCodeBlockEmptyLines, footnote } = this.muya.options
|
||||||
const tokens = new Lexer({ disableInline: true, footnote }).lex(markdown)
|
const tokens = new Lexer({ disableInline: true, footnote }).lex(markdown)
|
||||||
|
|
||||||
let token
|
let token
|
||||||
let block
|
let block
|
||||||
let value
|
let value
|
||||||
@ -114,6 +115,7 @@ const importRegister = ContentState => {
|
|||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'hr': {
|
case 'hr': {
|
||||||
value = token.marker
|
value = token.marker
|
||||||
block = this.createBlock('hr')
|
block = this.createBlock('hr')
|
||||||
@ -125,6 +127,7 @@ const importRegister = ContentState => {
|
|||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'heading': {
|
case 'heading': {
|
||||||
const { headingStyle, depth, text, marker } = token
|
const { headingStyle, depth, text, marker } = token
|
||||||
value = headingStyle === 'atx' ? '#'.repeat(+depth) + ` ${text}` : text
|
value = headingStyle === 'atx' ? '#'.repeat(+depth) + ` ${text}` : text
|
||||||
@ -146,12 +149,14 @@ const importRegister = ContentState => {
|
|||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'multiplemath': {
|
case 'multiplemath': {
|
||||||
value = token.text
|
value = token.text
|
||||||
block = this.createContainerBlock(token.type, value)
|
block = this.createContainerBlock(token.type, value)
|
||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'code': {
|
case 'code': {
|
||||||
const { codeBlockStyle, text, lang: infostring = '' } = token
|
const { codeBlockStyle, text, lang: infostring = '' } = token
|
||||||
|
|
||||||
@ -209,6 +214,7 @@ const importRegister = ContentState => {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'table': {
|
case 'table': {
|
||||||
const { header, align, cells } = token
|
const { header, align, cells } = token
|
||||||
const table = this.createBlock('table')
|
const table = this.createBlock('table')
|
||||||
@ -270,6 +276,7 @@ const importRegister = ContentState => {
|
|||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'html': {
|
case 'html': {
|
||||||
const text = token.text.trim()
|
const text = token.text.trim()
|
||||||
// TODO: Treat html block which only contains one img as paragraph, we maybe add image block in the future.
|
// TODO: Treat html block which only contains one img as paragraph, we maybe add image block in the future.
|
||||||
@ -287,6 +294,7 @@ const importRegister = ContentState => {
|
|||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'text': {
|
case 'text': {
|
||||||
value = token.text
|
value = token.text
|
||||||
while (tokens[0].type === 'text') {
|
while (tokens[0].type === 'text') {
|
||||||
@ -301,6 +309,7 @@ const importRegister = ContentState => {
|
|||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'paragraph': {
|
case 'paragraph': {
|
||||||
value = token.text
|
value = token.text
|
||||||
block = this.createBlock('p')
|
block = this.createBlock('p')
|
||||||
@ -311,16 +320,24 @@ const importRegister = ContentState => {
|
|||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'blockquote_start': {
|
case 'blockquote_start': {
|
||||||
block = this.createBlock('blockquote')
|
block = this.createBlock('blockquote')
|
||||||
this.appendChild(parentList[0], block)
|
this.appendChild(parentList[0], block)
|
||||||
parentList.unshift(block)
|
parentList.unshift(block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'blockquote_end': {
|
case 'blockquote_end': {
|
||||||
|
// Fix #1735 the blockquote maybe empty.
|
||||||
|
if (parentList[0].children.length === 0) {
|
||||||
|
const paragraphBlock = this.createBlockP()
|
||||||
|
this.appendChild(parentList[0], paragraphBlock)
|
||||||
|
}
|
||||||
parentList.shift()
|
parentList.shift()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'footnote_start': {
|
case 'footnote_start': {
|
||||||
block = this.createBlock('figure', {
|
block = this.createBlock('figure', {
|
||||||
functionType: 'footnote'
|
functionType: 'footnote'
|
||||||
@ -334,10 +351,12 @@ const importRegister = ContentState => {
|
|||||||
parentList.unshift(block)
|
parentList.unshift(block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'footnote_end': {
|
case 'footnote_end': {
|
||||||
parentList.shift()
|
parentList.shift()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'list_start': {
|
case 'list_start': {
|
||||||
const { ordered, listType, start } = token
|
const { ordered, listType, start } = token
|
||||||
block = this.createBlock(ordered === true ? 'ol' : 'ul')
|
block = this.createBlock(ordered === true ? 'ol' : 'ul')
|
||||||
@ -349,10 +368,12 @@ const importRegister = ContentState => {
|
|||||||
parentList.unshift(block)
|
parentList.unshift(block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'list_end': {
|
case 'list_end': {
|
||||||
parentList.shift()
|
parentList.shift()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'loose_item_start':
|
case 'loose_item_start':
|
||||||
case 'list_item_start': {
|
case 'list_item_start': {
|
||||||
const { listItemType, bulletMarkerOrDelimiter, checked, type } = token
|
const { listItemType, bulletMarkerOrDelimiter, checked, type } = token
|
||||||
@ -373,13 +394,16 @@ const importRegister = ContentState => {
|
|||||||
parentList.unshift(block)
|
parentList.unshift(block)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'list_item_end': {
|
case 'list_item_end': {
|
||||||
parentList.shift()
|
parentList.shift()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'space': {
|
case 'space': {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
console.warn(`Unknown type ${token.type}`)
|
console.warn(`Unknown type ${token.type}`)
|
||||||
break
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user