I don't think framework is the only template mechanism that would be affected by this. I'm not sure how you would better detect which src's to change without negatively impacting one that should be replaced and is not. As you know, I am more concerned that it detect links that are site root relative and not change those (ignore src="/dir/file.php").
I suppose another fix would be to put this code in an external file.
Thanks for looking into it.