Canvas in a code block

Use case or problem

In a similar fashion to how a Base can be a code block or a separated file, I would love to have a way to get a Canvas to be a code block.

As a visual learner — or to do pretty much everything else than just earning — this feature request aims at fixing two things I don’t like with my current workaround solution described below:

  1. Canvas are not readable from my main file. I have to navigate back and forth. This is especially inconvenient if I’m looking to find a piece of information but can’t remember in which section is it showcased.
  2. Canvas are isolated containers of information. The biggest strength of Obsidian regarding notes and their content is the ability to create link, point to or embed sections, and use the very powerful Search core plugin.

Proposed solution

The way I see it, you would work on a Canvas in a dedicated file first because of all the interactions available in the full view. Then, considering you have a not-too-big diagram, you could copy & paste the source content of the file to a code block like:

```canvas
{
	"nodes":[
		{"id":"a1","type":"text","text":"onLoad","x":0,"y":20,"width":120,"height":60},
		{"id":"a2","type":"text","text":"onLayoutReady","x":160,"y":20,"width":180,"height":60},
	],
	"edges":[]
}
```

This would display a non-editable Canvas view fitting the nodes within. It would be a read-only view with no interoperable way no move nor control zoom.

Of course, a more elaborate solution allowing a regular Canvas view could work too, but this might make things too complicated. However, this feature request is created with simpler use cases in mind.

A Canvas of three text nodes and an image embed could easily fit a relatively short code block and make its content available for Search. Then, you could perfectly point to the section that code block is in, or embed it!

Current workaround (optional)

The way I work around this currently is that I have my files in matching-names sets.
Using a numbered list to explained that in organized chunks of information.

  1. Considering I have a few files to document the Obsidian Plugin API in my own words, I will have a Obsidian-Plugin_API.md file with all my text, sections and code blocks.
  2. Then, I will create a few Canvas files to illustrate the dependencies in a given set of classes or the order to call functions in.
  3. Those Canvas files include content from Obsidian-Plugin_API.md so all my text is searchable, extractable and linkable from other notes.
  4. Then, I go back to the main md file, and I include embed links to the Canvas files.

Related feature requests (optional)

I could not find any similar feature request on the forum.

One of the search query I used, among others, was ` Feature requests tags:canvas in:first code`.

The only kinda close request I’d link to, as it’s also about links, is /t/link-to-a-specific-section-of-a-canvas/49779.

1 Like