Is there a way to inject the dir="auto" attribute to all p tags?
It would be nice if each paragraph's direction would automatically change based on the language in it.
Hey @GabrielKol,
I do not needed RTL support for my latest projects. Isn't that something you can do with CSS?
Hey @philippkuehn
I would like the direction to automatically change based on the language I'm using.
For example, if I start typing in Hebrew or Arabic, it would be presented from right to left,
but If I would press enter and on the next paragraph would type in English, then it would be presented from left to right.
It should automatically switch the direction based on the text's language.
It behaves this way in Gmail and Iv'e seen the same behavior in other editors such as Draft.js and Slate.js.
The only way I know of to implement this, is using the dir attribute on an html tag and setting it to "auto". So if I could give each p tag the dir="auto" attribute it would behave as I expect it to.
But I cannot figure out how to change the p tags in the editor.
Example from Gmail:

Okay, I'm not sure about implementing this by default. What you can do is to use a custom paragraph extension. Since it's a default extension you have to overwrite it.
import { setBlockType } from 'tiptap-commands'
import { Node } from 'tiptap'
export default class Paragraph extends Node {
get name() {
return 'paragraph'
}
get schema() {
return {
content: 'inline*',
group: 'block',
draggable: false,
parseDOM: [{
tag: 'p',
}],
toDOM: () => ['p', { dir: 'auto' }, 0],
}
}
commands({ type }) {
return () => setBlockType(type)
}
}
There is an option to disable the default extensions (useBuiltInExtensions). But you have to import Doc and Text.
import { Doc, Text } from 'tiptap'
import Paragraph from './CustomParagraph.js'
const editor = new Editor({
useBuiltInExtensions: false,
extensions: [
new Doc(), // default extension
new Text(), // default extension
new Paragraph(), // your custom extension
... // all other extensions
],
})
Thank you @philippkuehn
It works perfectly! :)
I still hope it gets implemented by default or activated through an option instead of making a custom paragraph plugin. Slate has it by default and it's a really great addition with almost no cost.
@philippkuehn At least 4% of the web is based on RTL languages. Could you please reconsider?
@philippkuehn Your amazing project is getting adopted by the mainstream since it is part of what Nextcloud is making, it only make sense to support the languages that has the opposite direction, all it needs is implementing dir="auto" in the tags p li h1 h2 h3 ... Not sure how hard it is to implement, but it is really really needed. And I have no idea how to use/implement the code you posted here in Nextcloud Text app.
I tried to add dir=auto but unfortunately I can't contribute directly to the project, since this is beyond my knowledge, all I know is HTML, CSS and a little bit of Javascript/jQuery and PHP.
@themedleb There're two ways to achieve that.
dir="auto", and it's the easiest. drawback: the direction is determined by the first character in the first child element, if it's an LTR character then that's the direction for the whole thing, and vice versa.@mrg0lden
the direction is determined by the first character in the first child element
I noticed that when I was playing with the HTML in the browser inspector.
re-implementing each text component of tiptap
That's how it should be done of course, yesterday I mentioned it in here https://github.com/nextcloud/text/issues/882#issuecomment-645190917, but I guess the developer is not caring much about it.
Most helpful comment
I still hope it gets implemented by default or activated through an option instead of making a custom paragraph plugin. Slate has it by default and it's a really great addition with almost no cost.