If I do:
wikicode = mwparserfromhell.parse("This is\n__TOC__\nan article.")
I get back a single Text node. For what I'm doing, it would be really convenient to have the __TOC__ be parsed as it's own node, i.e. instead of a single Text node with 'This is\n__TOC__\nan article.', I'd like to get 3 Text nodes, with 'This is\n', '__TOC__', '\nan article.']
The best I've come up with so far is to pre-process the text to insert HTML comments around the __TOC__, but that's really ugly for so many reasons. The next best I've come up with is to post-process the nodes to manually split any Text node that has __TOC__ in it into 2 or 3 Text nodes, but that's really ugly for so many other reasons. Anybody have any better ideas?