fix: preserve paragraphs when editing a status
This commit is contained in:
parent
1817afdb23
commit
3dc20ea2f9
@ -1,7 +1,7 @@
|
||||
// @unimport-disable
|
||||
import type { Emoji } from 'masto'
|
||||
import type { Node } from 'ultrahtml'
|
||||
import { ELEMENT_NODE, TEXT_NODE, h, parse, render } from 'ultrahtml'
|
||||
import { DOCUMENT_NODE, ELEMENT_NODE, TEXT_NODE, h, parse, render } from 'ultrahtml'
|
||||
import { findAndReplaceEmojisInText } from '@iconify/utils'
|
||||
import { emojiRegEx, getEmojiAttributes } from '../config/emojis'
|
||||
|
||||
@ -79,6 +79,8 @@ export function parseMastodonHTML(
|
||||
|
||||
transforms.push(replaceCustomEmoji(options.emojis || {}))
|
||||
|
||||
transforms.push(transformParagraphs)
|
||||
|
||||
return transformSync(parse(html), transforms)
|
||||
}
|
||||
|
||||
@ -349,3 +351,10 @@ function transformMarkdown(node: Node) {
|
||||
return node
|
||||
return _markdownProcess(node.value)
|
||||
}
|
||||
|
||||
function transformParagraphs(node: Node): Node | Node[] {
|
||||
// For top level paragraphs, inject an empty <p> to preserve status paragraphs in our editor (except for the last one)
|
||||
if (node.parent?.type === DOCUMENT_NODE && node.name === 'p' && node.parent.children.at(-1) !== node)
|
||||
return [node, h('p')]
|
||||
return node
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user