RTL Support

What do you mean by writing RTL words inside LTR sentences? If I guess correctly, it already supports it.

1 Like

I’d like to mention that usually people who write in RTL languages need a bidirectional environment as it’s common to have notes with paragraphs both in RTL/LTR. A common use case is taking notes on programming languages where the descriptions are in RTL while the code snippets are in English/LTR. A great implementation of bidirectional editor is Paper by dropbox where it can detect the first character of each paragraph and change the direction based on that.

9 Likes

I completely +1 this request, but with one important comment. Please don’t follow the mistake of some other apps (Zettlr, Mark Text), don’t make RTL a general app setting.
We who write RTL want some notes in English and some in Hebrew/Arabic/Farsi. We don’t want the entire app RTL – just some RTL notes. It has to be either auto-detected by paragraph (which is the common solution in most GUIs) or a per-note setting.

9 Likes

A quick search shows that CodeMirror has nice RTL support: https://codemirror.net/demo/bidi.html
If Obsidian can add a similar command, that can be mapped to a keyboard shortcut, to switch between LTR/RTL for a specific note, it’ll be amazing.

8 Likes

Any update from the obsidian team on this? is this something you consider working on?

5 Likes

Until we either get formal RTL support or the formal plugin API, here’s a hacky Volcano plugin for RTL/LTR switching.
It adds a global command “Switch Document Direction” which can be mapped to a key.
It’s probably not perfect and there’s plenty of room for improvement, but maybe it will be useful for some.
(to be saved as rtl.js under ~/volcano/plugins after installing Volcano)

class RTLPlugin {
	constructor() {
		this.id = 'rtl'
		this.name = 'RTL plugin'
		this.description = 'RTL support for Obsidian.'
		this.defaultOn = true // Whether or not to enable the plugin on load
	}
	
	init(app, instance) {
		console.log('RTL plugin is initializing!')
		this.app = app
		this.instance = instance
		this.enabled = false

		this.instance.registerGlobalCommand({
			id: 'switch_direction',
			name: 'Switch Document Direction',
			callback: () => this.switchDocumentDirection()
		})
	}

	onEnable(app, instance) {
		console.log('RTL support is now enabled')
		this.enabled = true
	}

	onDisable(app, instance) {
		console.log('RTL support is now disabled')
		this.enabled = false
	}

	switchDocumentDirection() {
		if (this.enabled) {
			var cmEditor = this.app.workspace.activeLeaf.view.currentMode.cmEditor
			if (cmEditor) {
				var newDirection = cmEditor.getOption("direction") == "ltr" ? "rtl" : "ltr"
				cmEditor.setOption("direction", newDirection)
			}
		}
	}
}

module.exports = () => new RTLPlugin()

4 Likes

+1 I wish for this to be implemented

Thanks for the solution. But it just move text to the right and doesn’t work for Persian English text.

1 Like

I thought of dropping a note here, that I posted a proper RTL support plugin to the Obsidian Third-party plugins.
This includes the real deal of setting RTL paragraph direction to all or just some notes in the Markdown editor mode (didn’t do preview yet).

8 Likes

Is there a way to add in this plugin a capability to RTL only one paragraph instead of the whole note?

4 Likes

I wish, but CodeMirror (the component behind Obsidian’s editor) can only set the direction for the whole document.

2 Likes

+1 for RTL support (mixed English/Other languages)
Really needed

3 Likes

Thanks for the plugin.
please make RTL for Preview mode as well.

1 Like

Will do, as it’s a very requested feature.

3 Likes

You are a true gold!

2 Likes

I published a new version 0.0.3 with preview mode RTL support, please upgrade and let me know how it works for you.

2 Likes

This is just great! THANK YOU!

One question: When exporting to pdf the text is still LTR, is there something I need to do in order to fix it or is it a known issue?

Thanks again!

1 Like

It should be pretty easy for the author to target print, which has class .print.

@esm90: great work you’re doing here! Have you considered opening a share & showcase thread if you haven’t? You can gather feedback and post updates there.

Otherwise, I think people are also discovering it by searching for “RTL” in third-party plugins.

2 Likes

@dorongol seems like it’s an area I didn’t cover yet. It should be easy enough, I’ll address that next time I have a few minutes to work on the plugin. You’re also very welcome to open a PR in the plugin Github repo if you’re up to it :slight_smile:
@Silver thanks for the tip, I didn’t think about it. If it’s gonna help users to discover the RTL support I’ll surely open a share & showcase thread.

4 Likes

I added Export support in the latest version, please give it a go and let me know if it works as expected.

5 Likes