[applescript] Modify Markdown Summaries

Viewer

copydownloadembedprintName: Modify Markdown Summaries
  1. on performSmartRule(theRecords)
  2.         tell application id "DNtp"
  3.                 repeat with theRecord in theRecords
  4.                         if (type of theRecord as string) = "markdown" then
  5.                                 -- Only process Markdown docs
  6.                                
  7.                                 set newText to {}
  8.                                 -- Set up an empty list to push the paragraphs into)
  9.                                
  10.                                 set currentText to (plain text of theRecord)
  11.                                 -- Get the current text of the document
  12.                                
  13.                                 repeat with thisLine in (paragraphs of currentText)
  14.                                         -- Loop through the document, paragraph by paragraph
  15.                                        
  16.                                         if thisLine begins with "##" then
  17.                                                 -- If this is an H2 page link
  18.                                                 set cachedText to (characters 4 thru -1 of thisLine as string) -- Cache all but the control characters in a variable
  19.                                                
  20.                                         else if thisLine begins with "* " then
  21.                                                 -- If it's just a bulleted paragraph 
  22.                                                
  23.                                                 copy ((characters 3 thru -1 of thisLine as string) & " (" & (cachedText) & ")  " & return) to end of newText
  24.                                                 -- Get all but the control characters and concatenate the cachedText.
  25.                                                 -- Then push it to the newText list
  26.                                         else
  27.                                                 copy thisLine & return to end of newText
  28.                                                 -- Anything else, including the H1 line at the top, just push into the newText list
  29.                                         end if
  30.                                 end repeat
  31.                                
  32.                                 set plain text of theRecord to (newText as string)
  33.                                 -- Set the text of the document to the new text
  34.                                
  35.                         end if
  36.                 end repeat
  37.         end tell
  38. end performSmartRule

Editor

You can edit this paste and save as new:


File Description
  • Modify Markdown Summaries
  • Paste Code
  • 23 Feb-2021
  • 1.37 Kb
You can Share it: