# Ekspor HTML dan JSON {#html-and-json}

Source: [Ekspor HTML dan JSON dari editor React · Yurich](https://leeyujoo.com/yurich/id/features/html-and-json/)

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

Package version: `0.1.2`

Simpan HTML editabel dan baca JSON terstruktur.

## Coba sendiri {#try-it}

Klik **Ekspor**. Callback menerima HTML dan mark `bold` pada keluaran JSON.

## Tambahkan ke editor {#setup}

Simpan HTML dengan `getHTML()`. Gunakan `getJSON()` untuk keluaran terstruktur.

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

export function ExportEditor({ onSave }: {
  onSave: (draft: { html: string; json: DocumentJSON }) => void;
}) {
  const editor = useEditor({
    extensions: [Bold],
    initialValue: "<p><strong>Siap terbit</strong></p>",
  });

  return (
    <EditorProvider editor={editor}>
      <EditorContent ariaLabel="Editor" />
      <button type="button" onClick={() => onSave({
        html: editor.getHTML(),
        json: editor.getJSON(),
      })}>
        Ekspor
      </button>
    </EditorProvider>
  );
}
```

## Perilaku yang perlu diperhatikan {#behavior}

Jangan ubah JSON langsung. Muat ulang dari [HTML yang disimpan](https://leeyujoo.com/yurich/id/#save-and-restore-html).

[Fitur](https://leeyujoo.com/yurich/id/features/)
