> ## Documentation Index
> Fetch the complete documentation index at: https://superdoc-caio-pizzol-docs-ai-core-preset.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ContentBlock extension

export const SourceCodeLink = ({extension, path}) => {
  const githubPath = path || `packages/super-editor/src/editors/v1/extensions/${extension.toLowerCase()}`;
  const githubUrl = `https://github.com/superdoc-dev/superdoc/tree/main/${githubPath}`;
  return <div>
      <p>
        <a href={githubUrl} target="_blank" rel="noopener noreferrer">
          View on GitHub →
        </a>
      </p>
    </div>;
};

export const SuperDocEditor = ({html = '<p>Start editing...</p>', height = '400px', maxHeight = '400px', onReady = null, showExport = true, customButtons = null}) => {
  const [ready, setReady] = useState(false);
  const editorRef = useRef(null);
  const containerIdRef = useRef(`editor-${Math.random().toString(36).substr(2, 9)}`);
  const DEV_DIST_URL = 'http://localhost:9094/dist';
  const UNPKG_DIST_URL = 'https://unpkg.com/superdoc@latest/dist';
  const getBaseUrl = async () => {
    const isDev = typeof window !== 'undefined' && window.location.hostname === 'localhost';
    if (isDev) {
      try {
        const res = await fetch(`${DEV_DIST_URL}/superdoc.min.js`, {
          method: 'HEAD'
        });
        if (res.ok) {
          console.info('[SuperDoc Docs] Using local build from', DEV_DIST_URL);
          return DEV_DIST_URL;
        }
        console.warn('[SuperDoc Docs] Local dev server returned', res.status, '- falling back to unpkg');
      } catch (err) {
        console.warn('[SuperDoc Docs] Local dev server not reachable: falling back to unpkg.', 'Run `pnpm dev:docs` from the repo root to use your local build.', err.message);
      }
    }
    return UNPKG_DIST_URL;
  };
  const ensureStyle = baseUrl => {
    const styleHref = `${baseUrl}/style.css`;
    if (document.querySelector(`link[href="${styleHref}"]`)) return;
    const link = document.createElement('link');
    link.rel = 'stylesheet';
    link.href = styleHref;
    document.head.appendChild(link);
  };
  const loadSuperDoc = baseUrl => {
    if (window.SuperDoc) return Promise.resolve();
    const scriptSrc = `${baseUrl}/superdoc.min.js`;
    const existingScript = document.querySelector(`script[src="${scriptSrc}"]`);
    if (existingScript) {
      if (window.SuperDoc) return Promise.resolve();
      return new Promise((resolve, reject) => {
        existingScript.addEventListener('load', resolve, {
          once: true
        });
        existingScript.addEventListener('error', reject, {
          once: true
        });
      });
    }
    return new Promise((resolve, reject) => {
      const script = document.createElement('script');
      script.src = scriptSrc;
      script.onload = resolve;
      script.onerror = reject;
      document.body.appendChild(script);
    });
  };
  const initEditor = () => {
    setTimeout(() => {
      if (!window.SuperDoc) return;
      if (!document.getElementById(containerIdRef.current)) return;
      if (editorRef.current) return;
      editorRef.current = new window.SuperDoc({
        selector: `#${containerIdRef.current}`,
        html,
        rulers: true,
        contained: true,
        onReady: () => {
          setReady(true);
          if (onReady) onReady(editorRef.current);
        }
      });
    }, 100);
  };
  useEffect(() => {
    let cancelled = false;
    const boot = async () => {
      try {
        const baseUrl = await getBaseUrl();
        ensureStyle(baseUrl);
        await loadSuperDoc(baseUrl);
        if (!cancelled) initEditor();
      } catch (error) {
        console.error('Failed to boot SuperDoc:', error);
      }
    };
    boot();
    return () => {
      cancelled = true;
      editorRef.current?.destroy?.();
      editorRef.current = null;
    };
  }, []);
  const exportDocx = () => {
    if (editorRef.current?.export) {
      editorRef.current.export();
    }
  };
  return <div className="border rounded-lg bg-white overflow-hidden">
      {ready && (showExport || customButtons) && <div className="px-3 py-2 bg-gray-50 border-b">
          {customButtons && <div className="space-y-1 mb-2">
              {customButtons.map((row, rowIndex) => <div key={rowIndex} className="flex gap-1">
                  {row.map((btn, i) => <button key={i} onClick={() => btn.onClick(editorRef.current)} className={btn.className || 'flex-1 px-2 py-1 bg-gray-100 text-gray-700 text-xs rounded hover:bg-gray-200'}>
                      {btn.label}
                    </button>)}
                </div>)}
            </div>}
          {showExport && <div className="text-right">
              <button onClick={exportDocx} className="px-3 py-1 bg-blue-500 text-white text-xs rounded hover:bg-blue-600">
                Export DOCX
              </button>
            </div>}
        </div>}
      <div id={containerIdRef.current} style={{
    height,
    maxHeight,
    paddingLeft: '5px'
  }} />
      <style jsx>{`
        #${containerIdRef.current} .superdoc__layers {
          max-width: 660px !important;
        }
        #${containerIdRef.current} .super-editor {
          max-width: 100% !important;
          width: 100% !important;
          color: #000;
        }
        #${containerIdRef.current} .editor-element {
          width: 100% !important;
          min-width: unset !important;
          transform: none !important;
        }
        #${containerIdRef.current} .editor-element {
          h1,
          h2,
          h3,
          h4,
          h5,
          strong {
            color: #000;
          }
        }
      `}</style>
    </div>;
};

