Sometimes, when writing, I inadvertently add a space after the colon in the title of a project. The software immediately identifies the title as plain text, causing it to lose its title status.
I would like the software to also identify titles ending with a colon and a space as project titles.
Is it possible to change this behaviour in any way?
It may be easier to run a script which prunes any trailing space after project colons.
To test the script below:
- paste the full source code into Script Editor (there’s a copy button at top right of the expanded code display panel)
- set the language selector at the top left of Script Editor to
JavaScript
(rather thanAppleScript
) - Click the Run button.
(With utilities like FastScripts and Keyboard Maestro, you can easily attach such a script to a keyboard shortcut)
Expand disclosure triangle to view JS source
(() => {
"use strict";
// ---------- TASKPAPER EVALUATION CONTEXT -----------
const tp3Context = editor => {
const outline = editor.outline;
const rgxExtraSpace = /:\s+$/gu;
let report = [];
outline.groupUndoAndChanges(() => {
report = outline.items.flatMap(item => {
const s = item.bodyString;
return rgxExtraSpace.test(s)
? (
item.bodyString = s.replace(
rgxExtraSpace, ":"
),
[`\t${s}`]
)
: [];
});
});
const n = report.length;
return 0 < n
? `Fixed ${n} line(s):\n\n${report.join("\n")}`
: "No trailing spaces found.";
};
// ------------- JXA EVALUATION CONTEXT --------------
// main :: IO ()
const main = () => {
const
doc = Application("TaskPaper")
.documents.at(0);
return doc.exists()
? doc.evaluate({
script: `${tp3Context}`
})
: "No document open in TaskPaper.";
};
// MAIN ---
return main();
})();
If you start with with a TaskPaper file like the following, in which the 2nd and 3rd intended projects have lost their project status because of an unintended trailing space after the project colon:
then after running the script, you should find that the project syntax of those lines has been automatically fixed (any trailing spaces pruned out), giving you:
This is intentional. It’s needed because sometime people want to end a line with a colon and not have it recognized as a project. I think @complexpoint’s cleanup script is best bet.