Introducing Orgmode CM6, my first obsidian plugin that allows to view/edit orgmode files (*.org), as opposed to markdown files (*.md). I am using it on desktop for my orgmode files coming from my phone with orgzly.
I was previously using obsidian-org-mode and wanted to customize the experience with some JS/CSS but was frustrated that it was using code mirror 5 like the legacy editor (feature removed in obsidian 1.5) and not code mirror 6 like current obsidian. So I wrote this plugin from scratch to do just that (CM6 is for code mirror 6), and a little more:
The syntax highlighting is not based on regexes but on a custom lezer grammar so it is much more accurate, even though not all orgmode syntax is implemented.
There are CSS classes to customize the syntax highlighting.
You can define your own todo/done keywords for the syntax highlighting.
Still not a fully-featured orgmode editor, but I hope it can be useful.
I would love to have your feedback about the plugin. I am also curious to know more about your orgmode/obsidian workflows, if you are into that.
I was hoping that someone would be brave enough to do this. Thank you so very much!
I’ll try out the plugin this weekend.
Initially when I was at least contemplating the idea of doing it myself, I looked at Lezer (nice idea like tree-sitter), but then I saw that CM6’s markdown mode was NOT done with lezer, I think due to its flexibility which supports a.o. embedded code blocks that also need to be correctly parsed. Does your parser support code blocks?
By CM6’s markdown mode, are you talking about @codemirror/lang-markdown which uses @lezer/markdown? It was done with lezer, just not using a grammar file. Markdown and Orgmode are similar in that their grammars are not context-free and cannot be expressed as a LR parser, but there are ways to implement them with Lezer.
My parser relies on external tokens. It doesn’t currently support code blocks, but there is no fundamental reason it couldn’t be implemented. CodeMirror and Lezer call this feature Mixed-Language Parsing.
Is that a feature you would be interested to use, or do you just want to know what is possible?
This plugin was not implemented on mobile. I never tried it on iOS but I tried it once on android and it didn’t work.
I am guessing some configuration is needed to make obsidian handle *.org files.
Since I don’t use obsidian on mobile, I didn’t look at how to make it work.
Vim mode was accidentally enabled, causing the editor to misbehave (if you don’t expect vim).
Someone opened an issue on github about it and that’s how I discovered it.
Vim mode now follows the obsidian vim setting (restart obsidian if you decide to change the obsidian vim setting).
I don’t have an iPhone to test it but yes it should work.
You have to tap on the left margin (the gutter) on the line of the heading, if the heading doesn’t contain any section or nested headings you cannot fold it. The fold marker is only visible after the heading is folded.
Can you tell me what are org roam ID: links? I don’t know org roam.
oh wow you’re right - it does work! a quick observation and suggestion:
(observation)
when I first open an org file with foldable content, there are no visual cues that it can fold (hence my question). However - when I click the empty margin, the content folds, and I get the “folded” icon in the margin. when I click the “folded” icon, the content then unfolds, and I get an “unfolded” icon.
(suggestion)
when an org file with foldable content loads - could it show the “unfolded” icon already?
re: ID links, they actually have nothing to do with roam, they are the fundamental org link structure:
:PROPERTIES:
:ID: abc
:END:
[[id:abc][My Link to Node abc]]
When the properties start the file, the ID is for the file itself and the link is to the file.
You can also of course add an ID property to any node, and link there directly, and link relatively to any child of an IDentified node using the :: syntax - but I’ll settle for just the first part for now!
I mentioned org-roam merely because that’s sometimes how ID links are created, but certainly not the only way.
I want to be consistent with obsidian for the foldable content. Looking again I see that I missed that the fold icon is always visible in obsidian when the cursor is inside the heading line. I believe it should solve the discoverability problem.
Concerning ID links, thank you for opening an issue about it. We can continue the discussion on github.