I suggest the following improvement: remove all this code and put it into `nikola.post.Post.text` and fix it there.