Skip to content

Commit 57835b5

Browse files
fix(files): add tiptap-text-direction extension to support RTL
Signed-off-by: julia.kirschenheuter <julia.kirschenheuter@nextcloud.com>
1 parent a821e0c commit 57835b5

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

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.1.13",
6363
"@tiptap/extension-document": "^2.1.13",
6464
"@tiptap/extension-dropcursor": "^2.1.13",
65+
"tiptap-text-direction": "^0.3.2",
6566
"@tiptap/extension-gapcursor": "^2.1.13",
6667
"@tiptap/extension-hard-break": "^2.1.13",
6768
"@tiptap/extension-heading": "^2.1.13",

src/css/prosemirror.scss

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

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

src/extensions/RichText.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import TaskItem from './../nodes/TaskItem.js'
5555
import TaskList from './../nodes/TaskList.js'
5656
import Text from '@tiptap/extension-text'
5757
import TrailingNode from './../nodes/TrailingNode.js'
58+
import TextDirection from 'tiptap-text-direction'
5859
/* eslint-enable import/no-named-as-default */
5960

6061
import { Strong, Italic, Strike, Link, Underline } from './../marks/index.js'
@@ -121,6 +122,9 @@ export default Extension.create({
121122
})
122123
: null,
123124
TrailingNode,
125+
TextDirection.configure({
126+
types: ['heading', 'paragraph', 'listItem', 'orderedList'],
127+
}),
124128
]
125129
if (this.options.link !== false) {
126130
defaultExtensions.push(Link.configure({

src/tests/tiptap.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ 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
})

0 commit comments

Comments
 (0)