Created
March 13, 2013 12:16
-
-
Save kerim/5151560 to your computer and use it in GitHub Desktop.
FoldingText to Remark AppleScript
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
to searchReplace(thisText, searchTerm, replacement) | |
set AppleScript's text item delimiters to searchTerm | |
set thisText to thisText's text items | |
set AppleScript's text item delimiters to replacement | |
set thisText to "" & thisText | |
set AppleScript's text item delimiters to {""} | |
return thisText | |
end searchReplace | |
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean) | |
try | |
set the target_file to the target_file as text | |
set the open_target_file to ¬ | |
open for access file target_file with write permission | |
if append_data is false then ¬ | |
set eof of the open_target_file to 0 | |
write this_data to the open_target_file starting at eof as «class utf8» | |
close access the open_target_file | |
return true | |
on error | |
try | |
close access file target_file | |
end try | |
return false | |
end try | |
end write_to_file | |
tell front document of application "FoldingText" | |
set thisText to my searchReplace(read text, " | |
# ", " | |
--- | |
# ") | |
set finalText to "<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Title</title> | |
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/> | |
<script src=\"remark.min.js\" type=\"text/javascript\"></script> | |
<link rel=\"stylesheet\" type=\"text/css\" href=\"remark.css\" /> | |
</head> | |
<body> | |
<textarea id=\"source\">" & thisText & "</textarea>a | |
<div id=\"slideshow\"></div> | |
</body> | |
</html> | |
" | |
tell front document of application "FoldingText" | |
set thedocument to file of front document of application "FoldingText" | |
-- alternative to give file pre-determined name in same folder | |
-- tell application "Finder" | |
-- set theContainer to container of (thedocument as alias) | |
-- end tell | |
-- set newPath to ((theContainer as string) & "export.html") | |
set newPath to ((thedocument as string) & ".html") | |
end tell | |
-- Alternative to select name of file (must replace "newpath" with "theFile" in write_to | |
-- set theFile to choose file name with prompt "Set file name and location:" | |
my write_to_file(finalText, newPath, false) | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment