CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-milkdown--preset-commonmark

Complete CommonMark preset for Milkdown editor providing all essential plugins for standard markdown editing

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

plugins.mddocs/

Utility Plugins

Advanced editing behaviors including remark transformers for markdown processing and ProseMirror plugins for cursor handling and content synchronization. These plugins provide essential functionality for a smooth editing experience.

Capabilities

Remark Plugins

Remark plugins handle markdown parsing and serialization, ensuring proper conversion between markdown text and the editor's internal representation.

/**
 * Adds order attributes to list items during markdown processing
 * Ensures proper numbering in ordered lists
 */
const remarkAddOrderInListPlugin: $remark<'remarkAddOrderInList'>;

/**
 * Handles inline line breaks during markdown transformation
 * Converts hard breaks to proper editor nodes
 */
const remarkLineBreak: $remark<'remarkLineBreak'>;

/**
 * Wraps the remark-inline-links plugin for processing inline link syntax
 * Converts reference-style links to inline format
 */
const remarkInlineLinkPlugin: $remark<'remarkInlineLink'>;

/**
 * Transforms HTML nodes during markdown processing
 * Handles inline HTML content preservation
 */
const remarkHtmlTransformer: $remark<'remarkHTMLTransformer'>;

/**
 * Preserves original emphasis and strong markers (* vs _ and ** vs __)
 * Maintains consistency with user's preferred markdown syntax
 */
const remarkMarker: $remark<'remarkMarker'>;

/**
 * Preserves empty lines in markdown output
 * Maintains document formatting and readability
 */
const remarkPreserveEmptyLinePlugin: $remark<'remark-preserve-empty-line'>;

Usage Examples:

import { 
  remarkAddOrderInListPlugin,
  remarkLineBreak,
  remarkMarker 
} from "@milkdown/preset-commonmark";

// These plugins are automatically included in the commonmark preset
// They can also be used individually if needed
const customPreset = [
  remarkAddOrderInListPlugin,
  remarkLineBreak,
  remarkMarker,
];

ProseMirror Plugins

ProseMirror plugins provide advanced editor behaviors and work directly with the editor's document model to enhance the editing experience.

/**
 * Fixes cursor positioning bug in Chrome 98+ for inline nodes
 * Ensures proper cursor placement around images, links, and other inline elements
 */
const inlineNodesCursorPlugin: $prose;

/**
 * Clears formatting marks around hard break nodes
 * Prevents marks from spanning across line breaks inappropriately
 */
const hardbreakClearMarkPlugin: $prose;

/**
 * Context configuration for nodes that should be filtered during hardbreak insertion
 * Array of node type names where hardbreaks should not be automatically inserted
 */
const hardbreakFilterNodes: $ctx<string[]>;

/**
 * Filters hardbreak insertion based on current context
 * Uses hardbreakFilterNodes context to determine where hardbreaks are allowed
 */
const hardbreakFilterPlugin: $prose;

/**
 * Synchronizes heading node IDs with their text content
 * Automatically updates heading IDs when heading text changes
 */
const syncHeadingIdPlugin: $prose;

/**
 * Synchronizes order attributes in list items
 * Maintains proper numbering in ordered lists during editing
 */
const syncListOrderPlugin: $prose;

Usage Examples:

import { 
  hardbreakFilterNodes,
  hardbreakFilterPlugin,
  syncHeadingIdPlugin 
} from "@milkdown/preset-commonmark";

// Configure hardbreak filtering
editor.config((ctx) => {
  ctx.set(hardbreakFilterNodes.key, ['codeBlock', 'heading']);
});

// The sync plugins work automatically once included
const customPlugins = [
  hardbreakFilterPlugin,
  syncHeadingIdPlugin,
];

Plugin Integration

All utility plugins are designed to work seamlessly together and are included in the main commonmark preset. They can also be used individually for custom configurations.

/**
 * Combined utility plugins included in the commonmark preset
 * Contains all remark and ProseMirror plugins for full functionality
 */
const plugins: MilkdownPlugin[];

Complete Integration Example:

import { Editor } from "@milkdown/core";
import { 
  remarkAddOrderInListPlugin,
  remarkLineBreak,
  inlineNodesCursorPlugin,
  syncHeadingIdPlugin,
  hardbreakFilterNodes
} from "@milkdown/preset-commonmark";

// Custom editor with specific plugins
const editor = await Editor.make()
  .config((ctx) => {
    // Configure hardbreak filtering
    ctx.set(hardbreakFilterNodes.key, ['codeBlock']);
  })
  .use([
    // Remark plugins for markdown processing
    remarkAddOrderInListPlugin,
    remarkLineBreak,
    
    // ProseMirror plugins for editor behavior
    inlineNodesCursorPlugin,
    syncHeadingIdPlugin,
  ])
  .create();

Plugin Categories

Content Processing Plugins

Handle the transformation and processing of content:

  • remarkAddOrderInListPlugin - List ordering
  • remarkLineBreak - Line break handling
  • remarkHtmlTransformer - HTML content processing
  • remarkMarker - Markdown syntax preservation
  • remarkPreserveEmptyLinePlugin - Whitespace preservation

Editor Behavior Plugins

Enhance the editing experience and fix browser-specific issues:

  • inlineNodesCursorPlugin - Cursor positioning fixes
  • hardbreakClearMarkPlugin - Mark cleanup around breaks
  • hardbreakFilterPlugin - Context-aware hardbreak insertion

Content Synchronization Plugins

Keep document properties synchronized during editing:

  • syncHeadingIdPlugin - Heading ID management
  • syncListOrderPlugin - List numbering consistency

Types

// Plugin types
type $remark<T> = any; // Remark plugin type
type $prose = any; // ProseMirror plugin type
type $ctx<T> = any; // Context configuration type
type MilkdownPlugin = any; // Core plugin type

// Context value types
type HardbreakFilterNodes = string[]; // Array of node type names

docs

commands.md

index.md

marks.md

nodes.md

plugins.md

tile.json