For example, when removing {{text}} from
word1 {{text|word2}} word3
the new revision should be:
word1 word3
instead of the current behaviour which is:
word1 word3
See this diff as an example of current script in action. As you can see, a new empty line is remained after the removal of the template.