-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(extensions): add text-direction extension #2963
Conversation
❌ Deploy Preview for tiptap-embed failed.
|
Sorry, I messed up my previous PR. I accidentally removed my fork, and all of my PRs got closed |
// eslint-disable-next-line no-misleading-character-class | ||
export const RTL_REGEX = new RegExp(`^[^${LTR}]*[${RTL}]`) | ||
|
||
// eslint-disable-next-line no-misleading-character-class | ||
export const LTR_REGEX = new RegExp(`^[^${RTL}]*[${LTR}]`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice I've disabled this rule here. I'm not sure about its impact on other plugins/collaborative editing.
### defaultDirection | ||
|
||
The default direction. | ||
|
||
:::warning | ||
If you specify a defaultDirection, the `dir` attribute will be excluded in nodes that have the same direction as the defaultDirection. | ||
::: | ||
|
||
Default: `null` | ||
|
||
```js | ||
TextDirection.configure({ | ||
defaultDirection: "rtl", | ||
}); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe "ignore" is a better name for that. The idea is that some apps are designed for a specific language, let's say Arabic, so it's not necessary to add dir="rtl" to every node because that's the default direction that is set in the html tag.
8a10848
to
3cf1786
Compare
@ahhshm feel free to make it your own package for now and post it to the discussions board! :) We'll discuss when we'll merge it. |
I published it as a separate package. Check it out if you want this feature: https://github.com/amirhhashemi/tiptap-text-direction
This plugin automatically adds
dir="ltr"
ordir="rtl"
to a specified list of nodes based on their content. Forcing a direction is also possible through thesetTextDirection
command. The direction detection logic comes from lexical.Why?
Why not? tiptap is one of the most popular rich text editors and it has been adopted for very large-scale applications. IMO it should have first-class support for RTL content. This plugin may not solve all of the issues with supporting both RTL and LTR content but definitely makes it easier.
Demo
2022-07-09.20-44-39.mp4
Example configuration:
editor.getHTML()
result:The
dir
attribute must be rendered instead of being a decorator (like text-align extention) because it's not just an in-editor thing. displaying and especially styling RTL content could be different than LTR content sodir
must be in the HTML output to clarify the direction for both browsers and developers.Why not
dir="auto"
?Mainly for more control. With
dir="auto"
we can't change the direction later and also styling would be harder (if RTL and LTR content have different styles)."Where to add
dir=" auto"
" is another challenging question. if we add it to an element that wraps the editor, the direction of the whole document would be determined by the first node. We can add it to each node but, again, we don't have any control over the direction.Why not a custom paragraph node?
headings and other text nodes also need it
Related issues
#116
#1621