You can then enter the directory and run redo there. This will generate article
 .html files from all .md and .rst files, plus a ./index.html, and a ./feed.xml.
-These files will be linked to symbolically in a directory ./public/. (Some
-metadata files will also be generated below ./metadata/: for each article, there
-will be generated a .uuid and a .intermediate file; furthermore, files for data
-used in ./feed.xml and ./index.html will be built and can be edited to customize
-the blog: ./metadata/url, ./metadata/author, ./metadata/uuid, ./metadata/title.) 
+These files will be linked to symbolically in a directory ./public/.
+
+Some metadata files will also be generated below ./metadata/: For each article,
+there will be generated a .uuid and a .intermediate file; furthermore, files for
+data used in ./feed.xml and ./index.html will be built there and can be edited
+to customize the blog – namely the files url, author, uuid, title, index.tmpl,
+index_snippet.tmpl, article.tmpl.
 
 bugs
 ----
 
 . ./helpers.sh
 metadata_dir=metadata
 intermediate_file="${metadata_dir}/${1%.html}.intermediate"
+redo-ifchange "$intermediate_file"
 title_file="${metadata_dir}"/title
 redo-ifchange "$title_file" 
-redo-ifchange "$intermediate_file"
+template_file="${metadata_dir}"/article.tmpl
+redo-ifchange "$template_file"
 
 # Build entry data.
-blog_title=`read_and_escape_file "$title_file" | head -1`
-title_html=`cat "$intermediate_file" | head -1`
+blog_title=$(read_and_escape_file "$title_file" | head -1 | prep_sed)
+title_html=$(cat "$intermediate_file" | head -1)
 title_plaintext=`echo "$title_html" | html2text`
-title_plaintext_escaped=`escape_html "$title_plaintext"`
-body=`cat "$intermediate_file" | sed 1d`
-
-# Write first part of entry head.
-cat << EOF
-<!DOCTYPE html>
-<html>
-<head>
-EOF
+title_html=$(printf "%s" "$title_html" | prep_sed)
+title_plaintext=$(escape_html "$title_plaintext" | prep_sed)
+body=$(cat "$intermediate_file" | sed 1d | prep_sed)
 
-# Write remaining entry head and body. 
-printf "<title>%s – %s</title>\n</head>\n<body>\n" "$blog_title" "$title_plaintext_escaped"
-printf "<h1>%s</h1>\n" "$title_html"
-printf "<section>\n%s\n</section>\n</body>\n</html>" "$body"
+# Put data into template.
+template=$(cat "$template_file")
+printf "%s" "$template" | \
+sed 's/%BLOG_TITLE%/'"$blog_title"'/g' | \
+sed 's/%ARTICLE_TITLE_ESCAPED%/'"$title_plaintext"'/g' | \
+sed 's/%ARTICLE_TITLE_HTML%/'"$title_html"'/g' | \
+sed 's/%BODY%/'"$body"'/g' | \
+tr '\a' '%'
 
   url_basepath=`echo $base_url | cut -d '/' -f 3-`
   url_basepath_escaped=`escape_url "$url_basepath"`
   basepath="$url_protocol""://""$url_basepath_escaped"
-  echo "$basepath"
+  printf "%s" "$basepath"
 }
 
 get_source_file() {
     exit 1
   fi
   redo-ifchange "$src_file"
-  printf "$src_file"
+  printf "%s" "$src_file"
+}
+
+prep_sed () {
+  # Escape characters that confuse sed in a replacement string. Also replace
+  # occurences of % (which the templating uses as a variable marker) with
+  # non-printable placeholder \a (clear input of it first), to be replaced by
+  # % again when the templating has finished (so that no replacement string gets
+  # interpreted by the templating).
+  sedsafe_pattern='s/\\/\\\\/g; s/\//\\\//g; s/&/\\\&/g; $!s/$/\\/g; '
+  sed "$sedsafe_pattern" | tr -d '\a' | tr '%' '\a'
 }
 
 srcdir=`pwd`
 title_file="$metadata_dir"/title
 redo-ifchange "$title_file"
+template_file="${metadata_dir}"/index.tmpl
+redo-ifchange "$template_file"
 
-# Write index head.
-cat << EOF
-<!DOCTYPE html>
-<html>
-<head>
-EOF
-blog_title=`read_and_escape_file "$title_file" | head -1`
-printf "<title>%s</title>\n</head>\n<body>\n" "$blog_title"
-printf "<h1>%s</h1>\n<ul>\n" "$blog_title"
+# Build blog title.
+title=$(read_and_escape_file "$title_file" | head -1 | prep_sed)
 
 # Generate link list entries.
 tmp_snippets_dir=.tmp_index_snippets
   mv ./${tmp_snippets_dir}/tmp ./${tmp_snippets_dir}/list
 done
 if [ -e "./${tmp_snippets_dir}/list" ]; then
