Last active
September 21, 2020 03:10
-
-
Save salmin89/33ac1c873ad39c59e3e15d89f38da005 to your computer and use it in GitHub Desktop.
Copy to Trello format
This file contains 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 characters
var rows = window.getSelection().toString().split("\n"); | |
var addDashes = true; | |
var instructionNr = 0; | |
var formattedText = rows.filter(row => row !== "").map(row => { | |
if (row.toLowerCase().includes("ingredient")) { | |
return '## ' + row + ' ##\n'; | |
} | |
if (row.toLowerCase().includes("instruction") || row.toLowerCase().includes("direction")) { | |
addDashes = false; | |
return '\n## ' + row + ' ##\n'; | |
} | |
if (addDashes) { | |
return '- ' + row; | |
} else { | |
instructionNr++; | |
return instructionNr + '. ' + row + '\n'; | |
} | |
}).join("\n"); | |
var text = document.createElement("textarea"); | |
text.value = formattedText; | |
text.setAttribute("contenteditable", true); | |
document.body.appendChild(text); | |
text.select(); | |
text.setSelectionRange(0, 99999); | |
document.execCommand("copy"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment