title: Merging HTML files
body: <p>I want to merge one HTML file into another. Not just include it, but <em>merge</em>.</p>
  
  <h2>Example</h2>
  
  <p>master.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;My cat&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;My cat is awesome!&lt;/h1&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>_index.html:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;body&gt;
      &lt;p&gt;&lt;img src="cat.jpg"/&gt;&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now I merge _index.html into master.html.</p>
  
  <pre><code>$ html_merge master.html _index.html &gt; result.html
  </code></pre>
  
  <p>result.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;My cat&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;My cat is awesome!&lt;/h1&gt;
      &lt;p&gt;&lt;img src="cat.jpg"/&gt;&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><code>html_merge</code> is a script what I'm looking for. I'll use it for building static websites.</p>
  
  <p>I would like to use Ruby, but it's not required.</p>
  
  <h3>Update</h3>
  
  <p>I don't want to reinvent yet another template language. There is a lot of template languages with <code>include</code>/<code>yield</code> statement and partials support. <a href="http://www.liquidmarkup.org/" rel="nofollow noreferrer">Liquid</a>, <a href="http://github.com/defunkt/mustache" rel="nofollow noreferrer">mustache</a> and so on. I use them for different tasks. Now I need to merge HTML files, nothing more.</p>