Interactive HTML stories creator I decided to write a small script to make writing HTML interactive stories less tedious:

import doctest
import re
import sys

import tkinter
import tkinter.filedialog

HTML_START = """&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
  &lt;div align="center"&gt;
  &lt;head&gt;
    &lt;title&gt;{}&lt;/title&gt;
    &lt;h1&gt;{}&lt;/h1&gt;
  &lt;/head&gt;
  &lt;body&gt;
     """

HTML_END = """
     &lt;/div&gt;
   &lt;/body&gt;
&lt;/html&gt;"""

SEPARATOR = '\n---\n\n'

def link_to_self(word):
    """
    Generates an html link to the given word.

    &gt;&gt;&gt; link_to_self("spam")
    '&lt;a href="Spam.html"&gt;spam&lt;/a&gt;'
    """
    return '&lt;a href="{}.html"&gt;{}&lt;/a&gt;'.format(word.capitalize(),word)

def inside_square_brackets(text):
    """
    Returns all the text inside square brackets.

    &gt;&gt;&gt; inside_square_brackets('Some nice [brackets]')
    ['[brackets]']
    """
    return re.findall('\[.*?\]',text)

def insert_links(text):
    """
    Insert links from square brackets.

    &gt;&gt;&gt; insert_links("A [cake]?")
    'A &lt;a href="Cake.html"&gt;cake&lt;/a&gt;?'
    """
    for link in inside_square_brackets(text):
        text = text.replace(link,link_to_self(link.replace('[','').replace(']','')))
    return text

def html_page(title,page):
    """
    Generates an html page with title and text.
    """
    return HTML_START.format(title.capitalize(),title.capitalize()) + insert_links(page) + HTML_END

def create_html_file(filename,text):
    with open(filename+'.html','w+') as f:
        f.write(html_page(filename,text))

def gen_interactive_story(titles_and_texts):
    for title,text in titles_and_texts:
        create_html_file(title,text)

def parse_stories_and_titles(text):
    """
    Spits out tuples (title,text) from a text containg paragraphs
    separated by the SEPARATOR.
    """
    chunks = text.split(SEPARATOR)
    lines_from_chunks = [chunk.splitlines() for chunk in chunks]
    return [(line[0].capitalize(),''.join(line[1:]))
                for line in lines_from_chunks]

def find_txt_file(lst):
    """
    Returns the first '.txt' file in a list.

    &gt;&gt;&gt; find_txt_file(['a.txt','b.foo','c.py'])
    'a.txt'
    """
    txts = [i for i in lst if '.txt' in i]
    if txts: return txts[0]

def contains_txt_file(lst):
    return bool(find_txt_file(lst))

def parse_and_generate_stories(filename):
    with open(filename) as f:
        titles_and_texts = parse_stories_and_titles(f.read())
    gen_interactive_story(titles_and_texts)

def ask_filename():
    root = tkinter.Tk()
    root.withdraw()
    return tkinter.filedialog.askopenfilenames()[0]

def _test():
    doctest.testmod()

def main():
    _test()
    if contains_txt_file(sys.argv):
        filename = find_txt_file(sys.argv)
    else:
        filename = ask_filename()
    parse_and_generate_stories(filename)

if __name__ == "__main__":
    main()


To simplify testing, I include a properly written story:



a scary choice

It was an extremely [dark] night and around me I could only 
see a [cave] and a [wood].

---

dark

I mean, extremely dark, even without moon. But I could not lose time,
it was time to make [a scary choice].

---

cave

The cave was frightening, but I decided to go in nonetheless,
what is life without risk?


---

wood

The wood was emitting scary and creepy sounds but I decided 
to enter it because it seemed less scary than the wood.
for starters, have it output valid html....so don't put a div and an h1 into your head...
also align is not a valid attribute. you should run your markup output through a validator