scrapbox.PopupMenu.addButton({ title : 'Embed Tweet', onClick : text => { const convertContent = (content, indent) => { const replaced = content .replace(/(.*?)<\/a>/g, '[$1 $2]') .replace(/
/g, `\n${indent}`); const elem = document.createElement('div'); elem.innerHTML = replaced; return indent + elem.innerText; } const tweetRegex = /(?[\t ]*)(?.*)<\/p>—(?.*)(?)<\/blockquote>[\n\t ]*<\/script>/; const match = text.match(tweetRegex); if(!match) return; const {spaces, content, author, link} = match.groups; const ind = `${spaces}>`; return text.replace(tweetRegex, convertContent(content, ind) + '\n' + convertContent(`\t—${author} ${link}`, ind)); } })