I think its because razor consumes the <script part and only passes the rest > ... <script to html. It should use a lookahead instead of a capture.
<script
> ... <script
heres some bug reports: