I am returning to using the Summarize Highlights feature after some time away, and I now find that this feature seems to add CriticMarkup syntax to each highlight. I would prefer this not happen. Is there an option to disable this? I am already running a script from a smart rule to reformat the file produced by the Summarize Highlights command, but I was not the author of the script so I’m not sure how to edit it to remove the CM syntax, if that’s the only option.
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
if (type of theRecord as string) = "markdown" then
-- Only process Markdown docs
set newText to {}
-- Set up an empty list to push the paragraphs into)
set currentText to (plain text of theRecord)
-- Get the current text of the document
repeat with thisLine in (paragraphs of currentText)
-- Loop through the document, paragraph by paragraph
if thisLine begins with "##" then
-- If this is an H2 page link
set cachedText to (characters 4 thru -1 of thisLine as string) -- Cache all but the control characters in a variable
else if thisLine begins with "* " then
-- If it's just a bulleted paragraph
copy ((characters 3 thru -1 of thisLine as string) & " (" & (cachedText) & ") " & return) to end of newText
-- Get all but the control characters and concatenate the cachedText.
-- Then push it to the newText list
else
copy thisLine & return to end of newText
-- Anything else, including the H1 line at the top, just push into the newText list
end if
end repeat
set plain text of theRecord to (newText as string)
-- Set the text of the document to the new text
end if
end repeat
end tell
end performSmartRule
Would love some help here @BLUEFROG . Here’s an attempt I made at removing the criticmarkup syntax with AppleScript but no luck:
on performSmartRule(theRecords)
tell application id "DNtp"
repeat with theRecord in theRecords
if (type of theRecord as string) = "markdown" then
-- Only process Markdown docs
set newText to {}
-- Set up an empty list to push the paragraphs into)
set currentText to (plain text of theRecord)
-- Get the current text of the document
repeat with thisLine in (paragraphs of currentText)
-- Loop through the document, paragraph by paragraph
if thisLine begins with "##" then
-- If this is an H2 page link
set cachedText to (characters 4 thru -1 of thisLine as string) -- Cache all but the control characters in a variable
else if thisLine begins with "* " then
-- If it's just a bulleted paragraph
copy ((characters 3 thru -1 of thisLine as string) & " (" & (cachedText) & ") " & return) to end of newText
-- Get all but the control characters and concatenate the cachedText.
-- Then push it to the newText list
else if thisLine contains "{==" then
set thisLine to findAndReplaceInText(thisLine, "{==", "")
copy thisLine & return to end of newText
else if thisLine contains "==}" then
set thisLine to findAndReplaceInText(thisLine, "==}", "")
copy thisLine & return to end of newText
else
copy thisLine & return to end of newText
-- Anything else, including the H1 line at the top, just push into the newText list
end if
end repeat
set plain text of theRecord to (newText as string)
-- Set the text of the document to the new text
end if
end repeat
end tell
end performSmartRule
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
Also, I’m now getting escape characters in my Markdown output (even without using this script and smart rule), e.g.,: \(2000\) What’s causing this?
Are you sure that paragraphs of currentText works with a Markdown file? If I understand Apple’s (as usually a bit terse) documentation, the Text suite requires Rich Text. Anyway, I tried the same approach with JavaScript and it threw an error when I tried to get the paragraphs of a MD plaintext. Here’s what I can offer:
(() => {
// NOT FOR USE IN A SMARTRULE
const app=Application("DEVONthink 3");
const recs = app.selectedRecords();
const collection = [];
recs.forEach(r => {
let txt = r.plainText();
let cache = "";
const lines = txt.split('\n\n');
lines.forEach(line => {
let match_h2 = line.match(/^## (.*)/);
if (match_h2) {
let cache = match_h2[1];
} else {
let match_list = line.match(/^\* (.*)/);
if (match_list) {
collection.push(`${match[1]} ( ${cache} )`);
} else {
collection.push(line.replaceAll(/==\{|\}==/g,""));
}
}
});
console.log(collection.join('\n\n'));
});
})()
No comments, I’m afraid, but I tried to follow your logic. As it is, the script does not modify the original file, it just prints out the new version on the console (so you have to run it in Script Editor). Also, it will not work in a smart rule – that’s not possible with JavaScript, I’m afraid).
I couldn’t test it, because I have neither a sample with Critical Markup nor one with the desired transformation.
Here is a script with a handler that scrapes CriticMarkup syntax from a Markdown file.
The handler can be called as a post-process step, if needed.
Note you must pass the plain text and the cached text item delimiter.
(* Uncomment for testing
tell application id "DNtp"
my performSmartRule(selected records)
end tell *)
on performSmartRule(theFiles)
tell application id "DNtp"
set od to AppleScript's text item delimiters
repeat with thisRecord in theFiles
if (type of thisRecord as string) = "markdown" then
set scrapedText to my scrapeCriticMarkup(plain text of thisRecord, od)
set plain text of thisRecord to scrapedText
end if
end repeat
end tell
end performSmartRule
on scrapeCriticMarkup(recText, od)
set AppleScript's text item delimiters to {"{==", "==}", "{--", "--}", "{++", "++}", "{==", "==}", "{~~", "~>", "~~}", "\\"}
set scrapedText to text items of recText
set AppleScript's text item delimiters to od
return (scrapedText as string)
end scrapeCriticMarkup
And here’s a sample smart rule that would strip the CriticMarkup once a Summary Markdown file is created… Scrape CriticMarkup.dtSmartRule.zip (1.4 KB)
It would have been better if the critic markups were not added in the first place. Many markdown reading apps do not support them. They also make the text very dirty.
Putting the highlighted text in Quote >
Putting an italic or bold over the underlined text. to differentiate it from the highlighted
keep the comments outside of quotation marks
would have been sufficient.
These are the systems used by Highlights app. The result is much better markdown text that can be opened by any markdown app.
That is great. Thank you.
I didn’t know that a specific preference for Markdown existed.
I have one more question dear @cgrunenberg.
Doesn’t summarize Highlights include image annotations?
I am pleased by the new summary (without the critic markup). But, the images are not included with the summary note. Is there any way to get image annotations?