Skip to content

Commit 8d7bd81

Browse files
authored
Merge pull request #6904 from nextcloud/backport/6874/stable30
[stable30] fix(files): add `tiptap-text-direction` extension to support RTL
2 parents 0f68119 + f5c8768 commit 8d7bd81

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
@@ -61,6 +61,7 @@
6161
"@tiptap/extension-collaboration-cursor": "^2.9.1",
6262
"@tiptap/extension-document": "^2.9.1",
6363
"@tiptap/extension-dropcursor": "^2.9.1",
64+
"tiptap-text-direction": "^0.3.2",
6465
"@tiptap/extension-gapcursor": "^2.9.1",
6566
"@tiptap/extension-hard-break": "^2.9.1",
6667
"@tiptap/extension-heading": "^2.9.1",

src/css/prosemirror.scss

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

287+
li [dir="rtl"] {
288+
text-align: right;
289+
}
290+
291+
li [dir="ltr"] {
292+
text-align: left;
293+
}
294+
287295
ul, ol {
288296
padding-left: 10px;
289297
margin-left: 10px;

src/extensions/RichText.js

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

4647
import { Strong, Italic, Strike, Link, Underline } from './../marks/index.js'
@@ -115,6 +116,9 @@ export default Extension.create({
115116
})
116117
: null,
117118
TrailingNode,
119+
TextDirection.configure({
120+
types: ['heading', 'paragraph', 'listItem', 'orderedList'],
121+
}),
118122
]
119123
const additionalExtensionNames = this.options.extensions.map(e => e.name)
120124
return [

src/tests/tiptap.spec.js

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

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

2929
it('render taskList', () => {
3030
const markdown = '* [ ] item 1\n'
31-
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>')
31+
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>')
3232
})
3333
})

0 commit comments

Comments
 (0)