Skip to content

Instantly share code, notes, and snippets.

@salmin89
Last active September 21, 2020 03:10
Show Gist options
  • Save salmin89/33ac1c873ad39c59e3e15d89f38da005 to your computer and use it in GitHub Desktop.
Save salmin89/33ac1c873ad39c59e3e15d89f38da005 to your computer and use it in GitHub Desktop.
Copy to Trello format
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