Handle inner CodeMirror modes and update PHP mode handling in HTMLUtils

Fixes #2563.