Improve the text template tokenizer

Closes #219