Here is an edit which aims for
- monochrome fully hyphenated date
- a comma trailing project names
(to see the edited lines, search for the word delta
in the script)
// DUE REPORT script for TaskPaper 3 ver 0.04 b
// Modified for date display
// (removed red color, despite May Day, restored hyphen before day)
// and insertion of comma after project
// 2016-05-01
var strClip = (function () {
'use strict';
function fnTP3Context(editor, options) {
// concatMap :: [a] -> (a -> [b]) -> [b]
function concatMap(xs, f) {
return [].concat.apply([], xs.map(f));
}
function itemProject(item) {
var p = item.parent;
while (p) {
if (p.getAttribute('data-type') === 'project') {
return p.bodyContentString;
};
p = p.parent;
}
return '';
}
function timePart(item, strTimeTag) {
var strDate = item.getAttribute('data-' + strTimeTag);
return strDate ? strDate.slice(10, 16)
.trim() : '';
}
function otherTags(lstAttribNames, attribs, strGroup) {
return concatMap(
lstAttribNames,
function (k) {
var strTag = k.indexOf(
'data-'
) === 0 ? k.slice(5) :
'',
strValue = attribs[k];
// Non-grouping tag attributes included
return (
strTag && ['type', strGroup]
.indexOf(strTag) === -1
) ? [
'@' + strTag + (strValue ? '(' + strValue + ')' : '')
] : [];
}
)
.join(' ');
}
var outline = editor.outline;
// READING OF SORT SPEC
var lstOrder = options.orderBy.split(/\s+/),
strSortBy = lstOrder[0].trim(),
blnZA = (lstOrder.length > 1) && (lstOrder[1].trim()
.substr(0, 4)
.toLowerCase() === 'desc'),
strSortAttrib = 'data-' + strSortBy;
// READING OF GROUPING SPEC
var lstGroup = options.groupBy.split(/\./),
strGroup = lstGroup[0],
strGroupAttrib = 'data-' + strGroup,
strGroupFn = lstGroup.length > 1 ? lstGroup[1] : undefined;
// FILTERED BY ...
var lstFiltered = outline.evaluateItemPath(options.filter),
// GROUPED BY ...
dctGroups = lstFiltered.reduce(
function (groups, dctItem) {
var v = dctItem.getAttribute(strGroupAttrib),
vGroup = strGroupFn ? eval(
'"' + v.toString() + '".' + strGroupFn
) : v,
dctGroup = groups[vGroup] || {};
dctGroup[dctItem.id] = dctItem;
groups[vGroup] = dctGroup;
return groups;
}, {}
),
// GROUPS ORDERED BY
lstGroups = Object.keys(dctGroups)
.sort(blnZA ?
function (a, b) {
return a === b ? 0 : (a < b ? 1 : -1);
} : function (a, b) {
return a === b ? 0 : (a > b ? 1 : -1);
});
return "### <font color='silver'>" + strGroup.charAt(0)
.toUpperCase() + strGroup.slice(1) + "</font>\n\n" +
lstGroups.map(function (k) {
var dctGroup = dctGroups[k];
// return "#### <font color=gray>" + k.substr(0, 7) + // delta
return "#### <font color=gray>" + k.substr(0, 10) +
// '</font> <font color=red>' + k.slice(8) + // delta
// (deleted)
'</font>\n' + Object.keys(dctGroup)
.map(function (id) {
var item = dctGroup[id];
var strTime = timePart(item, strGroup),
strProject = itemProject(item),
attribs = item.attributes,
strPrefixes = (strTime ?
'<font color=gray><b>' +
strTime +
'</font></b>\t' :
'') + (strProject ?
'<font color=gray>' +
//strProject + // delta
strProject + ':' +
'</font> ' : '');
return strPrefixes +
// body text
item.bodyContentString
// Any remaining (non-grouping) tags
+ ' <font color=gray>' + otherTags(
item.attributeNames,
attribs,
strGroup
) + '</font>';
})
.sort()
.join('\n');
})
.join('\n\n');
}
var ds = Application("TaskPaper")
.documents,
varResult = ds.length ? ds[0].evaluate({
script: fnTP3Context.toString(),
withOptions: {
filter: '//@due',
groupBy: 'due.substr(0, 10)',
orderBy: 'due'
}
}) : false;
return varResult;
})();
var a = Application.currentApplication(),
sa = (a.includeStandardAdditions = true, a);
sa.setTheClipboardTo(strClip);
strClip