feat(content-rich html parsing): add paragraphs LTR/RTL direction support (#2545)

This commit is contained in:
Joaquín Sánchez 2024-03-05 07:25:58 +01:00 committed by GitHub
parent 6cbe65c9d8
commit 3120bbb77f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 188 additions and 15 deletions

View file

@ -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
}