For example, the below fails to highlight correctly (detected as the wrong language?):

A workaround involves prefixing $ with window. which avoids $ at the start of the line which seems to disambiguate it:

Using <script type="text/javascript"> doesn't help either, FWIW.
Works fine with GitHub's syntax highlighter:
<script>
$('foo');
// This should be a comment
</script>
For context: we sprinkle a bit of <script> with some jQuery in our markdown docs to make some surgical adjustments to the markdown output, including linkifying some text in <code> blocks and such.