How to do block referencing in Obsidian

Actually every text line has a number (even if hidden), so surely,if it were parsed, this could be used. Line instead of block should be okay.

2 Likes

My thoughts on that in another forum topic: Block reference - #62 by Sellaro

1 Like

huh! :thinking: Interesting approach! I think for those of use using a strict folder structure, there would be a hassle of finding a place to put these newly made files, but it sounds interesting. Though For longer strings of text, as you mentioned, there is the limitation imposed by the OS (for windows it’s 255), and the use of most special characters is out of the question. But I think it will do. At least the price of using a Database is probably too high of a price for having something more convenient.

1 Like

The problem with referencing a line number is that as soon as you add a line anywhere above it, the whole thing falls apart.

I’ve been entertaining the idea of plain text block referencing for a while now, and I believe that some ID has to be added to the referenced line. Maybe just a few characters.

1 Like

I think in theory it could be done by tracking, in the same way that Obsidian tracks and adjusts for name changes.

@macedotavares @Dor Indeed, I think the best plugins for this will do both instantiate a block reference with a few characters and then cache and track that instantiation.

If I were to make such a plugin, I would use something like ((double parentheses)) to declare a statement reference. The statement itself can then be the identifier. (This assumes such statements would be unique, which I think is safe.)

Adding a couple thoughts. I think we could get most of the way there with Aliases if there were a way to embed a Page or Header without actually displaying the page title or header (e.g. embed contents only) and to display the contents in-line instead of inside a box.

Example:

  • Make a file called BlockTest.md
  • Type this out: [[blockRef123abc|Content I want to embed.]]
  • This would create a file called ‘blockRef123abc.md’ linked to a line of text “Content I want to embed.”
  • Now I can manually add the text “Content I want to embed.” to the file ‘blockRef123abc.md’.
  • Finally, I can embed this in another file with ![[blockRef123abc]]

The remaining problems are that the whole thing is in a box and that there’s a big “blockRef123abc” title above it.That should just be a display thing. Remove the title and display the content in-line with the rest of the note. We might even be able to do this with custom css? I’m not sure.

Now let’s modify this a bit:

  • Keep your BlockTest.md file, but also make BlockTest_BlockRef.md
  • Open BlockTest_BlockRef.md and type the following:
# blockRef123abc
Content I want to embed.
  • Now, in another file, type: [[BlockTest_BlockRef.md#blockRef123abc|Content I want to embed.]]

This works almost the same way as the first example with the same problems, except that, instead of creating a new markdown file for every single block you want to reference, you’re creating one additional file for each file that contains blocks you want to reference. The number of block reference files are, at most, going to equal the number of non-reference files in your vault instead of the total number of “blocks” that you want to reference.

Having gone through all that, I think a specialized syntax for creating a block is probably simpler (e.g. [[%abc123|Content I want to embed.]]. Though you’d probably need a way to generate a unique ID - at least unique per page, since you would probably do something like ![[BlockTest%abc123]] to embed it

The other problem I see is that any of these solutions would make the text pretty messy and difficult to read in edit mode.

We are able to do such thing by CSS. Many examples in the current CSS library.

I don’t like ‘problem(s)’ :wink:

I’ll be quoting a few posts from Block reference to summarize best practices found in that thread (which is a bit long).

Using H6 headers as blocks (albeit that can be a bit resource-intensive from what I recall).

1 Like

Block-level references for mathematical proofs:

Using header-level embeds:

Using CSS to make embeds inline:

Autohotkey script to create new notes based on selections:

How to add “naked” embeds

My current usage:
I have a text expander set up with a zettelkasten type date/time and an h6 followed by the date time.
I add text as desired either before the date/time or after - depending on how I envisage searching and preferred label.
I tend to use the pure date/time for new notes and the h6 one for blocks in a note.

This is quite sufficient for me. Unique names and links guaranteed. Most of the time I have no need for blocks, so I may not be typical of those who are interested in them.

2 Likes