Updates to sphinx extensions

I split this off of #1355 to make it smaller. See that PR for full list of changes. Unfortunately, it's a bit difficult to split this one up any more, since they're a bit interdependent.
This exciting unicode character is causing Sphinx to error for me when building the docs:

```
Encoding error:
'ascii' codec can't decode byte 0xc2 in position 118: ordinal not in range(128)
...
make[1]: *** [html] Error 1
```

Looks like you're replicating the built-in Sphinx permalink behaviour as per the matplotlib gallery. Assumedly you were also able to build the docs locally and they don't seem to have failed on Travis, so is this problem local to me?