Skip to content

Heading anchor slug does not respect GitHub behavior due to emojisΒ #9194

@slorber

Description

@slorber

Heading anchor slug does not respect GitHub behavior due to emojis

Discussed in #9193

Considering the heading ## :smiley: This is a friendly header

Our slugger package is supposed to align with GitHub and seems to work as intended (the input heading string is not supposed to contain the leading space):

    expect(slugger.slug(' This is a friendly header')).toBe(
      '-this-is-a-friendly-header',
    );
    expect(slugger.slug('This is a friendly header')).toBe(
      'this-is-a-friendly-header',
    );
    expect(slugger.slug(' :smiley: This is a friendly header')).toBe(
      '-smiley-this-is-a-friendly-header',
    );
    expect(slugger.slug(':smiley: This is a friendly header')).toBe(
      'smiley-this-is-a-friendly-header',
    );

    // Yes, that's how GitHub behave in this case
    expect(slugger.slug('πŸ˜ƒ This is a friendly header')).toBe(
      '-this-is-a-friendly-header',
    );

The MDX Playground shows the heading is parsed this way, and it's the value we pass to our slugger:

{
      "type": "heading",
      "depth": 2,
      "children": [
        {
          "type": "text",
          "value": ":smiley: This is a friendly header"
        }
      ]
    }

What I understand:

We should probably use node-emoji to "unconvert the value" before passing it to the slugger.

import * as emoji from https://github.com/omnidan/node-emoji,

slugger.slug(emoji.unemojify('πŸ˜ƒ This is a friendly header'));

The problem is that we shouldn't always unemojify πŸ˜…

If you look at the GitHub behavior, it has a different slugging behavior if we use πŸ˜ƒ or :smiley: in a heading:
See https://gist.github.com/slorber/9c499bb934434a3f7ac6603eff6647d3#-this-is-a-friendly-header-real-smiley
We should align to this behavior, but I'm not sure how πŸ˜…

The solution would be to get the "original" heading string value before remark-emoji gets applied. I'm not sure remark-emoji outputs that original value currently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executiongood first issueIf you are just getting started with Docusaurus, this issue should be a good place to begin.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions