Improve detection of pre, style and script tags containing an empty line

Considering the following 2 snippets:

<script>
    Foo
 
    Bar
</script>
<div>
  <script>
    Foo
 
    Bar
  </script>
</div>

Which are rendered respectively as:

<script>
    Foo
 
    Bar
</script>
<div>
  <script>
    Foo
<pre><code>Bar
</code></pre>
  </script>
</div>

I’d say that the script tag isn’t detected properly.

The first rule for detecting HTML blocks, here, seems designed explicitly for supporting the case where empty new lines are found inside pre, style and script tags.

But it breaks down as soon as we wrap that script in any another tag that is not a pre, style or script tag.

Since no human nor any HTML parser would not properly parse the script tag in the second snippet I posted I propose to fix this.

Maybe a good enough rule to fix this would be that if we are inside pre, style and script tags then their specific exit condition rule takes precedence over any other rules.

What do you think?

Here’s the original issue: https://github.com/commonmark/commonmark-spec/issues/597

To move the suggestion here, as mentioned in commonmark/commonmark-spec#issuecomment-515618751, something which would address this case would be the following:

One idea for making this parse more “intuitively” might be to reassess the start condition on lines that don’t meet the end condition and adjust the HTML block type accordingly in some order of precedence.
E.g. if a subsequent line of a type 6 or 7 HTML block (which don’t have, let’s say “intuitive”, end conditions in some cases) could start a type 1 through 5 HTML block then the HTML block will change to the respective type. Another way to phrase this might be that HTML blocks of type 1 through 5 may interrupt a type 6 or 7 HTML block.