reddit/reddit — pull request #653 by andre-d (2013-01-30 04:27:59+00:00)
Title: wikitoc: Fix some headers ending up at the wrong level.

The assumption was made that when a header ended it would go down one level, this code corrects that and goes down as many levels as it needs to in order to match the header tag level of the parent.

Example input:
# Level 1

## Level 2

### Level 3

# Level 1

The last Level 1 would end up being a level 2 in the table of contents