It just occurred to me that it might be possible for there to be more than one level of nesting--the CodeMirror manual page seems to imply that it's possible, and I could imagine scenarios where it could happen, though I don't know if any of them actually apply. For example, it seems like PHP mode could use htmlmixed as a submode, which might then use CSS as a submode inside `<style>` tags. (It doesn't look like PHP mode does this right now, but it probably should.)

Reading the CodeMirror manual page, it looks like it implies that you should basically chase `innerMode()` down until you don't get any more inner modes: "Use the CodeMirror.innerMode helper function to, starting from a mode and a state, recursively walk down to the innermost mode and state." 

This would probably apply anywhere we look for the current mode--e.g. the HTMLUtils case below. We might want to look for other places in the code where we get mode or state information and make sure that they're dealing with nested modes properly--if there are other such places, there might be some useful utilities we could refactor out.