You can clone with
HTTPS or Subversion.
Now that the headers are all sane, there is no noeed for so much jiggery pokery.
Simplify a bit.
Update HTML generation for new verson of dicsount.
Move TOC generation and cleanup to an external script that's easier to maintain.