Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
This commit is contained in:
parent
41c5f94fbf
commit
fa9c418e21
11 changed files with 136 additions and 101 deletions
|
@ -3,6 +3,7 @@ import {
|
|||
mergeAttributes,
|
||||
nodeInputRule,
|
||||
} from '@tiptap/core'
|
||||
import { emojiRegEx, getEmojiAttributes } from '~/config/emojis'
|
||||
|
||||
export const Emoji = Node.create({
|
||||
name: 'em-emoji',
|
||||
|
@ -14,35 +15,35 @@ export const Emoji = Node.create({
|
|||
parseHTML() {
|
||||
return [
|
||||
{
|
||||
tag: 'em-emoji[native]',
|
||||
tag: 'img.iconify-emoji',
|
||||
},
|
||||
]
|
||||
},
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
native: {
|
||||
alt: {
|
||||
default: null,
|
||||
},
|
||||
fallback: {
|
||||
src: {
|
||||
default: null,
|
||||
},
|
||||
class: {
|
||||
default: null,
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
renderHTML(args) {
|
||||
return ['em-emoji', mergeAttributes(this.options.HTMLAttributes, args.HTMLAttributes)]
|
||||
return ['img', mergeAttributes(this.options.HTMLAttributes, args.HTMLAttributes)]
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
insertEmoji: name => ({ commands }) => {
|
||||
insertEmoji: code => ({ commands }) => {
|
||||
return commands.insertContent({
|
||||
type: this.name,
|
||||
attrs: {
|
||||
native: name,
|
||||
fallback: name,
|
||||
},
|
||||
attrs: getEmojiAttributes(code),
|
||||
})
|
||||
},
|
||||
}
|
||||
|
@ -50,14 +51,11 @@ export const Emoji = Node.create({
|
|||
|
||||
addInputRules() {
|
||||
const inputRule = nodeInputRule({
|
||||
find: EMOJI_REGEX,
|
||||
find: emojiRegEx as RegExp,
|
||||
type: this.type,
|
||||
getAttributes: (match) => {
|
||||
const [native] = match
|
||||
return {
|
||||
native,
|
||||
fallback: native,
|
||||
}
|
||||
return getEmojiAttributes(native)
|
||||
},
|
||||
})
|
||||
// Error catch for unsupported emoji
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue