It sounds like there may be an error in the formatting. When I inserted the suggested modification and created a test entry, Drafts created the appropriate journal with the appropriate text. I tried to recreate your conditions by creating a separate draft titled “Journal for January” and it still parsed it out correctly.
Maybe the issue lies elsewhere in the script? Here is the complete JavaScript I used to produce the above journal entry:
// This is the same as "Go to Today's Journal", but I don't know how to define them in one place and share that information
var ds = draft.processTemplate("[[date|%A, %3 %B %Y]]");
var bjTitle = "# Journal for " + ds;
var ts = draft.processTemplate("[[created|%H:%M]]");
var tag = "journal";
const tags = draft.tags;
var currentContent = draft.content;
// If the current draft doesn't start with "-", "*", or "@", then add a "- " to the front of it, give it a second-level header "##" and add a horizontal rule "---" beneath this section to visually distinguish each entry.
if ("-*@".indexOf(currentContent[0]) == -1) {currentContent = "- " + "## " + ts + "\n\n" + "- " + currentContent + "\n\n" + "---";
} else {currentContent = "- " + "## " + ts + "\n" + currentContent + "\n\n" + "---";
}
// If the current draft doesn't end with a newline, then add one.
if (currentContent.slice(-1) != "\n") {
currentContent = currentContent + "\n";
}
// Look for Today's Journal and complain if there are more than one matches.
var drafts = Draft.query(bjTitle, "all", [tag]);
if (drafts.length > 1) {
app.displayErrorMessage(drafts.length + " drafts have title '" + bjTitle + "'");
exit();
}
// It would be bad if we kept adding a draft's contents to itself. Keep that up a few times and the world would run out of hard drives to store it.
if (drafts.length > 0 && draft.uuid == drafts[0].uuid) {
app.displayErrorMessage("Not appending this note to itself.");
exit();
}
// Either create a new draft or use the existing one
if (drafts.length == 0) {
var ourDraft = Draft.create();
ourDraft.content = bjTitle + "\n\n";
ourDraft.addTag(tag);
ourDraft.update();
app.displayInfoMessage("Created a new journal: " + bjTitle);
}
else
{
var ourDraft = drafts[0];
}
var existingContent = ourDraft.content;
// If the existing content doesn't end with a newline, then add one.
if (existingContent.slice(-1) != "\n") {
existingContent = existingContent + "\n"
}
// Check each line for special characters, "-*@". If they are missing, prepend "- " to the line so it gets journaled.
var newContent = '';
var lines = currentContent.split("\n");
for (var line of lines) {
if (line.length >0) {
if ("-*@".indexOf(line[0]) == -1) {
line = "- " + line;
newContent += line + "\n";
} else {
newContent += line + "\n";
}
} else {
newContent += line + "\n";
}
}
// Append the old draft to Today's Journal and save it.
existingContent = existingContent + newContent;
ourDraft.content = existingContent;
for (var tag of tags) {
ourDraft.addTag(tag);
}
ourDraft.update();
script.complete();
Correction 2021-01-21 19:54: The second line should actually read, var ds = draft.processTemplate("[[date|%A, %e %B %Y]]");
