Skip to content

Commit 3adb61e

Browse files
committed
fix: πŸ› should not throw error when emoji in code
βœ… Closes: #1264
1 parent b1cda6b commit 3adb61e

File tree

6 files changed

+81
-2
lines changed

6 files changed

+81
-2
lines changed

Diff for: β€Že2e/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"@milkdown/ctx": "workspace:*",
3232
"@milkdown/plugin-automd": "workspace:*",
3333
"@milkdown/plugin-clipboard": "workspace:*",
34+
"@milkdown/plugin-emoji": "workspace:*",
3435
"@milkdown/plugin-history": "workspace:*",
3536
"@milkdown/plugin-listener": "workspace:*",
3637
"@milkdown/plugin-math": "workspace:*",

Diff for: β€Že2e/src/plugin-emoji/main.stories.ts

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/* Copyright 2021, Milkdown by Mirone. */
2+
import type { Meta, StoryObj } from '@storybook/html'
3+
import { Editor, defaultValueCtx, rootCtx } from '@milkdown/core'
4+
import { nord } from '@milkdown/theme-nord'
5+
import { commonmark } from '@milkdown/preset-commonmark'
6+
import { history } from '@milkdown/plugin-history'
7+
import { emoji } from '@milkdown/plugin-emoji'
8+
9+
import '@milkdown/theme-nord/style.css'
10+
11+
import '../style.css'
12+
13+
interface Args {
14+
enableInspector: boolean
15+
defaultValue: string
16+
instance: Editor
17+
}
18+
19+
const meta: Meta<Args> = {
20+
title: 'Emoji/Main',
21+
}
22+
23+
export default meta
24+
25+
type Story = StoryObj<Args>
26+
27+
export const Empty: Story = {
28+
render: (args) => {
29+
const root = document.createElement('div')
30+
const editor = Editor.make()
31+
.enableInspector(args.enableInspector ?? false)
32+
.config((ctx) => {
33+
ctx.set(defaultValueCtx, args.defaultValue ?? '')
34+
ctx.set(rootCtx, root)
35+
})
36+
.config(nord)
37+
.use(commonmark)
38+
.use(history)
39+
.use(emoji)
40+
.create()
41+
42+
editor.then((instance) => {
43+
args.instance = instance
44+
})
45+
46+
return root
47+
},
48+
}
49+
50+
const defaultValue = `
51+
# Milkdown
52+
53+
πŸ«₯
54+
55+
:+1:
56+
`
57+
58+
export const WithDefaultValue: Story = {
59+
...Empty,
60+
args: {
61+
defaultValue: defaultValue.trim(),
62+
},
63+
}

Diff for: β€Že2e/src/preset-commonmark/commands.stories.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const ToggleStrong: Story = {
6161

6262
await expect(args.instance.action(getMarkdown())).toContain(`**${text}**`)
6363

64-
const strong = canvasElement.querySelector('strong')
64+
const strong = canvasElement.querySelector('strong') ?? undefined
6565

6666
await expect(strong).toHaveTextContent(text)
6767
await userEvent.pointer([{ target: strong, offset: 0, keys: '[MouseLeft>]' }, { offset: text.length }])
@@ -91,7 +91,7 @@ export const ToggleItalic: Story = {
9191

9292
await expect(args.instance.action(getMarkdown())).toContain(`*${text}*`)
9393

94-
const em = canvasElement.querySelector('em')
94+
const em = canvasElement.querySelector('em') ?? undefined
9595

9696
await expect(em).toHaveTextContent(text)
9797
await userEvent.pointer([{ target: em, offset: 0, keys: '[MouseLeft>]' }, { offset: text.length }])

Diff for: β€Že2e/src/style.css

+8
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,11 @@ input:focus {
2020
outline: none;
2121
box-shadow: none;
2222
}
23+
24+
span[data-type='emoji'] {
25+
@apply inline-block;
26+
}
27+
28+
span[data-type='emoji'] .emoji {
29+
@apply w-4;
30+
}

Diff for: β€Žpackages/plugin-emoji/src/__internal__/remark-twemoji.ts

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export const twemojiPlugin: RemarkPluginRaw<TwemojiOptions> = (twemojiOptions) =
4141
if (!isLiteral(node))
4242
return [node]
4343

44+
// Should not convert code block
45+
if (node.type === 'code')
46+
return [node]
47+
4448
const value = node.value
4549
const output: Array<Node & { value: string }> = []
4650
let match

Diff for: β€Žpnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
Β (0)