2

There's a glitch that I've noticed in GitHub markdown, the VSCode markdown extension and other places too. It's behaving particularly unusually on GitHub and using git.

Very frequently when I type in headings such as # heading or ## sub-heading, the heading does not render correctly. Here is an example commit for a markdown file:

Source diff:

Rich diff:

As you can see, the rich diff isn't rendering correctly, and so isn't the file when I go into "browse files" (regardless of what computer/device I use):

Somehow, after deleting the space character after ### and re-typing it, there were changes to be committed. From my knowledge this shouldn't happen (because nothing has actually changed, I just re-typed the space character). But I committed it anyways and got the following diff:

As you can see the space character is highlighted. Now I magically get the following rich diff, which is now showing the heading:

And now, when I "browse files", the heading shows on every computer I use:

This is happening to my a lot, and I'm wondering why this is happening, how git is even able to commit no change, and if there is a way to solve this?

This is definitely not just me because others have mentioned this to me too in the past.

Note: My GitHub repo is private so I can't share a link, but it should be easy to reproduce.

Update

I opened the revision with the issue inside HxD and got the following hex output:

I then replaced the space character inside VSCode and got the following hex output:

There's an extra  character that is not shown in VSCode and that I didn't input. I've had this problem on both Windows and Mac OS.

Update 2

Both ascii and utf-8 define the character as  so I can't figure out why it's not showing up in VSCode or GitHub text editor.

I've also seen ascii defining it as the following on https://www.asciitable.com/

David Callanan
  • 5,601
  • 7
  • 63
  • 105
  • _“how git is even able to commit no change”_ – Well, the thing is that there **is** a difference as you can see from the fact that there is a diff. It’s likely that the space between the `###` and the title isn’t a normal space which could also be the reason why the Markdown parser doesn’t pick it up as a heading. Can you copy/paste the exact string so we can check what actual character is used there? You can also open the file in a hex editor and look at the actual bytes that are in there to figure out what character there actually is. – poke Jul 21 '19 at 20:20
  • \xa0 is "non breaking space" which is I guess not recognized by github's markdown as a valid space character in a header – anthony sottile Jul 21 '19 at 21:43

2 Answers2

5

The byte sequence 0xC2 0xA0 is the UTF-8 sequence of for the character U+00A0 NO-BREAK SPACE. So it is a non-breaking space character which explains why it is looking like a space in editors and shows up as a difference when compared to a simple space.

The fact that it shows up as  within the hex editor is simply because hex editors only ever display ASCII in the text representation since they only look at a single byte at a time. So they don’t look for character sequences like this which is required for UTF-8 to encode characters outside of the ASCII space.

As for why the non-breaking space breaks the Markdown parser, this is expected if the parser conforms to the CommonMark specification. According to it, the ATX headings are required to be followed by a space, where a space is explicitly defined to be a U+0020 SPACE character.

poke
  • 369,085
  • 72
  • 557
  • 602
  • Thanks for your answer. I'm still confused as to why VSCode and GitHub markdown editor randomly decide to insert a "non-breaking space" instead of a normal space from time to time. – David Callanan Jul 22 '19 at 18:48
  • 2
    @DavidCallanan I have just realised why this is happening to me at least - the keybind to insert a non-breaking space on Mac OS is just Option+space, which means that if you accidentally hold Option after doing Option+3 to create a markdown heading #, you insert a non-breaking space by mistake. – David Gregory Jun 06 '22 at 13:48
-2

Another cause may be an improperly named file or missing .md file extension.