-  cat ./${tmp_snippets_dir}/list
+  list=$(cat ./${tmp_snippets_dir}/list | prep_sed)
 fi
 rm -rf "${tmp_snippets_dir}"
 
-# Write index footer.
-printf "</ul>\n</body>\n</html>"
+# Put data into template.
+template=$(cat "$template_file")
+printf "%s" "$template" | \
+sed 's/%TITLE%/'"$title"'/g' | \
+sed 's/%LIST%/'"$list"'/g' | \
+tr '\a' '%'
 
--- /dev/null
+#!/bin/sh
+
+if [ ! -f "$1" ]; then
+cat << EOF
+<!DOCTYPE html>
+<html>
+<head>
+<title>%BLOG_TITLE% – %ARTICLE_TITLE_ESCAPED%</title>
+</head>
+<body>
+<h1>%ARTICLE_TITLE_HTML%</h1>
+<section>
+%BODY%
+</section>
+</body>
+</html>
+EOF
+fi
 
 redo-ifchange "$intermediate_file"
 html_file="${src_file%.*}.html"
 redo-ifchange "$html_file"
+template_file=index_snippet.tmpl
+redo-ifchange "$template_file"
 
-# Get variables, write entry.
-title_html=$(cat "$intermediate_file" | head -1)
-html_file_escaped=$(escape_url "${1%.index_snippet}.html")
-printf "<li><a href=\"%s\" />%s</a></li>\n" "$html_file_escaped" "$title_html"
+# Build entry data.
+title=$(cat "$intermediate_file" | head -1 | prep_sed)
+link=$(escape_url "${1%.index_snippet}.html" | prep_sed)
+
+# Put data into template.
+template=$(cat "$template_file")
+printf "%s\n" "$template" | \
+sed 's/%TITLE%/'"$title"'/g' | \
+sed 's/%LINK%/'"$link"'/g' | \
+tr '\a' '%'
 
--- /dev/null
+#!/bin/sh
+
+if [ ! -f "$1" ]; then
+cat << EOF
+<!DOCTYPE html>
+<html>
+<head>
+<title>%TITLE%</title>
+</head>
+<body>
+<h1>%TITLE%</h1>
+<ul>
+%LIST%
+</ul>
+</body>
+</html>
+EOF
+fi
 
--- /dev/null
+#!/bin/sh
+
+if [ ! -f "$1" ]; then
+cat << EOF
+<li><a href="%LINK%">%TITLE%</a></li>
+EOF
+fi
 
 </entry>
 
 <entry>
-<title type="html">a title with some nasty characters: &amp;&lt;&gt;&quot;'</title>
+<title type="html">a title with some nasty characters: &amp;&lt;&gt;&quot;' %BODY%</title>
 <id>urn:uuid:IGNORE</id>
 <updated>IGNORE</updated>
 <published>IGNORE</published>
 <link href="http://example.org/foo.html" />
 <content type="html">
-<p>this text contains some special characters: '&quot;&gt;&lt;&amp;</p>
+<p>this text contains some special characters: /;%'&quot;&gt;&lt;&amp;äöüß</p>
 <p>and more than one paragraph</p>
+<p>note that should be ignored but \ should give a backlash</p>
 </content>
 </entry>
 
 
 <!DOCTYPE html>
 <html>
 <head>
-<title>Yet another blog – a title with some nasty characters: &<>"'</title>
+<title>Yet another blog – a title with some nasty characters: &<>"' %BODY%</title>
 </head>
 <body>
-<h1>a title with some nasty characters: &<>"'</h1>
+<h1>a title with some nasty characters: &<>"' %BODY%</h1>
 <section>
-<p>this text contains some special characters: '"><&</p>
+<p>this text contains some special characters: /;%'"><&äöüß</p>
 <p>and more than one paragraph</p>
+<p>note that should be ignored but \ should give a backlash</p>
 </section>
 </body>
 </html>
\ No newline at end of file
 
-a title with some nasty characters: &<>"'
-=========================================
+a title with some nasty characters: &<>"' %BODY%
+================================================
 
-this text contains some special characters: '"><&
+this text contains some special characters: /;%'"><&äöüß
 
 and more than one paragraph
+
+note that \ should be ignored but \\ should give a backlash
 
 <body>
 <h1>Yet another blog</h1>
 <ul>
-<li><a href="foo.html" />a title with some nasty characters: &<>"'</a></li>
-<li><a href="bar%20baz.html" />foo</a></li>
-<li><a href="test.html" />foo <em>bar</em> <strong>baz</strong></a></li>
+<li><a href="foo.html">a title with some nasty characters: &<>"' %BODY%</a></li>
+<li><a href="bar%20baz.html">foo</a></li>
+<li><a href="test.html">foo <em>bar</em> <strong>baz</strong></a></li>
 </ul>
 </body>
 </html>
\ No newline at end of file