Skip to content

Instantly share code, notes, and snippets.

@kerim kerim/FT2REMARK
Created Mar 13, 2013

What would you like to do?
FoldingText to Remark AppleScript
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)
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
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>
<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\" />
<textarea id=\"source\">" & thisText & "</textarea>a
<div id=\"slideshow\"></div>
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
You can’t perform that action at this time.