Skip to content

Commit

Permalink
Merge pull request #6874 from nextcloud/fix/882-add-rtl-support
Browse files Browse the repository at this point in the history
fix(files): add `tiptap-text-direction` extension to support RTL
  • Loading branch information
JuliaKirschenheuter authored Feb 14, 2025
2 parents 3440cac + 0f02d1f commit caded17
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"@tiptap/extension-collaboration-cursor": "^2.9.1",
"@tiptap/extension-document": "^2.9.1",
"@tiptap/extension-dropcursor": "^2.9.1",
"tiptap-text-direction": "^0.3.2",
"@tiptap/extension-gapcursor": "^2.9.1",
"@tiptap/extension-hard-break": "^2.9.1",
"@tiptap/extension-heading": "^2.9.1",
Expand Down
8 changes: 8 additions & 0 deletions src/css/prosemirror.scss
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ div.ProseMirror {
}
}

li [dir="rtl"] {
text-align: right;
}

li [dir="ltr"] {
text-align: left;
}

ul, ol {
padding-left: 10px;
margin-left: 10px;
Expand Down
4 changes: 4 additions & 0 deletions src/extensions/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import TaskItem from './../nodes/TaskItem.js'
import TaskList from './../nodes/TaskList.js'
import Text from '@tiptap/extension-text'
import TrailingNode from './../nodes/TrailingNode.js'
import TextDirection from 'tiptap-text-direction'
/* eslint-enable import/no-named-as-default */

import { Strong, Italic, Strike, Link, Underline } from './../marks/index.js'
Expand Down Expand Up @@ -111,6 +112,9 @@ export default Extension.create({
}),
LinkBubble,
TrailingNode,
TextDirection.configure({
types: ['heading', 'paragraph', 'listItem', 'orderedList'],
}),
]
const additionalExtensionNames = this.options.extensions.map(e => e.name)
return [
Expand Down
6 changes: 3 additions & 3 deletions src/tests/tiptap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ const renderedHTML = (markdown) => {
describe('TipTap', () => {
it('render softbreaks', () => {
const markdown = 'This\nis\none\nparagraph'
expect(renderedHTML(markdown)).toEqual(`<p>${markdown}</p>`)
expect(renderedHTML(markdown)).toEqual(`<p dir="ltr">${markdown}</p>`)
})

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

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

0 comments on commit caded17

Please sign in to comment.