Created
March 3, 2014 14:28
-
-
Save danielpunkass/9326067 to your computer and use it in GitHub Desktop.
Linkify MarsEdit Lines - a simple script to turn plain text shorthand for e.g. podcasting show notes into links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Linkify! Select text in HTML mode in MarsEdit that follows the convention: | |
-- | |
-- [Link Title] | |
-- [Link URL] | |
-- [Link Description] | |
-- | |
-- Separated by blank lines between clumps, and run this script to put | |
-- suitable HTML on the pasteboard for linking to each item. | |
on linkClustersFromText(inputText) | |
set saveDelims to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to " | |
" | |
set linkItems to text items of inputText | |
set AppleScript's text item delimiters to saveDelims | |
return linkItems | |
end linkClustersFromText | |
-- Takes a cluster containing title, url, and description | |
-- as described above, and creates a record from it | |
on linkRecordFromCluster(inputCluster) | |
set saveDelims to AppleScript's text item delimiters | |
set AppleScript's text item delimiters to " | |
" | |
set inputLines to text items of inputCluster | |
set AppleScript's text item delimiters to saveDelims | |
return {title:item 1 of inputLines, URL:item 2 of inputLines, description:item 3 of inputLines} | |
end linkRecordFromCluster | |
-- Take a list of link clusters as described above, | |
-- and return a full HTML list suitable for inserting | |
-- into the post for publishing. | |
on linkTextFromClusters(inputClusters) | |
-- List preamble | |
set linkText to "<ul>" | |
repeat with thisCluster in inputClusters | |
set thisRecord to my linkRecordFromCluster(thisCluster) | |
set thisLinkLine to " | |
<li><a href=\"" & thisRecord's URL & "\">" & thisRecord's title & "</a> - " & thisRecord's description & "</li>" | |
set linkText to linkText & " " & thisLinkLine & " | |
" | |
end repeat | |
-- List postamble | |
set linkText to linkText & " | |
</ul>" | |
return linkText | |
end linkTextFromClusters | |
tell application "MarsEdit" | |
set baseText to selected text of document 1 | |
set linkClusters to my linkClustersFromText(baseText) | |
set finalText to my linkTextFromClusters(linkClusters) | |
set the clipboard to finalText | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment