I have a workflow in Obsidian where I save web clippings (articles) in a dedicated Clippings/ folder. While reading these articles, I highlight important parts using the ==highlight== syntax. I also use daily notes to reflect on my day.
Here’s what I want to achieve:
Dynamically create a list of the highlights (inside the note) on the top of the note.
Automatically add all highlights I added today to my daily notes for reflection.
Does anyone do something similar? And if so, how?
I’m wondering where I should get the date from. I have a created date variable in the note, which is not the time I read it. I also have a task at the beginning of each document, that I use to mark it as done (read) - this might be more suitable.
So I see two options:
Dynamically fetch all the highlights into a daily/weekly note, based on the completion date of this task - here I’m not sure how to add them to the top of the file.
Trigger a script manually after reading that a) copies the highlights to the daily/weekly notes and b) copies them to the beginning of the file.
I’m aware of the extract-highlights-plugin, but I don’t see yet how it would help, especially automating this.
Would love to hear how others have tackled similar workflows and in which way (plugins/scripts). Thanks!
// Fetch the raw content of the current note
const content = await dv.io.load(dv.current().file.path);
if (content) {
// Extract highlights
const highlights = content.match(/==.+?==/g) || [];
// Skip the first highlight
const filteredHighlights = highlights.slice(1);
if (filteredHighlights.length > 0) {
dv.header(2, "Highlights in This Note");
filteredHighlights.forEach((highlight, index) => {
const cleanHighlight = highlight.replace(/==/g, "").trim();
// Calculate the line number where the highlight appears
const lineNumber = content.substring(0, content.indexOf(highlight)).split("\n").length;
// Generate a wikilink with line anchor
const anchor = `[[${dv.current().file.name}#^line-${lineNumber}]]`;
// Add an inline blockquote with the clickable link
dv.paragraph(`> ${cleanHighlight}(${anchor})`);
});
} else {
dv.paragraph("No highlights found in this note.");
}
} else {
dv.paragraph("Failed to load content for this note.");
}
Note: the links to the line don’t work - I’m not sure if this is possible
2. Added a dataviewjs snippet in my daily note, that dynamically fetches the highlights of Clippings that have a matching completed (the day I read it) date.
const folderPath = "Clippings"; // Path to your clippings folder
const today = dv.current().file.name; // Assumes daily note name is YYYY-MM-DD
dv.header(2, `Highlights Added on ${today}`);
// Fetch notes with tasks completed today and highlights
let notesWithHighlights = [];
for (let note of dv.pages(`"${folderPath}"`).where(p =>
p.file.tasks.some(task => {
const match = task.text.match(/✅ (\d{4}-\d{2}-\d{2})/);
return match && match[1] === today;
})
)) {
const content = await dv.io.load(note.file.path);
const highlights = content.match(/==.+?==/g)?.slice(1) || []; // Remove the first highlight
if (highlights.length > 0) notesWithHighlights.push({ note, highlights });
}
// Display highlights
if (notesWithHighlights.length > 0) {
notesWithHighlights.forEach(({ note, highlights }) => {
highlights.forEach(highlight => {
const cleanHighlight = highlight.replace(/==/g, "").trim();
dv.paragraph(`> ${cleanHighlight}\n- From [[${note.file.name}]]`);
});
});
} else {
dv.paragraph("No highlights found for today.");
}