Fix Remarkup generation of Table of Contents links
Summary:
See T2333. When a Phriction document includes a header like this:
= [[ Engineering ]] =
...we currently render it as "2Z" (or similar) in the table of contents. There are two problems:
- We don't restore stored blocks inside the ToC text, so we end up with a placeholder value ("2Z") instead of the right text.
- Once that's fixed, we render <h1><a href="#engineering"><a href="/w/engineering/">Engineering</a></a></h1>.
To fix the first problem, I allowed text to be restored explicitly, and restored the blocks inside the text before storing it. This bascially just involves decoupling "restore text" from "destroy storage", and letting "restore text" be called multiple times before we destroy storage (we don't really even need to destroy storage, it's just a little cleaner to do so). I think this part is pretty straightforward.
To fix the second problem, I hacked a bit more. I added pushState(), popState() and getState() to the engine, and push a "toc" state before we render the headers. Then all the rules which render links check for "toc" state (meaning, "we are currently rendering the table of contents") and render text instead of links. This feels a bit odd, but I don't see any cleaner alternatives. One possibility would be to simply disallow links in headers, but this would run counter to user expectations, and T2333 shows one install using them in the wild.
Test Plan:
Ran unit tests.
{F29888}
Reviewers: btrahan, vrana
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2333
Differential Revision: https://secure.phabricator.com/D4565