Skip to content

Instantly share code, notes, and snippets.

@scottslowe
Last active October 8, 2019 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottslowe/5686217 to your computer and use it in GitHub Desktop.
Save scottslowe/5686217 to your computer and use it in GitHub Desktop.
This AppleScript takes Markdown text from BBEdit, runs it through MultiMarkdown, then through TextSoap, and finally posts it to a new entry in MarsEdit.
-- Set some global values to be used later in the script
property markdownloc : "/usr/local/bin/multimarkdown"
on translate_line_breaks(str)
set AppleScript's text item delimiters to {ASCII character 13}
set _lines to every text item of str
set AppleScript's text item delimiters to {ASCII character 10}
set str to _lines as text
set AppleScript's text item delimiters to {}
return str
end translate_line_breaks
-- Handler for when the script is called from the BBEdit scripts menu
on run
tell application "BBEdit"
set mdSource to contents of text window 1 as Unicode text
end tell
set mdSource to translate_line_breaks(mdSource)
set rawHTML to do shell script "echo " & the quoted form of mdSource & " | " & markdownloc
tell application "textsoap7agent"
set cleanedHTML to cleanText rawHTML with "Remove HTML Entities"
end tell
tell application "MarsEdit"
make new document
tell document 1
set body to cleanedHTML
end tell
activate
end tell
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment