addButton({ display: ({ selection }) => selection.hasSelection() ? { type: "unlink" } : "", onClick: async ({ selection }) => { const text = selection.getSelectedText(); const unlinked = text.split("\n") .map(line => line.replace( /\[((?:[^\[$!"#%&'()\*\+,\-\.\/\{\|\}<>_~]\s?|[\[$!"#%&'()\*\+,\-\.\/\{\|\}<>_~]\S)[^\[\]]*)\]/g, "$1" )) .join("\n"); if (text === unlinked) return; await insertText(unlinked); }, }); addButton({ display: ({ selection }) => selection.hasSelection() ? { type: "strikethrough" } : "", onClick: async ({ selection }) => { const text = selection.getSelectedText(); const striked = strike(text); if (text === striked) return; await insertText(striked); }, }); addButton({ display: ({ selection }) => selection.hasSingleLineSelection() ? { type: "code" } : "", onClick: async ({ selection }) => { const text = selection.getSelectedText(); await insertText(`\`${text}\``); }, }); addButton({ display: ({ selection }) => hasURL(selection.getSelectedText()) ? "URL" : "", onClick: async ({ selection }) => { const text = selection.getSelectedText(); const converted = await convertURL(text); if (text === converted) return; await insertText(converted); }, }); addButton({ display: ({ selection }) => getLink(selection.getSelectedText()) ? "update a link" : "", onClick: async ({ selection }) => { const text = selection.getSelectedText(); await replace( text, [scrapbox.Project.name, "takker", "takker-memex", "takker-private"], ); }, });