Last active
November 8, 2022 16:58
-
-
Save mixio/02b1e24a7ef7033ead55c7d91bcfb449 to your computer and use it in GitHub Desktop.
This BBEdit script copies a markdown document's selection as HTML to the pasteboard.
This file contains 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
(* | |
README | |
This BBEdit script copies a markdown document's selection as HTML to the pasteboard. | |
In case nothing is selected it copies the whole contents of the document. | |
DOCUMENTATION | |
https://pandoc.org | |
INSTALL | |
Install pandoc from the Terminal: | |
% brew install pandoc | |
Create this script (with execute permissions) in : | |
~/Library/Application\ Support/BBEdit/Scripts/copy_markdown_as_html.applescript | |
Call the script from: | |
menu Scripts > copy_markdown_as_html | |
*) | |
-- | |
use AppleScript version "2.8" | |
use scripting additions | |
-- | |
try | |
tell application "BBEdit" | |
tell first window | |
set vSelection to its selection | |
tell its first document | |
if class of vSelection is insertion point then | |
set vMarkdown to (its contents) as string | |
else if class of vSelection is character then | |
set vMarkdown to (vSelection's contents) as string | |
else | |
error ("The script '" & (my name) as string) & "' doesn't handle discontinuous selections." | |
end if | |
end tell | |
set vCommand to ("echo " & (the quoted form of vMarkdown) & "| /opt/homebrew/bin/pandoc -f markdown -t html | pbcopy") | |
do shell script vCommand | |
end tell | |
end tell | |
on error aMessage number aErrorNumber | |
if aErrorNumber ≠ -128 then -- Error number -128 (User Cancelled). | |
display alert aMessage | |
end if | |
return | |
end try | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment