Documentação

Exportação HTML e JSON

Salve HTML editável e leia JSON estruturado.

Experimente

Clique em Exportar. O callback recebe HTML e um nó de texto com a marca bold no JSON.

Exemplo interativo
Resultado do exemplo

Adicione ao seu editor

Use getHTML() para gravar um documento reabrível e getJSON() para obter dados estruturados.

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>Pode publicar</strong></p>",
  });

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

Como o recurso se comporta

Trate o JSON como imutável. O carregamento usa HTML, como em Salvar e restaurar HTML.

Recursos