Skip to content

Instantly share code, notes, and snippets.

@scripting
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scripting/2a612b0e2cbb7077482a to your computer and use it in GitHub Desktop.
Save scripting/2a612b0e2cbb7077482a to your computer and use it in GitHub Desktop.
A code fragment that gets the myword.io compatible JSON from the bar cursor outline
function opGetBarCursor () { //11/12/14 by DW
return ($(getActiveOutliner ()).concord ().op.getCursorRef ());
}
function dateToNumber (theDate) { //2/15/15 by DW
return (Number (new Date (theDate)));
}
function opGetMywordJstruct (theNode) { //2/15/15 by DW
if (theNode == undefined) {
theNode = opGetBarCursor ();
}
function getImg (headline) {
var urlImg;
headline.visitToSummit (function (theNode) {
var img = theNode.attributes.getOne ("img");
if (img != undefined) {
urlImg = img;
return (false); //stop looking
}
return (true); //keep looking
});
return (urlImg);
}
function notComment (headline) {
return (!getBoolean (headline.attributes.getOne ("isComment")));
}
function addsubs (adrx) {
var theSubs = new Array ();
adrx.visitLevel (function (headline) {
if (notComment (headline)) {
var linetext = headline.getLineText ();
if (headline.countSubs () > 0) {
var sub = new Object ();
sub.title = linetext;
sub.subs = addsubs (headline);
theSubs [theSubs.length] = sub;
}
else {
theSubs [theSubs.length] = linetext;
}
}
});
return (theSubs);
}
var jstruct = new Object (), atts = theNode.attributes.getAll ();
jstruct.title = theNode.getLineText ();
jstruct.description = atts.description;
jstruct.authorname = appPrefs.authorName;
jstruct.when = atts.created;
jstruct.img = getImg (theNode); //walk to summit
jstruct.subs = addsubs (theNode);
return (jstruct);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment