Script to generate Remark formatted HTML file form FoldingText?
I've written several earlier posts about trying to use FoldingText to write HTML slide presentations. My new favorite app for this is Remark. But because the format of a Remark file is HTML it would be nice if I could work in pure FoldingText Markdown and then convert/export to Remark. Here is what would be needed to make this work.
(1) Add "---" between all top-level headers. So
# Header 1
## Header 2
- item1
# Header 3
- item 2
would become:
# Header 1
## Header 2
- item1
---
# Header 3
- item 2
(2) Insert the resulting text into the following HTML file where I've written [INSERT]
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<script src="https://github.com/downloads/gnab/remark/remark-0.4.4.min.js" type="text/javascript"></script>
<style type="text/css" media="screen">
/* Slideshow styles */
</style>
</head>
<body>
<textarea id="source">
[INSERT]
</textarea>
<div id="slideshow"></div>
</body>
</html>
(3) Finally, "Save as" in the appropriate folder.
I don't think this should be too hard, but I haven't used AppleScript in a while and could use some help.
Thanks!
Support Staff 2 Posted by Jesse Grosjean on 18 Feb, 2013 03:35 PM
A bit late... and not very pretty, but this does the first part of what you want I think:
It doesn't do the save as part, but instead just prints the text out into the AppleScript Editor console where you can copy it.
3 Posted by kerim on 18 Feb, 2013 11:09 PM
Thanks!
4 Posted by kerim on 18 Feb, 2013 11:53 PM
This almost works. It pops up a save-as dialog and writes the results to a file, but somehow TextWrangler tells me that the resulting "UTF-8 file is damaged or incorrectly formed." Not sure why?
5 Posted by kerim on 19 Feb, 2013 02:01 AM
OK. I think this solves the problem:
6 Posted by kerim on 19 Feb, 2013 02:22 AM
A couple of notes:
The HTML can specify an external stylesheet if you replace
with this:
Also, it would be nice if the script could automatically save the file as [CURRENT FILENAME].HTML (pulling the name and path of the current FT file, and simply changing the extension to HTML and saving it in the same folder. It would need to fail gracefully if a file with that name already exists.
7 Posted by kerim on 02 Mar, 2013 06:29 AM
Here is a revised script
8 Posted by kerim on 02 Mar, 2013 06:49 AM
Oops, that version would append to an existing file instead of overwriting it when making changes. This version works better:
9 Posted by kerim on 03 Mar, 2013 07:48 AM
This script works very well now. But the search-replace function doesn't work with one of the key features of Remark, which involves certain Markdown Extensions placed right after the slide divider. For instance:
---
name: title
class: center, middle, inverse
# Silde Text
> More slide text
---
There is also a "template" function which can refer to a previous "name," inheriting all of it's class values. The search-replace currently divides the slide at the `#` and so these these additions end up being before the slide divider and not after it. I don't know if it is possible to re-write the script to fix this? It would need to make exceptions for lines starting with any of these three words, including them in the following slide, not the previous one.
Anyone able to script this?
10 Posted by kerim on 04 Mar, 2013 02:08 AM
I've fully documented this script's use and posted the latest version of the code over at Remark GitHub Wiki.