What I’m trying to do
I have a large number of notes with a description:
property. It is basically a short sentence summarizing the note content. I want to display this summary at the beginning of preview text, but I don’t know how to achieve that.
A markdown source example:
---
description: This is a test
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pellentesque tristique euismod. Etiam tincidunt enim et suscipit suscipit. Interdum et malesuada fames ac ante ipsum primis in faucibus. Phasellus id nisl eget dui ultrices viverra non ac ex.
Quisque non tortor laoreet, rhoncus massa ut, dictum est. Fusce a sapien diam. Sed congue orci libero, eu semper ante posuere ac. In suscipit metus vel elementum eleifend.
Desired live preview and reading view (a description block is inserted at the beginning of note body):
Desired preview when hovering the cursor over a link in Reading View:
It would be acceptable if the inserted block is not editable.
Things I have tried
In pure markdown (MultiMarkdown), the following JavaScript does what I want perfectly.
(() => {
// Add description block at the top
let descriptionText = document.querySelector('meta[name="description"]')?.content;
if (descriptionText) {
let descriptionBlock = document.createElement('p');
descriptionBlock.setAttribute('id', 'description');
descriptionBlock.textContent = descriptionText;
document.querySelector('body').prepend(descriptionBlock);
}
})()
I don‘t know how to do the equivalent in Obsidian, though. I know little about JS and nothing about TS.
I want the description
property to be indexed in both Obsidian and my other tool, so it‘s not OK to simply delete the property and insert something like <p id="description">This is a test</p>
as the first line of body in every note.
Any pointers would be appreciated!