     delete_extras(output)
 
     epub_file
+  end
+
+  # Helper to generate an UUID v4. This version uses pseudo-random bytes generated by
+  # the `crypto` module.
+  def uuid4 do
+    <<u0::48, _::4, u1::12, _::2, u2::62>> = :crypto.rand_bytes(16)
+    bin = <<u0::48, 4::4, u1::12, 2::2, u2::62>>
+    <<u0::32, u1::16, u2::16, u3::16, u4::48>> = bin
+
+    Enum.map_join([<<u0::32>>, <<u1::16>>, <<u2::16>>, <<u3::16>>, <<u4::48>>], <<45>>, &(binary_to_hex_list(&1)))
+    |> IO.iodata_to_binary
+    |> String.downcase
+  end
+
+  defp binary_to_hex_list(binary) do
+    :binary.bin_to_list(binary)
+    |> Enum.reduce('', &(&2 ++ Integer.to_char_list(&1, 16)))
   end
 
   defp templates_path(other) do

    end
  end

  defp generate_content(output, config, modules, exceptions, protocols) do
    content = Templates.content_template(config, modules ++ exceptions ++ protocols)
    File.write("#{output}/OEBPS/content.opf", content)
  end

  defp generate_toc(output, config, modules, exceptions, protocols) do
    content = Templates.toc_template(config, modules ++ exceptions ++ protocols)
    File.write("#{output}/OEBPS/toc.ncx", content)
  end


    exceptions = HTML.filter_list(:exceptions, all)
    protocols = HTML.filter_list(:protocols, all)

    uuid = "urn:uuid:#{uuid4()}"
    generate_content(output, config, modules, exceptions, protocols, uuid)
    generate_toc(output, config, modules, exceptions, protocols, uuid)
    generate_nav(output, config, modules, exceptions, protocols)
    generate_title(output, config)
    generate_list(output, config, modules)
