I don’t think there is really any ambiguity. “An ATX header consists of a string of characters, parsed as inline content, between an opening sequence of 1–6 unescaped # characters and an optional closing sequence of any number of # characters.” So we need to ask whether
#\#
in your example counts as “an optional closing sequence of any number of # characters.” Example 36 does not show that “escaping closing sequences is valid”; it is meant to illustrate the explicit statement in the spec that “backslash-escaped # characters do not count as part of the closing sequence.” So, given what the spec says, the ending sequence in your example is not a closing sequence of # characters.
I think this is a bug in the js implementation. (The C implementation gets it right.) And it shows we need an example in the spec like yours. Can you submit this as an issue on the stmd issue tracker?
Well, the spec explicitly says that backslash-escaped # characters are
not counted as part of the closing sequence. So, the final # is not
a closing sequence.