Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove support for seeing non-ASCII whitespace as such #321

Closed
maximbaz opened this issue Jan 17, 2018 · 7 comments · Fixed by #424
Closed

Remove support for seeing non-ASCII whitespace as such #321

maximbaz opened this issue Jan 17, 2018 · 7 comments · Fixed by #424
Labels

Comments

@maximbaz
Copy link

maximbaz commented Jan 17, 2018

Subject of the issue

preserve leading and trailing no-break whitespaces in inline code: `   hello   `

Markdown strips regular whitespaces: hello
However it preserves non-breaking whitespaces:    hello   

Parser should also preserve non-breaking whitespaces, while stripping regular ones.

Steps to reproduce

astexplorer

Expected behaviour

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "preserve leading and trailing whitespaces in inline code: ",
        },
        {
          "type": "inlineCode",
          "value": "   hello   ",
        }
      ],
    }
  ],
}

Actual behaviour

{
  "type": "root",
  "children": [
    {
      "type": "paragraph",
      "children": [
        {
          "type": "text",
          "value": "preserve leading and trailing whitespaces in inline code: ",
        },
        {
          "type": "inlineCode",
          "value": "hello",
        }
      ],
    }
  ],
}
@wooorm
Copy link
Member

wooorm commented Jan 17, 2018

Hey @maximbaz!

I tried it on the commonmark dingus (permalinking doesn’t work for me there) and it didn’t have your result. Why do you believe markdown should act like this?

P.S. GitHub does show them: preserve leading and trailing no-break whitespaces in inline code:    hello   

@wooorm wooorm added the 🙉 open/needs-info This needs some more info label Jan 17, 2018
@maximbaz
Copy link
Author

Hey, this all started because I have a variable with trailing whitespace as a default value, and this is documented in a markdown file (example below). I noticed that Github removes the trailing whitespace, and then I was suggested to use a non-breaking whitespace because Github keeps it. However, prettier (which uses this project internally) auto-formats my markdown document and removes the trailing whitespace, which is annoying 🙂

image

Now I see that apparently multiple markdown specifications exist (of course 🤦‍♂️ ), and not all of them preserve non-breaking whitespaces... What do you usually do in such cases? Follow commonmark's specification and not github's?

@maximbaz
Copy link
Author

Actually, can it be a bug in commonmark dingus?

http://spec.commonmark.org/0.28/#code-spans

The contents of the code span are the characters between the two backtick strings, with leading and trailing spaces and line endings removed

http://spec.commonmark.org/0.28/#space

A space is U+0020.

@wooorm
Copy link
Member

wooorm commented Jan 17, 2018

It could be! I dunno?!

Anyway, unrelated to this bug, but related to your original question: what I personally do in these cases of invisible characters is use the middot characters: foo·· (where · represents a space), similar to » for tab, for \n and ␍␊ for \r\n.

@maximbaz
Copy link
Author

This is an interesting approach, thanks for sharing!

@wooorm
Copy link
Member

wooorm commented Jan 20, 2018

Could you check with commonmark to see if it’s a bug in their code / dingus?

  • If that’s a case, and they should follow GFM instead, I feel we should support this here too
  • If it’s in fact GFM not following the commonmark spec, I’m not sure we should do something here...

@maximbaz
Copy link
Author

It was easy, here's owner of commonmark repo explaining that non-breaking space should not be stripped, and this ticket in commonmark.js is describing what looks like a pretty much the same issue.

@wooorm wooorm changed the title Non-breaking whitespaces are parsed incorrectly in inline code blocks Remove support for seeing non-ASCII whitespace as such Jul 2, 2019
@wooorm wooorm added 🐛 type/bug This is a problem needs pr remark-parse and removed 🙉 open/needs-info This needs some more info labels Jul 2, 2019
wooorm added a commit that referenced this issue Jul 15, 2019
@wooorm wooorm added has pr and removed needs pr labels Jul 15, 2019
wooorm added a commit that referenced this issue Jul 15, 2019
Closes GH-321.
Closes GH-424.

Reviewed-by: Marouane Fazouane <fazouanem3@gmail.com>
Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants