# Automatically update HTML when text file changes.

#### davidjohnmacdonald

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

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?

3. Support Staff 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:

• Two image 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 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 ...

9. Support Staff 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?

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

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

### »

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

### Generic

? Show this help Blurs the current field

### Comment Form

r Focus the comment reply box Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

## Recent Discussions

 21 Feb, 2020 11:32 PM Option to use MathJax 3? 20 Feb, 2020 03:12 PM Regular crashes 13 Feb, 2020 09:22 PM Markdown Formatting 11 Feb, 2020 11:53 AM Custom themes not working 10 Feb, 2020 06:48 PM KaTex Preview Update

## Recent Articles

 Using JavaScript in Marked Custom CSS: Writing custom CSS for Marked License code has already been utilized Highlight sentences longer than a certain number of words How do I retrieve a lost license (direct version)