Last active
June 23, 2019 00:41
-
-
Save kn1cht/911ca1e4c3e92c636a603dce940eae99 to your computer and use it in GitHub Desktop.
Revisions
-
kn1cht revised this gist
Jun 23, 2019 . 1 changed file with 8 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +1,19 @@ scrapbox.PopupMenu.addButton({ title : 'Embed Tweet', onClick : text => { const convertContent = (content, indent) => { const replaced = content .replace(/<a href="(https?:.*?)">(.*?)<\/a>/g, '[$1 $2]') .replace(/<br>/g, `\n${indent}`); const elem = document.createElement('div'); elem.innerHTML = replaced; return indent + elem.innerText; } const tweetRegex = /(?<spaces>[\t ]*)<blockquote[\w"\-= ]*><p[\w"\-= ]*>(?<content>.*)<\/p>—(?<author>.*)(?<link><a.*>)<\/blockquote>[\n\t ]*<script.*?><\/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)); } }) -
kn1cht revised this gist
May 2, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ scrapbox.PopupMenu.addButton({ elem.innerHTML = replaced; return elem.innerText; } const tweetRegex = /<blockquote[\w"\-= ]*><p[\w"\-= ]*>(?<content>.*)<\/p>—(?<author>.*)(?<link><a.*>)<\/blockquote>\n<script.*?><\/script>/; const match = text.match(tweetRegex); if(!match) return; const {content, author, link} = match.groups; -
kn1cht revised this gist
Apr 30, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ scrapbox.PopupMenu.addButton({ onClick : text => { const convertContent = content => { const replaced = content .replace(/<a href="(https?:.*?)">(.*?)<\/a>/g, '[$1 $2]') .replace(/<br>/g, '\n>'); const elem = document.createElement('div'); elem.innerHTML = replaced; @@ -15,4 +15,4 @@ scrapbox.PopupMenu.addButton({ const {content, author, link} = match.groups; return text.replace(tweetRegex, `>${convertContent(content)}\n>\t—${author} ${convertContent(link)}`); } }) -
kn1cht created this gist
Apr 30, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ scrapbox.PopupMenu.addButton({ title : 'Embed Tweet', onClick : text => { const convertContent = content => { const replaced = content .replace(/<a.*href="(https?:.*)">(.*)<\/a>/, '[$1 $2]') .replace(/<br>/g, '\n>'); const elem = document.createElement('div'); elem.innerHTML = replaced; return elem.innerText; } const tweetRegex = /<blockquote[\w"\-= ]*><p[\w"\-= ]*>(?<content>.*)<\/p>—(?<author>.*)(?<link><a.*>)<\/blockquote>/; const match = text.match(tweetRegex); if(!match) return; const {content, author, link} = match.groups; return text.replace(tweetRegex, `>${convertContent(content)}\n>\t—${author} ${convertContent(link)}`); } })