Automatically update HTML when text file changes.
This isn't necessarily a Marked-specific question, but I figured somebody here would have a good answer.
I keep a number of HTML files in a public Google Drive folder for a small group of people to reference. They are all generated from Multimarkdown files in Marked 2, and I am regularly updating them. My question is this: Is there a way, using Marked or any other tool, to watch my text files, and automatically "sync" the HTML files anytime they change?
I want to just save the .txt in my text editor and have Marked pop out a .html that overwrites the previous one, without having to open Marked 2 each time.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Brett on 01 Feb, 2014 03:40 PM
Marked isn't built to handle this kind of un-manned conversion, but you
can do it pretty easily with Hazel and the multimarkdown executable. You
would just have Hazel watch the folder for files matching "*.md" (or
whatever criteria) and then run a custom script that ran it through
multimarkdown. You can add a custom CSS file to it using metadata
headers:
CSS: path/to/cssfile.css
at the top of the file.
-Brett
2 Posted by ken on 02 Feb, 2014 06:22 PM
The Hazel solution is probably very good but would multimarkdown be able to manage the links in the markdown files through to the html files? For instance, changing filetype of link from
.md
to.html
and keeping directory structure relative?Do any of you know of a good Hazel "receipe" for this?
Support Staff 3 Posted by Brett on 02 Feb, 2014 06:24 PM
That would take some custom scripting, but shouldn't be terribly
difficult (search and replace type of stuff).
I don't know of any existing Hazel recipes, but if you send me some
examples to work with, I'm willing to help build something that I could
publish on my blog for others to use.
-Brett
4 Posted by ken on 02 Feb, 2014 06:36 PM
Sure I'd love to ... in many ways the example would be quite basic. It's just any
.md
file with:With both image and link examples you'd have:
Out of interest, what processor would you use for the regex search/replace magic?
Support Staff 5 Posted by Brett on 02 Feb, 2014 06:38 PM
I would write a quick Ruby script that just scanned the content for .md
links and replaced them with .html. If I understand the needs, that
should do the trick, right?
-Brett
6 Posted by ken on 02 Feb, 2014 09:20 PM
Yup, the one additional requirement is distinguishing relative versus absolute links and ignoring any replacement with absolute links.
7 Posted by davidjohnmacdon... on 19 Feb, 2014 08:30 PM
Sorry, I've been a jerk asking for help and then not following up on the kind offer for help.
Here's an example of a .txt file that I'd like to be cooked automatically when I save it: https://googledrive.com/host/0B5JSFlWeB1jTWXlCU2Qya3BBNHM/BMG-A4-bu...
Here's the current HTML file generated from it: https://googledrive.com/host/0B5JSFlWeB1jTWXlCU2Qya3BBNHM/BMG-A4-bu...
I already have my styles linked from outside. I use this (and several other files like it) inside an iframe in a content (learning) management system, which is what that Javascript is doing. It just adds target=_parent so the links work right.
8 Posted by ken on 25 Jun, 2014 01:34 PM
Brett, any progress on this? This is my #1 feature request. I think it would just add awesome capability to your product. Anyway, I'm sure what I think has limited interest but since you had indicated a willingness to consider this ...
Support Staff 9 Posted by Brett on 25 Jun, 2014 01:38 PM
I have created a way to use the custom pre/processor features to automatically export various formats any time the document refreshes. Basically you run the conversion in the script, add your own headers and footers and then pass it back to Marked with "NOCUSTOM" to skip the results of the processor. I think it would work for you, but the functionality is broken in the current public release. It's been fixed for the next update, so once that's out (very soon), let me know and I can work with you to build the processor.
10 Posted by ken on 29 Aug, 2014 09:05 PM
Hi Brett. Is the current build now implementing this functionality? Can you provide a little more context so I can get my head around how this would be done?
Support Staff 11 Posted by Brett on 29 Aug, 2014 09:13 PM
http://brettterpstra.com/2014/07/22/custom-export-options-for-marked-2/