Dev request: Markdown View for dynamic content (not file-based)

Use case or problem

Many plugins require dynamic markdown, but there is no standard way of displaying such views.

Proposed solution

Adapting an existing class like MarkdownPreviewView to allow views to be created with custom Markdown, in lieu of a TFile, to streamline many plugin applications.

Current workaround

ItemView

Right now, you can use ItemView to render custom Markdown, but there are many Markdown behaviors not implemented in this view:

  • Inner links and tags do not render as expected
  • Must add “user-select: text” to CSS to allow text selection
  • Headers do not render in outline sidebar
  • codeblocks do not run as expected (i.e. query)

So developers independently implement these features, leading to inconsistencies (see: ItemView issue)

Other Methods

Otherwise, you can use a Code Block Post Processor to insert Markdown into the page, or create new Markdown files in the vault.

Code blocks lack the user-friendly nature of modals, commands, etc. to customize behavior. For example, to use Dataview you need to write in special syntax.

Creating files lead to file glut when lots of Markdown needs to be dynamically generated even when the user doesn’t really need to save the result. For example, a tags pages plugin creates tons of duplicate content for heavy tag users.

Both code blocks and file creation make sense when you want to save the dynamic markdown output, but for ad-hoc actions like search, they make less sense.

This also reduces interoperability IMO, as it leads to mixing of Obsidian-only content (plugin logic) with universal content (valid Markdown), even when it isn’t needed.

As a workaround, you can do something similar as Meld Encrypt plugin. It uses a MarkdownView but pre-processes the file contents so that it is only decrypted in-memory and never on disk. Thus the rendered markdown is “dynamic” because it can be pre-processed however you see fit, and you still get the “true” Obsidian markdown rendering by using a MarkdownView.

I believe this requires a file to open first though, but maybe with some tweaks you can trick Obsidian into thinking that you open a file. Even though it’s a hack, it is still quite a clean solution I would say.

Start looking in this source code file, it contains how the view is implemented. In particular the override setViewData and setUnencryptedData functions.

I’m not sure if this is related but some time ago I was trying to get notes to appear elsewhere for a grid style plugin and could not get them to be editable without being stuck with ghost tabs when i restarted obsidian. tried a lot of things, never did figure out how to do this in a clean way. It always opened a tab somehow, whether it was visible or not, until an app restart would reveal it (or many, depending on what i was doing)