feat(content-rich html parsing): add paragraphs LTR/RTL direction support (#2545)
This commit is contained in:
parent
6cbe65c9d8
commit
3120bbb77f
4 changed files with 188 additions and 15 deletions
|
@ -524,10 +524,21 @@ function transformMarkdown(node: Node) {
|
|||
return _markdownProcess(node.value)
|
||||
}
|
||||
|
||||
function addBdiParagraphs(node: Node) {
|
||||
if (node.name === 'p' && !('dir' in node.attributes) && node.children?.length && node.children.length > 1)
|
||||
node.attributes.dir = 'auto'
|
||||
|
||||
return node
|
||||
}
|
||||
|
||||
function transformParagraphs(node: Node): Node | Node[] {
|
||||
// Add bdi to paragraphs
|
||||
addBdiParagraphs(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…
Add table
Add a link
Reference in a new issue