• English
  • Slot plugins

    Slot plugins render slots. Content such as code, links, and headings is already prepared; you decide which components and interactions readers see. Start here for most interface changes.

    Declare and use a plugin

    This example hides the code toolbar while keeping the default highlighting and code styles:

    import type { CodeBlockProps } from '@fluxdown/react-presets/base';
    
    import { BaseSlotPlugin } from '@fluxdown/react-presets/base';
    import { Fluxdown } from 'fluxdown';
    
    function CompactCodeBlock({ Raw, ...props }: CodeBlockProps) {
      return Raw ? <Raw {...props} showHeader={false} /> : null;
    }
    
    class CompactCodeBlockPlugin extends BaseSlotPlugin<'CodeBlock'> {
      static readonly key = 'compact-code-block';
    
      readonly type = 'CodeBlock';
    
      readonly Component = CompactCodeBlock;
    }
    
    type MessageProps = {
      text: string;
    };
    
    export function Message({ text }: MessageProps) {
      return <Fluxdown plugins={{ slots: [CompactCodeBlockPlugin] }} text={text} />;
    }

    key identifies the plugin, type selects the slot, and Component provides its component. Add the plugin class to slots; Fluxdown manages its creation and cleanup.

    Import base classes and prop types from @fluxdown/react-presets/base. Install the extension package with pnpm add @fluxdown/react-presets first.

    Keep the defaults

    Raw is the component supplied by the previous plugin. Call it to keep the existing highlighting, copying, or link behavior, then adjust the props you want to change.

    Several plugins can target the same slot. Later plugins wrap earlier components through Raw. To replace a slot entirely, return your own JSX.

    Raw can be null; check it before rendering.

    Choose a slot

    SlotCommon uses
    CodeBlockAdjust the whole code block or hide its toolbar.
    CodeHeaderChange the toolbar or add actions alongside copying.
    CodeHighlighterProvide your own code highlighting presentation.
    Link, ImageCustomize navigation and image interactions.
    Heading, ParagraphChange heading and paragraph components.
    Table, List, BlockquoteCustomize tables, lists, and blockquotes.
    TexProvide your own formula presentation.

    Each slot has a corresponding prop type, such as LinkProps or HeadingProps.

    To change which slot a HAST node uses, continue with Render plugins.

    Built-in plugins

    Fluxdown includes these plugins by default; no additional setup is needed.

    These plugins are included in PRESET_SLOT_PLUGINS and exported from @fluxdown/react-presets/slot.

    PluginPurpose
    BlockquoteSlotPluginProvides the layout and styling for blockquotes.
    BreakLineSlotPluginDisplays line breaks.
    CodeBlockSlotPluginCombines the code toolbar and highlighted code area.
    CodeHeaderSlotPluginDisplays the language and copy action, with support for custom actions.
    CodeHighlighterSlotPluginHighlights code by language and keeps source readable while highlighting loads.
    EmphasisSlotPluginDisplays italic text.
    HeadingSlotPluginDisplays headings at each level.
    ImageSlotPluginDisplays images with alternative text and dimensions, and checks image URLs.
    LinkSlotPluginDisplays links and handles usable URLs.
    ListSlotPluginProvides the default layout for ordered, unordered, and task lists.
    ParagraphSlotPluginProvides paragraph typography and spacing.
    StrongSlotPluginDisplays bold text.
    TableSlotPluginProvides the table container and layout.
    TexSlotPluginDisplays formulas, with a lightweight presentation while the full renderer loads.

    The formula presets are included, but formula syntax still needs build={{ tex: true }}.