Disclaimer
Is this project open source? Yes
Is this project completely free? Yes
Is this project made with AI beyond the author’s ability to comprehend how it works? No
This is a showcase which pertains to two specific plugins: Spaced Repetition, a flashcard plugin, and Cornell Notes, a plugin which styles information as, well, Cornell Notes.
Interestingly, the concept for flashcards and Cornell Notes is similar.
- Flashcards ask a question or give a term, and test your memorization of the definition.
- Cornell Notes lead with a “cue”, which tends to be a phrase/term or question, and proceeds to answer it.
In my workflow (and perhaps yours, if you’re reading this), I wanted to compress my notes for classes into a “summary table” where I compressed the important information into testable questions/important concepts, which Cornell Notes seemed optimal for. I also wanted to have a means of reviewing the information, and used Spaced Repetition in this process.
However, creating Cornell Notes and Spaced Repetition flashcards felt redundant, and specifically creating Cornell Notes via the plugin got annoying because I’d need to break the codeblock (````cornell) every time I changed something.
To solve this, I involved a custom script: via a third plugin, User Scripts, I automated the conversion of flashcards into Cornell Notes. Here’s the showcase:
/* Converts Spaced Reptition Flashcards to Cornell Notes */
plugin.addCommand({
id: 'cornell-notify-flashcards',
name: 'Cornell-Notify Flashcards',
callback: async () => {
const activeView = app.workspace.activeLeaf.view;
if (!activeView) {
console.warn("No active view!");
return;
}
// PART 1: Collect text from clipboard
let clipboard;
try {
clipboard = await navigator.clipboard.readText();
} catch (err) {
console.error("Clipboard access denied or failed", err);
return;
}
if (!clipboard) {
window.alert("No text in clipboard");
return;
}
let corrected = clipboard;
// STEP 2.1: Clean up memory tags
corrected = corrected.replace(/(\n)<!--(.*?)-->/g, "");
// STEP 2.2: Convert multi/single-line flashcards to cue-notes
corrected = corrected.replace(/(.*?)(\n(\?\?|\?) *)((\n.+)+)(\n( *)\n|\n *$|$)/g, "::cue\n$1\n::note$4$6");
corrected = corrected.replace(/(.*?)(\s*)(;;;|;;)(\s*)(.*?)(\n+)/g, "::cue\n$1\n::note\n$5\n\n");
// STEP 2.3: Delete "[!answer] tables"
let lineSplitTxt = corrected.split("\n");
let line;
let newTxt = [];
while(lineSplitTxt.length > 0) {
line = lineSplitTxt.shift();
if(/!answer/.test(line)) {
newTxt.push('');
while(/^>\s*/.test(line)) {
line = lineSplitTxt.shift();
newTxt.push(line.replace(/^>\s*/, ""));
}
} else {
newTxt.push(line);
}
}
corrected = newTxt.join("\n");
// // STEP 3: Wrap all cue-note blocks with Cornell Note codeblock
corrected = corrected.replace(/(#+ .*\n)((?!.*##+)(.|\n)*?)(\n<br>|\n*\s*$)/g, "$1````cornell\n$2\n````\n$4");
// STEP 4: Replace text with Cornell-notified text
const editor = activeView.editor;
const lastLine = editor.lineCount() - 1;
const lastCh = editor.getLine(lastLine).length;
editor.setSelection(
{ line: 0, ch: 0 },
{ line: lastLine, ch: lastCh }
);
editor.replaceSelection(corrected);
editor.setCursor({ line: 0, ch: 0 });
}
});
Usage: Simply copy the text into the clipboard, open the file for the Cornell Notes, and run the script. Also, this script excepts headers to be separated by <br>. If it isn’t, simply edit the <br> part to be (#+ .*\n).