How to create custom CodeMirror block widget?

Dear fellow Obsidianers,

I’m working on my first (non-toy) plugin…

Is there a way to create a custom block (not inline) widget in Obsidian’s CodeMirror v6, as documented here?

I get the following error:

RangeError: Decorations that replace line breaks may not be specified via plugins

I guess this is a restriction due to Obsidian’s implementation details, and there is no reasonable workaround. Or is there?

I know about createCodeBlockPostProcessor, which can be used to show block HTML elements, but I don’t want to be restricted to markdown code fences. Also, I don’t want to use registerMarkdownPostProcessor to show the widget only in preview mode. I want it to work in edit / live preview mode.

If there is no way to achieve block decorations/widgets with Obsidian’s CodeMirror, is there a way to replace the editor with a custom CodeMirror instance?

I’m still new to Obsidian and its plugin system. Any advice is welcome. Thanks in advance!

1 Like