# एक्सटेंशन ऑब्जेक्ट बनाएँ {#extension-object}

Source: [एक्सटेंशन ऑब्जेक्ट बनाएँ | React एडिटर के लिए कस्टम एक्सटेंशन बनाएँ · Yurich](https://leeyujoo.com/yurich/hi/extensions/extension-object/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

ऐट्रिब्यूट, एक से ज़्यादा कमांड या अपनी सक्रिय स्थिति के लिए `Extension` ऑब्जेक्ट इस्तेमाल करें। इस उदाहरण में `<cite>` टैग पर अंकों वाला पहचानकर्ता सेव होता है।

**@Ada** चुनें और **मेंशन जोड़ें** दबाएँ। HTML आउटपुट में `<cite data-id="42">@Ada</cite>` दिखेगा।

```tsx
import { EditorContent, EditorProvider, useEditor, type Extension } from 'yurich';

export const Mention: Extension = {
  name: 'mention',
  marks: [{
    tag: 'cite',
    type: 'mention',
    attrs: {
      'data-id': value => value && /^\d+$/.test(value) ? value : null,
    },
  }],
  commands: {
    setMention(editor, value) {
      if (typeof value === 'string' && /^\d+$/.test(value)) {
        editor.setMark('cite', { 'data-id': value });
      }
    },
    removeMention(editor) {
      editor.removeMark('cite');
    },
  },
  isActive: editor => editor.isMarkActive('cite'),
};

export function MentionEditor() {
  const editor = useEditor({
    extensions: [Mention],
    initialValue: "<p>@Ada से बोल्ड बटन आज़माने को कहें।</p>",
  });

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('setMention', '42')}
      >
        मेंशन जोड़ें
      </button>
      <EditorContent ariaLabel="एडिटर" />
    </EditorProvider>
  );
}
```

`Mention` को एक्सटेंशन सूची में जोड़ें। टेक्स्ट चुनकर `editor.execute('setMention', '42')` चलाएँ और `editor.getHTML()` से नतीजा देखें। टूलबार की स्थिति के लिए `useIsActive(editor, 'mention')` इस्तेमाल करें।

[एक्सटेंशन की जाँच करें](https://leeyujoo.com/yurich/hi/extensions/verify/)
