I’ve been using DEVONthink for about two months and have been very happy with the experience.
I would like to ask about automatically formatting Markdown text in both the source and preview modes. Specifically, I want the text to be right-to-left (RTL) when writing in Arabic and left-to-right (LTR) when writing in English.
I’ve tried adding CSS code in the settings, but it didn’t work as expected—the text still appears left-to-right, as is showing in the below screenshot. Here’s the code I used:
If automatic text direction detection is not supported, how can I ensure that the text always appears right-to-left in the source mode?
I’ve also tested the issue in the DEVONthink 4 beta release, but unfortunately the same problem persists—Markdown text written in Arabic still defaults to left-to-right alignment in source mode , where the direction appears to be forcibly set and cannot be changed, regardless of the CSS settings.
Interestingly, this issue does not occur with RTF documents in DEVONthink.
I’d really appreciate any guidance or workaround for this. Thank you in advance!
This is not an answer, but a query. If you open the markdown document in an external editor that supports RTL languages, and later view that document in DEVONthink, is the text correctly displayed? Equally important, does search in DEVONthink find the text?
According to the W3C, you should set the dir attribute on the html element of the document. Which is not possible with an MD document, since the html element is added by the preview processor.
The same article expressly discourages using CSS for direction settings.
So, the more relevant question would be: what are the lang and the dir attributes in the resulting HTML? You can see that by converting the MD file to HTML in DT and then looking at its source (the HTML one’s, that is).
It might be possible to set the direction on the HTML element with a script like this one
Regarding your first question: I did try opening the document in the CotEditor app, which supports right-to-left editing (screenshot below), but when I opened the same document again in DEVONthink, I got the same result: Arabic text editing is left-to-right!
The answer to your second question:
Yes, text search in DEVONthink finds the text in this document.
Thanks again.
I’m afraid my post wasn’t clear enough. What I meant was not preview mode, but source mode. Preview mode works fine from right to left after I’ve used CSS in the preferences, but the problem is with source mode.
The code you sent only works in preview mode, which is what the CSS actually does. My problem occurs when I’m editing. It’s annoying when I’m writing from right to left, while the text alignment is left to right.
I understand now that the dir attribute should be set on the <html> element, and that this isn’t possible in Markdown directly, since the HTML structure is generated by the preview processor. I’ve also read the W3C guidance and understand why CSS alone isn’t enough.
However, my issue is not with the preview of the Markdown file. It displays correctly when using a custom stylesheet.
The problem I’m facing is with the source mode while writing Markdown inside DEVONthink. The text in that mode is always left-aligned and doesn’t follow the direction of the script (like Arabic). Since the source mode is a plain-text editor, I believe none of the HTML or scripting workarounds can affect it.
I’d really appreciate any suggestions.
Thanks again!
Thank you very much for your response and for pointing me to the Format > Alignment > Writing Direction option.
I already tried that in both versions 3 and 4. It works when I select some text and change its direction to RTL. But when I continue typing, the text goes back to LTR automatically.
The screenshot below shows this.
Thank you again for your help!