Dokumentasi

Blok kode

Tampilkan kode beberapa baris dalam blok tersendiri.

Coba sendiri

Klik Blok kode pada contoh. Hasilnya <pre>editor.execute('toggleBold');</pre>.

Contoh interaktif
Hasil contoh

Tambahkan ke editor

Aktifkan CodeBlock dan gunakan toggleCodeBlock untuk membuat <pre>.

import { EditorContent, EditorProvider, CodeBlock, useEditor, useIsActive } from 'yurich';

export function CodeBlockEditor() {
  const editor = useEditor({
    extensions: [CodeBlock],
    initialValue: "<p>editor.execute('toggleBold');</p>",
  });
  const active = useIsActive(editor, 'toggleCodeBlock');

  return (
    <EditorProvider editor={editor}>
      <button
        type="button"
        aria-pressed={active}
        onMouseDown={event => event.preventDefault()}
        onClick={() => editor.execute('toggleCodeBlock')}
      >
        Blok kode
      </button>
      <EditorContent ariaLabel="Editor" />
    </EditorProvider>
  );
}

Perilaku yang perlu diperhatikan

Jeda baris tetap ada saat menempel teks polos di blok. Tambahkan penyorotan sintaks melalui aplikasi.

Fitur