Flexible inline blocks for horizontal rules, spacers, and custom dividers.

Preserves special Word content like shapes and drawings through import/export.

<SuperDocEditor
  html={`<p>Content blocks create visual breaks and spacing in your document.</p><div data-type="contentBlock" style="width: 100%; height: 2px; background-color: #e5e7eb;" data-horizontal-rule="true"></div><p>They can be horizontal rules, spacers, or custom dividers.</p><div data-type="contentBlock" style="width: 50%; height: 3px; background-color: #3b82f6;"></div><p>Use them to organize content visually.</p>`}
  height="300px"
  customButtons={[
[
  {
    label: '─ Horizontal Rule',
    onClick: (superdoc) => {
      const editor = superdoc?.activeEditor || superdoc?.editor
      if (!editor?.commands) return
      editor.commands.insertHorizontalRule()
    }
  },
  {
    label: '▭ Spacer (20px)',
    onClick: (superdoc) => {
      const editor = superdoc?.activeEditor || superdoc?.editor
      if (!editor?.commands) return
      editor.commands.insertContentBlock({ 
        size: { height: 20, width: '100%' } 
      })
    }
  },
  {
    label: '━ Thick Blue',
    onClick: (superdoc) => {
      const editor = superdoc?.activeEditor || superdoc?.editor
      if (!editor?.commands) return
      editor.commands.insertContentBlock({
        size: { width: '100%', height: 4 },
        background: '#2563eb'
      })
    }
  }
],
[
  {
    label: '▬ 50% Red',
    onClick: (superdoc) => {
      const editor = superdoc?.activeEditor || superdoc?.editor
      if (!editor?.commands) return
      editor.commands.insertContentBlock({
        size: { width: '50%', height: 2 },
        background: '#dc2626'
      })
    }
  },
  {
    label: '■ Block (100x50)',
    onClick: (superdoc) => {
      const editor = superdoc?.activeEditor || superdoc?.editor
      if (!editor?.commands) return
      editor.commands.insertContentBlock({
        size: { width: 100, height: 50 },
        background: '#f3f4f6'
      })
    }
  },
  {
    label: '• • • Dotted',
    onClick: (superdoc) => {
      const editor = superdoc?.activeEditor || superdoc?.editor
      if (!editor?.commands) return
      editor.commands.insertContentBlock({
        size: { width: '100%', height: 1 },
        background: 'repeating-linear-gradient(90deg, #6b7280 0px, #6b7280 5px, transparent 5px, transparent 10px)'
      })
    }
  }
]
]}
/>

