Skip to content

Emojis can cause broken result #68

New issue

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

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

Already on GitHub? # to your account

Open
4 tasks done
craftzdog opened this issue Mar 11, 2025 · 1 comment
Open
4 tasks done

Emojis can cause broken result #68

craftzdog opened this issue Mar 11, 2025 · 1 comment
Labels
🤞 phase/open Post is being triaged manually

Comments

@craftzdog
Copy link

craftzdog commented Mar 11, 2025

Initial checklist

Affected package

mdast-util-to-markdown@2.1.2

Steps to reproduce

const mdast = {
  type: 'root',
  children: [
    {
      type: 'paragraph',
      children: [
        {
          type: 'text',
          value: '💡',
          position: {
            start: {
              line: 8,
              column: 10,
              offset: 113
            },
            end: {
              line: 8,
              column: 12,
              offset: 115
            }
          }
        },
        {
          type: 'strong',
          children: [
            {
              type: 'text',
              value: ' Some tex',
              position: {
                start: {
                  line: 8,
                  column: 20,
                  offset: 123
                },
                end: {
                  line: 8,
                  column: 29,
                  offset: 132
                }
              }
            }
          ],
          position: {
            start: {
              line: 8,
              column: 12,
              offset: 115
            },
            end: {
              line: 8,
              column: 38,
              offset: 141
            }
          }
        },
        {
          type: 'text',
          value: 't',
          position: {
            start: {
              line: 8,
              column: 38,
              offset: 141
            },
            end: {
              line: 8,
              column: 39,
              offset: 142
            }
          }
        }
      ],
      position: {
        start: {
          line: 8,
          column: 7,
          offset: 110
        },
        end: {
          line: 8,
          column: 43,
          offset: 146
        }
      }
    }
  ],
  position: {
    start: {
      line: 1,
      column: 1,
      offset: 0
    },
    end: {
      line: 12,
      column: 1,
      offset: 176
    }
  }
}
const md = toMarkdown(mdast)
console.log('md:', md)

Actual behavior

��** Some tex**t

Expected behavior

💡** Some tex**t

Runtime

node@23.6.1

Package manager

npm@10.9.2

Operating system

macOS Sequoia 15.3.1

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Mar 11, 2025
@craftzdog
Copy link
Author

In container-phrasing.js, it uses slice() many times, but it can break emojis.
A workaround would be to use Array.from, something like:

> Array.from('👩‍👩‍👧‍👦')
[
  '👩', '‍',   '👩',
  '‍',   '👧', '‍',
  '👦'
]

> '👩‍👩‍👧‍👦'.split('')
[
  '\ud83d', '\udc69',
  '‍',       '\ud83d',
  '\udc69', '‍',
  '\ud83d', '\udc67',
  '‍',       '\ud83d',
  '\udc66'
]

> '👩‍👩‍👧‍👦'.slice(-1)
'\udc66'
> Array.from('👩‍👩‍👧‍👦').slice(-1).toString()
'👦'
>

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
🤞 phase/open Post is being triaged manually
Development

No branches or pull requests

1 participant