Automatically update HTML when text file changes.

davidjohnmacdonald's Avatar


01 Feb, 2014 01:52 PM

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.

  1. Support Staff 1 Posted by Brett on 01 Feb, 2014 03:40 PM

    Brett's Avatar

    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

    CSS: path/to/cssfile.css

    at the top of the file.


  2. 2 Posted by ken on 02 Feb, 2014 06:22 PM

    ken's Avatar

    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?

  3. Support Staff 3 Posted by Brett on 02 Feb, 2014 06:24 PM

    Brett's Avatar

    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.


  4. 4 Posted by ken on 02 Feb, 2014 06:36 PM

    ken's Avatar

    Sure I'd love to ... in many ways the example would be quite basic. It's just any .md file with:

    • Two image references
    • Two link references

    With both image and link examples you'd have:

    1. Relatively reference a target in the markdown and then that should be moved across to the HTML as a relative reference.
      • with the HTML file there would need to also be a modification of the filetype as previously mentioned
    2. Static reference to target.
      • in both image and link I think an absolute reference should be treated absolutely (aka, to magic needed other than recognising it is a direct link and avoiding any previously design magic).

    Out of interest, what processor would you use for the regex search/replace magic?

  5. Support Staff 5 Posted by Brett on 02 Feb, 2014 06:38 PM

    Brett's Avatar

    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?


  6. 6 Posted by ken on 02 Feb, 2014 09:20 PM

    ken's Avatar

    Yup, the one additional requirement is distinguishing relative versus absolute links and ignoring any replacement with absolute links.

  7. 7 Posted by davidjohnmacdon... on 19 Feb, 2014 08:30 PM

    davidjohnmacdonald's Avatar

    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:

    Here's the current HTML file generated from it:

    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. 8 Posted by ken on 25 Jun, 2014 01:34 PM

    ken's Avatar

    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 ...

  9. Support Staff 9 Posted by Brett on 25 Jun, 2014 01:38 PM

    Brett's Avatar

    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. 10 Posted by ken on 29 Aug, 2014 09:05 PM

    ken's Avatar

    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?

  11. Support Staff 11 Posted by Brett on 29 Aug, 2014 09:13 PM

    Brett's Avatar

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? 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