## OOXML Structure

```xml theme={null}
<!-- Horizontal Rule -->
<w:p>
  <w:r>
    <w:pict>
      <v:rect style="width:100%;height:2px" 
              fillcolor="#e5e7eb"
              stroked="f"/>
    </w:pict>
  </w:r>
</w:p>
```

## Use case

* **Section Breaks** - Visually separate different parts of your document
* **Horizontal Rules** - Classic divider between content sections
* **Spacers** - Add precise vertical spacing without empty paragraphs
* **Custom Dividers** - Brand-colored separators for professional documents
* **Shape Preservation** - Maintains Word shapes and drawings through import/export
* **Layout Control** - Fine-tune document appearance with inline blocks

## Options

Configure the extension behavior:

<ParamField path="htmlAttributes" type="Object">
  HTML attributes for the block element
</ParamField>

## Attributes

Node attributes that can be set and retrieved:

<ParamField path="horizontalRule" type="boolean" default="false">
  Whether this block is a horizontal rule
</ParamField>

<ParamField path="size" type="ContentBlockSize">
  Size and position of the content block
</ParamField>

<ParamField path="background" type="string">
  Background color for the block
</ParamField>

## Commands

### `insertHorizontalRule`

Insert a horizontal rule

<Note>
  Creates a visual separator between content sections
</Note>

**Example:**

<CodeGroup>
  ```javascript Usage theme={null}
  editor.commands.insertHorizontalRule()
  ```

  ```javascript Full Example theme={null}
  import { SuperDoc } from 'superdoc';
  import 'superdoc/style.css';

  const superdoc = new SuperDoc({
    selector: '#editor',
    document: yourFile,
    onReady: (superdoc) => {
      const editor = superdoc.activeEditor;
      editor.commands.insertHorizontalRule()
    },
  });
  ```
</CodeGroup>

### `insertContentBlock`

Insert a content block

<Note>
  Used for spacing, dividers, and special inline content
</Note>

**Example:**

<CodeGroup>
  ```javascript Usage theme={null}
  // Insert a spacer block
  editor.commands.insertContentBlock({ size: { height: 20 } })
  ```

  ```javascript Full Example theme={null}
  import { SuperDoc } from 'superdoc';
  import 'superdoc/style.css';

  const superdoc = new SuperDoc({
    selector: '#editor',
    document: yourFile,
    onReady: (superdoc) => {
      const editor = superdoc.activeEditor;
      // Insert a spacer block
      editor.commands.insertContentBlock({ size: { height: 20 } })
    },
  });
  ```
</CodeGroup>

**Parameters:**

<ParamField path="config" type="ContentBlockConfig" required>
  Block configuration
</ParamField>

## Types

### `ContentBlockSize`

Size configuration for content blocks

<Expandable title="Properties">
  <ResponseField name="top" type="number">
    Top position in pixels
  </ResponseField>

  <ResponseField name="left" type="number">
    Left position in pixels
  </ResponseField>

  <ResponseField name="width" type="number | string">
    Width in pixels or percentage (e.g., "50%")
  </ResponseField>

  <ResponseField name="height" type="number | string">
    Height in pixels or percentage
  </ResponseField>
</Expandable>

### `ContentBlockConfig`

Content block configuration

<Expandable title="Properties">
  <ResponseField name="horizontalRule" type="boolean">
    Whether this is a horizontal rule
  </ResponseField>

  <ResponseField name="size" type="ContentBlockSize">
    Size and position configuration
  </ResponseField>

  <ResponseField name="background" type="string">
    Background color (hex, rgb, or named color)
  </ResponseField>
</Expandable>

## Source code

<SourceCodeLink path="packages/super-editor/src/editors/v1/extensions/content-block/content-block.js" />
