2006/04/05

MarsEdit script: Markdown quote

I’ve put together a quick script to quote in Markdown through MarsEdit. Simply select the text you want to quote and this script’ll add “> ” in front of every line. Adapt trivially for verbatim (change “> ” to a tab character instead). This is a shining example of how great Applescript is (as opposed to a number of very good reasons why Applescript is a monster to work with). With thanks to Brent Simmons:

tell application "MarsEdit"
    try
        set currentWindow to post window 1
    on error errorMessage
        displayErrorMessage("Can’t quote current selection because no post windows are open. This script works on selected text in the frontmost post window.") of me
        return
    end try
    set |new text| to ""
    set |text to quote| to the selected text of the front post window
    set |text lines| to the count of the paragraphs in the |text to quote|
    repeat with ii from 1 to |text lines| - 1
        set |new text| to |new text| & "    " & paragraph ii of |text to quote| & return
    end repeat
    if paragraph |text lines| of |text to quote| is not "" then
        set |new text| to |new text| & "    " & paragraph |text lines| of |text to quote| & return
    end if
    set the selected text of the front post window to |new text|
end tell

More as they come.