# インライン書式を作る {#mark}

Source: [インライン書式を作る | React エディターのカスタム拡張を作る · Yurich](https://leeyujoo.com/yurich/ja/extensions/mark/)

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

Package version: `0.1.2`

`mark()` は文章の一部に書式を適用します。**Yurich** を選び、**ハイライト** を押すと、選択した単語が `<mark>` で囲まれます。

```tsx
import { mark, EditorContent, EditorProvider, useEditor, useIsActive } from 'yurich';

const Highlight = mark({ name: 'highlight', tag: 'mark', shortcut: 'Mod+Shift+H' });

export function HighlightEditor() {
  const editor = useEditor({
    extensions: [Highlight],
    initialValue: "<p>Yurich を少し目立たせてみましょう。</p>",
  });
  const active = useIsActive(editor, 'toggleHighlight');

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        aria-pressed={active}
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('toggleHighlight')}
      >
        ハイライト
      </button>
      <EditorContent ariaLabel="エディター" />
    </EditorProvider>
  );
}
```

## 結果を確認する {#result}

`editor.getHTML()` が返す HTML では、**Yurich** だけが `<mark>` で囲まれます。

```html
<p><mark>Yurich</mark> を少し目立たせてみましょう。</p>
```

以下は `editor.getJSON()` が返す文書ツリーのうち、**Yurich** に対応するテキストノードです。`marks` の `highlight` は、`mark()` で登録した書式名です。

```json
{
  "type": "text",
  "text": "Yurich",
  "marks": [{ "type": "highlight" }]
}
```

タグ名は小文字で指定します。`mark()` の `aliases` で同等の入力タグを受け付けられます。

[拡張を確認する](https://leeyujoo.com/yurich/ja/extensions/verify/)
