Note Merger Plugin

Name

Merge note

Description

Merge the contents, tasks, tags, and backlinks of two notes

Icon

merge_type

Instructions

When prompted, this plugin will merge the contents and tasks of the current note with another note selected from the prompt box and then delete the original note. Follow these steps:

1. From the note you want to merge with another note, open the note menu (three dots) and select "Merge note"



2. In the dialogue window, select the note you want to merge the current note content with (i.e., the "Destination" note)


3. Hit submit. The current note (i.e., "origin" note) content will be added below the selected note content. Tags and backlinks from the origin note will also be added to the destination note.


linkWishlist

Merge completed tasks from origin note to destination note



Setup settings for backlink and archiving options




linkVersion History

1.4.0 (Released: March 8th, 2024)

Added support for the new deleteNote function (the plugin will now delete the origin note after merging with the destination note)

1.3.0

Added support for removing all tags from the origin note

Added support for renaming the origin note after merge to indicate content has been merged with another note

1.2.1

Updated dialogue text to clarify the direction of the merge (i.e., merge from current note into note searched for)

1.2.0

Added support for merging backlinks from the origin note to the destination note

1.1.0

Added support for merging tags from the origin note with the destination note

Added auto-archived tag to origin note after merge completed

Fixed formatting issue with destination note adding an extra "\"

Fixed error with await functions

1.0.0

Initial public release


linkCodeblock

{
async noteOption(app, noteUUID) {
 
// retrieve first note content and information
const noteHandle = await app.findNote({ uuid: noteUUID });
const content1 = await app.getNoteContent({ uuid: noteUUID });
const noteName1 = noteHandle.name;
const backLinks = await app.getNoteBacklinks({ uuid: noteUUID });
const tags1 = noteHandle.tags;
// console.log(noteHandle);
 
// retrieve second note content and information (i.e., the destination note)
const result = await app.prompt("Choose the note to merge this content into:", {
inputs: [
{ type: "note" }
]
});
 
if (result) {
const noteUUID2 = result.uuid;
const noteName2 = result.name;
const noteURL = await app.getNoteURL({ uuid: noteUUID2 });
const content2 = await app.getNoteContent({ uuid: noteUUID2 });
const tags2 = noteHandle.tags;
 
// Merge note contents
const newContent = content2 + "\n# Merged content from " + noteName1 + "\n" + content1;
app.replaceNoteContent({ uuid: noteUUID2 }, newContent);
 
// Merge note tags
tags1.forEach(function(tag) {
app.addNoteTag({ uuid: noteUUID2 }, tag);
});
 
// Merge note backlinks
async function processLinks(backLinks, regex) {
for (const link of backLinks) {
const note = await app.getNoteContent({ uuid: link.uuid });
const matches = note.match(regex);
const markdown = note.replace(regex, `[${noteName2}](https://www.amplenote.com/notes/${noteUUID2})`);
app.replaceNoteContent({ uuid: link.uuid }, markdown);
}
}
 
let linkRegex = new RegExp(`\\[.+\\]\\(https:\/\/www\\.amplenote\\.com\/notes\/${noteUUID}\\)`, "g");
 
processLinks(backLinks, linkRegex);
 
// Navigate to second note
app.navigate(noteURL);
 
// Rename and delete origin note
tags2.forEach(function(tag) {
app.removeNoteTag({ uuid: noteUUID }, tag);
});
app.setNoteName({ uuid: noteUUID }, noteName1 + " [OLD - Merged with '" + noteName2 + "' note]")
app.deleteNote({ uuid: noteUUID });
 
 
} else {
console.log("User cancelled action");
}
}
}