I’ve come up with a hacky way to set up block references better in obsidian (for some use cases).
From the past few versions, obsidian has a way to reference any block in a note.
But what constitutes a block is not obvious in all cases. This becomes more difficult if you have multiple lines, or you want to give the block some structure like headings and tags.
If you know that the block will very likely be referenced elsewhere, how should you compose it? Making another note about it an option, of course, but there plenty of use cases where one may not want to do that.
I coopt the quote-block to do this. The entirety of the quote is one block, and there’s styling that demarcates its boundaries, so it does solve a few problems.
The huge advantage is that the contents of the quote block are rendered as markdown independent of the main note, so there is a lot one can do with the block in terms of structure.
The following screen shot illustrates this (edit on the left, preview on the right)
The first example is a simple block, but the second one about code mirror hotkeys is a more complex block with 2 levels of headers (h3 and h4) tags, tasks, inline-code etc. (The item marked done is just to illustrate capabilities).
I’ve even inserted my own meaningful reference string
to find it easily later. (I don’t know how robust this part is. There have been no problems in my testing.) You can even use the same reference string
in different notes (I haven’t tested in the same note), so you don’t have to worry about duplication.
Writing markdown inside quote blocks may seem daunting at first, but it’s actually pretty easy:
- write regular markdown in the note
- inspect the preview (with practice and/or the right theme, you may not need this)
- insert
>
at the start of every line you want to make a part of the quote-block - inspect the preview
Depending on the elements you want to include in the quote block you may only need to precede the first line with >
. It’s called lazy formatting I think.
At a later point if you want to create a proper note for this quote-block
, you copy the entire block to a blank note and remove the >
. Your formatting stays as intended. Make sure the block reference stays put, along with a link to the new note. If you do this correctly the same block reference will forward you to the new note.
alternatives
headers
you can link to headers. There’s an elegance and simplicity to it, but you may not always want to mess with the structure of the document just because a block might be referenced later.
I prefer referencing headers when appropriate.
code block
there are other forum posts describing how to do this, and ideas for plug-ins that can utilize the code block. That could be the right way to go about this in future.
But for now, the biggest disadvantage is that tags are not recognized inside the code block (and with good reason). Also, formatting inside codeblocks is not great even if you define the language as markdown.
styling
The default styling for a quote block may not suit this purpose. In the screenshot I have modified it to closely mimic a note (because it will have markdown elements in it), but stand out enough to know that could be a separate element.
I would like to have borders on the top and bottom of the quote block in edit mode but I haven’t figured out how to do that as of now. A discussion on discord didn’t yield the solution. yet.
This is the styling I use:
/* usage of `!important` is not recommended */
/* I use it here because this is WIP */
/* the following is defined in my dark theme */
/* --attention4: hsla(0, 0%, 25%, 0.50);*/
/* you will need transparency here*/
/* to show cursor selections properly*/
.cm-s-obsidian span.cm-quote {
color: unset;
background: unset;
}
.HyperMD-quote {
color: var(--text-normal);
background: var(--attention4) !important;
border-left: 1px solid white !important;
border-right: 1px solid white !important;
}
.markdown-preview-view blockquote {
background: var(--attention4);
border-radius: unset;
border: unset;
padding: 10px;
margin: unset;
margin-top: 10px;
margin-bottom: 20px;
border-left: 1px solid white !important;
border-right: 1px solid white !important;
}
.markdown-preview-view blockquote p {
margin: 0 10px;
}