Skip to content

Commit f9bad7e

Browse files
JuliaKirschenheuterjuliusknorr
authored andcommitted
fix(files): add tiptap-text-direction extension to support RTL
Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com>
1 parent 3815bc7 commit f9bad7e

5 files changed

Lines changed: 33 additions & 3 deletions

File tree

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"@tiptap/extension-collaboration-cursor": "^2.3.2",
6363
"@tiptap/extension-document": "^2.3.2",
6464
"@tiptap/extension-dropcursor": "^2.3.2",
65+
"tiptap-text-direction": "^0.3.2",
6566
"@tiptap/extension-gapcursor": "^2.3.2",
6667
"@tiptap/extension-hard-break": "^2.3.2",
6768
"@tiptap/extension-heading": "^2.3.2",

src/css/prosemirror.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,14 @@ div.ProseMirror {
277277
}
278278
}
279279

280+
li [dir="rtl"] {
281+
text-align: right;
282+
}
283+
284+
li [dir="ltr"] {
285+
text-align: left;
286+
}
287+
280288
ul, ol {
281289
padding-left: 10px;
282290
margin-left: 10px;

src/extensions/RichText.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import TaskItem from './../nodes/TaskItem.js'
5757
import TaskList from './../nodes/TaskList.js'
5858
import Text from '@tiptap/extension-text'
5959
import TrailingNode from './../nodes/TrailingNode.js'
60+
import TextDirection from 'tiptap-text-direction'
6061
/* eslint-enable import/no-named-as-default */
6162

6263
import { Strong, Italic, Strike, Link, Underline } from './../marks/index.js'
@@ -132,6 +133,9 @@ export default Extension.create({
132133
})
133134
: null,
134135
TrailingNode,
136+
TextDirection.configure({
137+
types: ['heading', 'paragraph', 'listItem', 'orderedList'],
138+
}),
135139
]
136140
const additionalExtensionNames = this.options.extensions.map(e => e.name)
137141
return [

src/tests/tiptap.spec.js

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

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

2424
it('render taskList', () => {
2525
const markdown = '* [ ] item 1\n'
26-
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>')
26+
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 dir="ltr">item 1</p></label></li></ul>')
2727
})
2828
})

0 commit comments

Comments
 (0)