# Replace some symbol/text on typing/paste to custom NodeView

**URL:** https://discuss.prosemirror.net/t/replace-some-symbol-text-on-typing-paste-to-custom-nodeview/6532
**Category:** Uncategorized
**Created:** [June 27, 2024, 12:35pm UTC](https://discuss.prosemirror.net/t/replace-some-symbol-text-on-typing-paste-to-custom-nodeview/6532 "2024-06-27T12:35:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![SirrioN](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/sirrion/32/4144_2.png) [@SirrioN](https://discuss.prosemirror.net/u/SirrioN)
#### Post date: [June 27, 2024, 12:35pm UTC](https://discuss.prosemirror.net/t/replace-some-symbol-text-on-typing-paste-to-custom-nodeview/6532/1 "2024-06-27T12:35:27Z")

</div>

Hi! I need to replace pasted or typed emoji to some custom NodeView and don’t understand how to do it -\_- What i tryed: create NodeView `class EmojiView { this.dom = 'some HTML' }` then declare it in nodeViews

```auto
new EditorView(htmlEl, {
	state: EditorState.create(proseMirrorEditorConfig),
	nodeViews: {
		emoji: new EmojiView ()
	},
});

```

In schema declare node with type ‘emoji’

```auto
new Schema({
	nodes: { emoji: { ... } }
} 

```

declare InputRule with [emojiRegex](https://github.com/mathiasbynens/emoji-regex)

```auto
new InputRule(emojiRegex(), function emojiHandler(state, match, start, end) {
	return state.tr.replaceWith(start, enf, proseMirrorSchema.nodes.emoji.createChecked());
}),

```

In this case, when i type emoji symbol in editor, emoji disapearse, but new node not rendered (just empty editor)

If i move node to mark in scheme (`new Schema({ marks: { emoji: {} } `) and change return of InputRule to `return state.tr.addMark(start, end, proseMirrorSchema.marks.emoji.create());`, then my EmojiView is rendred, but inside it inserted content (emoji symbol) and i need to prevent this

Maybe someone cann help with this?

---

<div class="post-metadata">

### Author: ![ViktorVaczi](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/viktorvaczi/32/1919_2.png) [@ViktorVaczi](https://discuss.prosemirror.net/u/ViktorVaczi)
#### Post date: [July 2, 2024, 1:19pm UTC](https://discuss.prosemirror.net/t/replace-some-symbol-text-on-typing-paste-to-custom-nodeview/6532/2 "2024-07-02T13:19:11Z")

</div>

The NodeView is a bit orgthogonal to your issue. If the `emoji` node exsist in a doc and you have a NodeView that displays it then you’re good.

First check if the `emoji` node exists in your state.doc. If it doesn’t then start digging in `emojiHandler`.

If it does then check EmojiView, take a look at what it renders / logs etc.

`Node` is okay, you don’t want a `Mark` for this.

---

<div class="post-metadata">

### Author: ![SirrioN](https://discuss.prosemirror.net/user_avatar/discuss.prosemirror.net/sirrion/32/4144_2.png) [@SirrioN](https://discuss.prosemirror.net/u/SirrioN)
#### Post date: [July 2, 2024, 1:41pm UTC](https://discuss.prosemirror.net/t/replace-some-symbol-text-on-typing-paste-to-custom-nodeview/6532/3 "2024-07-02T13:41:57Z")

</div>

Thank you for answer!

I allready find a mistake.

I just not mark my node as inline, when i did this - all starts to work like a charm

So my final node looks like this

```auto
emoji: {
	attrs: { emoji: {} },
	inline: true,
	group: 'inline',
	draggable: false,
	atom: false,
	selectable: false,

	toDOM: (node): DOMOutputSpec => {
		const dom = document.createElement('span');
		dom.textContent = node.attrs['emoji'];
		return {
			dom,
		};
	},
	parseDOM: [
		{
			tag: 'emoji-ui',
			getAttrs: (dom): false | Attrs | null => {
				const emoji = dom.getAttribute('data-emoji');
				return emoji ? { emoji } : false;
			},
		},
	],
	leafText: (node): string => node.attrs['emoji'],
},

```
