Skip to content

Commit 2b477ee

Browse files
committed
fix(editor): add tiptap-text-direction extension to support RTL
Manual backport of f5c8768 as it seems to have been forgotten to get backported to stable31. Signed-off-by: Jonas <[email protected]>
1 parent 640d49b commit 2b477ee

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

src/css/prosemirror.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ div.ProseMirror {
282282
}
283283
}
284284

285+
li [dir="rtl"] {
286+
text-align: right;
287+
}
288+
289+
li [dir="ltr"] {
290+
text-align: left;
291+
}
292+
285293
ul, ol {
286294
padding-inline-start: 10px;
287295
margin-inline-start: 10px;

src/extensions/RichText.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import Table from './../nodes/Table.js'
4141
import TaskItem from './../nodes/TaskItem.js'
4242
import TaskList from './../nodes/TaskList.js'
4343
import Text from '@tiptap/extension-text'
44+
import TextDirection from './../extensions/TextDirection.ts'
4445
import TrailingNode from './../nodes/TrailingNode.js'
4546
/* eslint-enable import/no-named-as-default */
4647

@@ -113,6 +114,15 @@ export default Extension.create({
113114
}),
114115
LinkBubble,
115116
TrailingNode,
117+
TextDirection.configure({
118+
types: [
119+
'heading',
120+
'paragraph',
121+
'listItem',
122+
'taskItem',
123+
'blockquote',
124+
],
125+
}),
116126
]
117127
const additionalExtensionNames = this.options.extensions.map(e => e.name)
118128
return [

src/tests/tiptap.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ const renderedHTML = (markdown) => {
1616
describe('TipTap', () => {
1717
it('render softbreaks', () => {
1818
const markdown = 'This\nis\none\nparagraph'
19-
expect(renderedHTML(markdown)).toEqual(`<p>${markdown}</p>`)
19+
expect(renderedHTML(markdown)).toEqual(`<p dir="ltr">${markdown}</p>`)
2020
})
2121

2222
it('render hardbreak', () => {
2323
const markdown = 'Hard line break \nNext Paragraph'
24-
expect(renderedHTML(markdown)).toEqual('<p>Hard line break<br>Next Paragraph</p>')
24+
expect(renderedHTML(markdown)).toEqual('<p dir="ltr">Hard line break<br>Next Paragraph</p>')
2525
})
2626

2727
it('render taskList', () => {
2828
const markdown = '* [ ] item 1\n'
29-
expect(renderedHTML(markdown)).toEqual('<ul class="contains-task-list"><li data-checked="false" class="task-list-item checkbox-item"><input type="checkbox" class="" contenteditable="false"><label><p>item 1</p></label></li></ul>')
29+
expect(renderedHTML(markdown)).toEqual('<ul class="contains-task-list"><li dir="ltr" data-checked="false" class="task-list-item checkbox-item"><input type="checkbox" class="" contenteditable="false"><label><p dir="ltr">item 1</p></label></li></ul>')
3030
})
3131
})

0 commit comments

Comments
 (0)