Dokumentasi

Ekspor HTML dan JSON

Simpan HTML editabel dan baca JSON terstruktur.

Coba sendiri

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

Contoh interaktif
Hasil contoh

Tambahkan ke editor

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

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

Jangan ubah JSON langsung. Muat ulang dari HTML yang disimpan.

Fitur