Skip to content

Consider Non-breaking space (unicode spaces) as regular spaces for formatting #675

Closed

Description

@linkdotnet

Hey,

if we have for example no-break spaces in ## (aka h2) elements, they don't get transform into <h2> elements because the library checks whether or not a "regular space" is used. A no-break space would be this: aka U+00A= (info here: https://www.compart.com/en/unicode/U+00A0)

Also GitHub does not consider them (whereas stackedit.io does recognize them).
## This should be an h2 element

If you have a Mac you can easily reproduce this with Option+SpaceBar, which produces the non-breaking space.

My request would be to include those characters as valid space-bars so that the above example would work.
I am not sure what the Markdown specification says about those "unicode spaces".

Activity

  1. MihaZupan commented on Oct 18, 2022

    @MihaZupan
    Collaborator

    I think GitHub may have stripped these characters from your example.
    Do you mean if the heading is "#\u00A0# foo"? Or ## f\u00A0oo?

    For the former, that doesn't make sense as the input, just like it wouldn't make sense with regular spaces # # foo. The spec doesn't mention that anything can be in between the # characters.

  2. linkdotnet commented on Oct 18, 2022

    @linkdotnet
    Author

    The latter example ## f\u00A0oo.
    This example "should" work: ## My h2 title.

    You can copy&paste this into a website like this, which shows you non-printable characters.
    image

  3. xoofx commented on Oct 18, 2022

    @xoofx
    Owner

    I think the spec says ## must be followed by a space or a tab (not a unicode in the space category), so if you look at all other CommonMark compliant parser here they don't parse ## foo correctly either.

    So I would say, it's constrained as per spec, and so won't fix. Thoughts @MihaZupan ?

  4. MihaZupan commented on Oct 18, 2022

    @MihaZupan
    Collaborator

    The opening sequence of # characters must be followed by spaces or tabs

    My interpretation of the spec is that same as @xoofx.
    If the spec intends for the broader interpretation of whitespace, it generally explicitly calls it whitespace or Unicode whitespace.
    Given that commonmark.js and GitHub don't support it either, I would also lean towards not changing anything in Markdig.

    In any case, you can apply the fix on your side

    markdown = markdown.Replace('\u00A0', ' ');

    or a more targeted

    markdown = markdown.Replace("#\u00A0", "# ", StringComparison.Ordinal);
  5. linkdotnet commented on Oct 18, 2022

    @linkdotnet
    Author

    Fair point. I guess for now we can close the issue. Thanks for your inputs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions