Smarter scaling of images for display on Story overview

The existing code only scales based on width, resulting in tall
images being cut off. This patch scales on width or height,
whichever will allow the entire image to be displayed.

So that non-square images are displayed nicely, they are centred
after scaling.
Merge pull request #116 from lachlancooper/imagescaling

Smarter scaling of images for display in Story Map
Find links in SugarCube-style <<click>> and <<link>> macros

The <<link>> syntax is ambiguous in the 2-argument case. I checked the
SugarCube source and if the last argument is a known action keyword,
it is treated as an action, otherwise it is treated as a location.

Since these macros are SugarCube-specific, this code should probably
be moved into the header-specific Python module, once that lands.
Add special passage names and tags for SugarCube

This is a temporary solution; it would be better to make the header-
specific Python module register these.
Force UTF8 output if stdout of command line compiler is redirected

The typical way of using "twee" is to redirect its output to an HTML
file. However, such a redirect will use ASCII encoding unless
overriden by the PYTHONIOENCODING environment variable. Therefore it
would break if the output contains Unicode characters.

To avoid that, check whether we are outputting to a tty or to a file
and in the latter case, explictly encode as UTF8 (with BOM).