Skip to content
On this page

Table Plugins

Marzipan provides three powerful table plugins for different use cases, from simple markdown tables to interactive grid editors.

Overview

PluginBest ForFeatures
tablePluginBasic table creationToolbar button, configurable defaults
tableGridPluginVisual table creationInteractive grid overlay
tableGeneratorPluginQuick table insertionPrompt-based sizing

All plugins generate GitHub-flavored markdown tables:

markdown
| Header 1 | Header 2 | Header 3 |
|----------|----------|----------|
| Cell 1   | Cell 2   | Cell 3   |
| Cell 4   | Cell 5   | Cell 6   |

Table Plugin

Basic table creation with toolbar integration.

Installation

ts
import { Marzipan } from '@pinkpixel/marzipan';
import { tablePlugin } from '@pinkpixel/marzipan/plugins/tablePlugin';

new Marzipan('#editor', {
  toolbar: true,
  plugins: [tablePlugin()]
});

Options

ts
interface TablePluginOptions {
  defaultColumns?: number;  // Default: 3
  defaultRows?: number;     // Default: 3
}

Usage Example

ts
import { tablePlugin } from '@pinkpixel/marzipan/plugins/tablePlugin';

new Marzipan('#editor', {
  plugins: [
    tablePlugin({
      defaultColumns: 4,
      defaultRows: 5
    })
  ]
});

Features

  • ✅ Adds toolbar button for table insertion
  • ✅ Configurable default dimensions
  • ✅ Generates properly formatted markdown
  • ✅ Includes header row with separators
  • ✅ Empty cells ready for content

Generated Output

With defaultColumns: 3 and defaultRows: 3:

markdown
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
|          |          |          |
|          |          |          |
|          |          |          |

Table Grid Plugin

Interactive visual grid for table creation.

Installation

ts
import { tableGridPlugin } from '@pinkpixel/marzipan/plugins/tableGridPlugin';

new Marzipan('#editor', {
  plugins: [tableGridPlugin()]
});

Options

ts
interface TableGridPluginOptions {
  maxColumns?: number;  // Default: 10 (alias: maxCols)
  maxRows?: number;     // Default: 10
}

Usage Example

ts
import { tableGridPlugin } from '@pinkpixel/marzipan/plugins/tableGridPlugin';

new Marzipan('#editor', {
  plugins: [
    tableGridPlugin({
      maxColumns: 8,
      maxRows: 8
    })
  ]
});

Features

  • ✅ Visual grid overlay for size selection
  • ✅ Hover to preview table size
  • ✅ Click to insert table
  • ✅ Configurable maximum dimensions
  • ✅ Intuitive UI similar to Word/Excel

How It Works

  1. Click the table grid button in toolbar
  2. Hover over the grid to select size
  3. See live preview (e.g., "3x4 table")
  4. Click to insert the table

Styling

The plugin exports tableGridStyles for custom styling:

ts
import { tableGridPlugin, tableGridStyles } from '@pinkpixel/marzipan/plugins/tableGridPlugin';

// Inject custom styles
const styleElement = document.createElement('style');
styleElement.textContent = tableGridStyles;
document.head.appendChild(styleElement);

new Marzipan('#editor', {
  plugins: [tableGridPlugin()]
});

Table Generator Plugin

Quick table insertion with prompts.

Installation

ts
import { tableGeneratorPlugin } from '@pinkpixel/marzipan/plugins/tableGenerator';

new Marzipan('#editor', {
  plugins: [tableGeneratorPlugin()]
});

Usage Example

ts
import { tableGeneratorPlugin } from '@pinkpixel/marzipan/plugins/tableGenerator';

new Marzipan('#editor', {
  plugins: [tableGeneratorPlugin()]
});

Features

  • ✅ Prompts user for table dimensions
  • ✅ Fast keyboard-driven workflow
  • ✅ Validates input
  • ✅ Generates table immediately

How It Works

  1. Click the table generator button
  2. Enter number of columns (prompt)
  3. Enter number of rows (prompt)
  4. Table is inserted at cursor position

User Experience

Prompt 1: "How many columns?"
Input: 4

Prompt 2: "How many rows?"
Input: 3

Result:
| Column 1 | Column 2 | Column 3 | Column 4 |
|----------|----------|----------|----------|
|          |          |          |          |
|          |          |          |          |

Using Multiple Table Plugins

You can use multiple table plugins together:

ts
import { 
  tablePlugin, 
  tableGridPlugin, 
  tableGeneratorPlugin 
} from '@pinkpixel/marzipan/plugins';

new Marzipan('#editor', {
  toolbar: true,
  plugins: [
    tablePlugin({ defaultColumns: 3, defaultRows: 3 }),
    tableGridPlugin({ maxColumns: 10, maxRows: 10 }),
    tableGeneratorPlugin()
  ]
});

Each plugin adds its own toolbar button, giving users multiple ways to create tables.

Complete Example

ts
import { Marzipan } from '@pinkpixel/marzipan';
import { 
  tablePlugin,
  tableGridPlugin 
} from '@pinkpixel/marzipan/plugins';

const [editor] = new Marzipan('#editor', {
  // Enable toolbar
  toolbar: true,
  
  // Add table plugins
  plugins: [
    // Basic table with defaults
    tablePlugin({
      defaultColumns: 3,
      defaultRows: 4
    }),
    
    // Interactive grid picker
    tableGridPlugin({
      maxColumns: 8,
      maxRows: 8
    })
  ],
  
  // Callback when tables are created
  onChange: (value, instance) => {
    const tableCount = (value.match(/\|/g) || []).length;
    console.log('Tables in document:', Math.floor(tableCount / 3));
  }
});

Markdown Table Syntax

All plugins generate GitHub-flavored markdown tables:

Basic Table

markdown
| Header 1 | Header 2 |
|----------|----------|
| Cell 1   | Cell 2   |
| Cell 3   | Cell 4   |

Alignment

You can manually adjust column alignment after insertion:

markdown
| Left    | Center  | Right   |
|:--------|:-------:|--------:|
| L1      | C1      | R1      |
| L2      | C2      | R2      |
  • :--- - Left-aligned
  • :---: - Center-aligned
  • ---: - Right-aligned

Tips for Tables

Best Practices

  1. Keep tables simple - Complex tables don't render well in markdown
  2. Use pipe alignment - Makes raw markdown more readable
  3. Consider CSV - For large data sets, link to CSV files instead
  4. Test rendering - Preview your tables before publishing

Cell Content

  • Avoid using pipe characters | inside cells
  • Escape pipes if needed: \|
  • Keep cell content concise

Browser Compatibility

All table plugins work in:

  • Chrome/Edge 60+
  • Firefox 55+
  • Safari 11+

See Also

Released under the Apache 2.0 License