Skip to content

Instantly share code, notes, and snippets.

@rwilcox
Created October 12, 2020 18:17
Show Gist options
  • Save rwilcox/31fa9482757286a16c1fa15e957f10b8 to your computer and use it in GitHub Desktop.
Save rwilcox/31fa9482757286a16c1fa15e957f10b8 to your computer and use it in GitHub Desktop.
/*{
"type": "action",
"targets": ["omnioutliner"],
"author": "Marc A. Kastner, with minor edits by Ryan Wilcox",
"description": "Create a markdown compatible format from the current document and export it to Drafts 5.",
"label": "Drafts - New Draft with Markdown format",
"paletteLabel": "Drafts Doc"
}*/
var _ = function() {
var action = new PlugIn.Action(function(selection, sender){
var topics = new Array()
rootItem.descendants.forEach(function(item){
level = item.level
if (item.descendants.length > 0) {
itemString = '#'.repeat(level) + " " + item.topic
topics.push(itemString)
} else {
// if no descendents treat the outline item as plain paragraph. RPW 10/12/2020
topics.push(item.topic)
}
noteString = '\n'
if(item.note) {
noteString = noteString + item.note + '\n'
}
topics.push(noteString)
})
topics.join('\n')
encodedStr = encodeURIComponent(topics.join("\n"))
urlStr = "drafts5://x-callback-url/create?text=" + encodedStr
url = URL.fromString(urlStr)
url.call(function(result){console.log(result)})
});
action.validate = function(selection, sender){
if(rootItem.descendants.length > 0){return true} else {return false}
}
return action
}();
_;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment