CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-vuepress--markdown

Markdown processing library for VuePress with enhanced plugins for documentation sites

Pending
Overview
Eval results
Files

plugin-management.mddocs/

Plugin Management

Utilities for managing the built-in VuePress markdown plugins, including checking requirements, removing plugins, and bulk plugin management.

Capabilities

Plugin Requirement Check

Check if a plugin is required by VuePress and cannot be removed.

/**
 * Check if a plugin is required and cannot be removed
 * @param {string} plugin - Plugin name to check
 * @returns {boolean} True if plugin is required (COMPONENT or ANCHOR)
 */
function isRequiredPlugin(plugin: string): boolean;

Usage Examples:

const { isRequiredPlugin, PLUGINS } = require('@vuepress/markdown');

// Check required plugins
console.log(isRequiredPlugin(PLUGINS.COMPONENT)); // true
console.log(isRequiredPlugin(PLUGINS.ANCHOR)); // true
console.log(isRequiredPlugin(PLUGINS.HIGHLIGHT_LINES)); // false
console.log(isRequiredPlugin(PLUGINS.EMOJI)); // false

// Use in conditional logic
if (!isRequiredPlugin(PLUGINS.TOC)) {
  // Safe to remove TOC plugin
}

Single Plugin Removal

Remove a specific built-in markdown-it plugin from the configuration.

/**
 * Remove a specific built-in plugin from the markdown configuration
 * @param {object} config - markdown-it-chain configuration object
 * @param {string} plugin - Plugin name to remove (use PLUGINS constants)
 */
function removePlugin(config: ChainConfig, plugin: string): void;

Usage Examples:

const createMarkdown = require('@vuepress/markdown');
const { removePlugin, PLUGINS } = require('@vuepress/markdown');

// Use with VuePress Plugin API chainMarkdown
module.exports = {
  chainMarkdown(config) {
    // Remove specific plugins
    removePlugin(config, PLUGINS.HIGHLIGHT_LINES);
    removePlugin(config, PLUGINS.LINE_NUMBERS);
    removePlugin(config, PLUGINS.EMOJI);
    
    // Cannot remove required plugins (will log warning)
    // removePlugin(config, PLUGINS.COMPONENT); // Not allowed
    // removePlugin(config, PLUGINS.ANCHOR); // Not allowed
  }
};

// Use with beforeInstantiate hook
const md = createMarkdown({
  beforeInstantiate(config) {
    removePlugin(config, PLUGINS.TOC);
    removePlugin(config, PLUGINS.SNIPPET);
  }
});

Bulk Plugin Removal

Remove all non-required built-in plugins in one operation.

/**
 * Remove all built-in plugins except required ones (COMPONENT, ANCHOR)
 * @param {object} config - markdown-it-chain configuration object
 */
function removeAllBuiltInPlugins(config: ChainConfig): void;

Usage Examples:

const createMarkdown = require('@vuepress/markdown');
const { removeAllBuiltInPlugins } = require('@vuepress/markdown');

// Use with VuePress Plugin API
module.exports = {
  chainMarkdown(config) {
    // Remove all non-required plugins at once
    removeAllBuiltInPlugins(config);
    
    // Add your own plugins
    config.plugin('my-custom-plugin')
      .use(myCustomPlugin, [options]);
  }
};

// Use with beforeInstantiate hook for clean slate
const md = createMarkdown({
  beforeInstantiate(config) {
    // Start with minimal setup
    removeAllBuiltInPlugins(config);
    
    // Add only what you need
    config.plugin('highlight-lines')
      .use(highlightLinesPlugin);
  }
});

Plugin Constants

PLUGINS Object

Constant object containing the names of all built-in markdown-it plugins.

const PLUGINS: {
  readonly COMPONENT: 'component';
  readonly HIGHLIGHT_LINES: 'highlight-lines';
  readonly PRE_WRAPPER: 'pre-wrapper';
  readonly SNIPPET: 'snippet';
  readonly CONVERT_ROUTER_LINK: 'convert-router-link';
  readonly HOIST_SCRIPT_STYLE: 'hoist-script-style';
  readonly ANCHOR: 'anchor';
  readonly EMOJI: 'emoji';
  readonly TOC: 'toc';
  readonly LINE_NUMBERS: 'line-numbers';
};

Usage Examples:

const { PLUGINS, removePlugin } = require('@vuepress/markdown');

// Use constants instead of strings
removePlugin(config, PLUGINS.HIGHLIGHT_LINES); // Good
removePlugin(config, 'highlight-lines'); // Works but not recommended

// List all available plugins
Object.keys(PLUGINS).forEach(key => {
  console.log(`${key}: ${PLUGINS[key]}`);
});

Required Plugins

The following plugins are required and cannot be removed:

  • COMPONENT ('component'): Enables Vue components in markdown (required for VuePress)
  • ANCHOR ('anchor'): Generates heading anchors with permalinks (required for navigation)

Optional Plugins

The following plugins can be safely removed:

  • HIGHLIGHT_LINES ('highlight-lines'): Highlights specific lines in code blocks
  • PRE_WRAPPER ('pre-wrapper'): Wraps code blocks with additional containers
  • SNIPPET ('snippet'): Includes code snippets from external files
  • CONVERT_ROUTER_LINK ('convert-router-link'): Converts links to Vue Router links
  • HOIST_SCRIPT_STYLE ('hoist-script-style'): Hoists script/style tags
  • EMOJI ('emoji'): Converts emoji shortcodes to Unicode
  • TOC ('toc'): Generates table of contents
  • LINE_NUMBERS ('line-numbers'): Adds line numbers to code blocks

Error Handling

Plugin management functions include error handling and logging:

  • Attempting to remove required plugins logs a warning but does not fail
  • Invalid plugin names are ignored
  • All plugin operations are safe and won't break the markdown processor

Install with Tessl CLI

npx tessl i tessl/npm-vuepress--markdown

docs

builtin-plugins.md

index.md

markdown-processing.md

plugin-management.md

tile.json