Markdown processing library for VuePress with enhanced plugins for documentation sites
npx @tessl/cli install tessl/npm-vuepress--markdown@1.9.0@vuepress/markdown is a comprehensive markdown processing library specifically designed for VuePress, the Vue.js-based static site generator. It extends markdown-it with custom plugins and enhancements tailored for documentation sites, including syntax highlighting, component embedding, anchor generation, table of contents, line numbers, snippet inclusion, emoji support, and Vue Router link conversion.
npm install @vuepress/markdownconst createMarkdown = require('@vuepress/markdown');
const { PLUGINS, isRequiredPlugin, removePlugin, removeAllBuiltInPlugins, dataReturnable } = require('@vuepress/markdown');For ES modules:
import createMarkdown, { PLUGINS, isRequiredPlugin, removePlugin, removeAllBuiltInPlugins, dataReturnable } from '@vuepress/markdown';const createMarkdown = require('@vuepress/markdown');
// Create a markdown processor with default VuePress plugins
const md = createMarkdown({
lineNumbers: true,
anchor: {
permalink: true,
permalinkBefore: true,
permalinkSymbol: '#'
}
});
// Process markdown content
const result = md.render('# Hello World\n\nThis is a test.');
console.log(result.html); // Rendered HTML
console.log(result.data); // Plugin data
console.log(result.dataBlockString); // Serialized data for Vue@vuepress/markdown is built around several key components:
Factory function that creates a markdown-it instance with VuePress-specific plugins and configuration.
/**
* Create a markdown processor with VuePress plugins
* @param {object} markdown - Configuration options
* @returns {MarkdownIt} Enhanced markdown-it instance
*/
function createMarkdown(markdown?: MarkdownConfig): MarkdownIt;
interface MarkdownConfig {
externalLinks?: ExternalLinksConfig;
pageSuffix?: string;
anchor?: AnchorConfig;
toc?: TocConfig;
plugins?: Plugin[];
lineNumbers?: boolean;
slugify?: (str: string) => string;
beforeInstantiate?: (config: ChainConfig) => void;
afterInstantiate?: (md: MarkdownIt) => void;
}Utilities for managing built-in VuePress markdown plugins, including removal and configuration.
/**
* Check if a plugin is required and cannot be removed
* @param {string} plugin - Plugin name
* @returns {boolean} True if plugin is required
*/
function isRequiredPlugin(plugin: string): boolean;
/**
* Remove a specific built-in plugin
* @param {object} config - markdown-it-chain configuration
* @param {string} plugin - Plugin name to remove
*/
function removePlugin(config: ChainConfig, plugin: string): void;
/**
* Remove all non-required built-in plugins
* @param {object} config - markdown-it-chain configuration
*/
function removeAllBuiltInPlugins(config: ChainConfig): void;Access to plugin names and built-in plugin functionality for VuePress markdown processing.
const PLUGINS: {
COMPONENT: 'component';
HIGHLIGHT_LINES: 'highlight-lines';
PRE_WRAPPER: 'pre-wrapper';
SNIPPET: 'snippet';
CONVERT_ROUTER_LINK: 'convert-router-link';
HOIST_SCRIPT_STYLE: 'hoist-script-style';
ANCHOR: 'anchor';
EMOJI: 'emoji';
TOC: 'toc';
LINE_NUMBERS: 'line-numbers';
};interface ExternalLinksConfig {
target?: string;
rel?: string;
}
interface AnchorConfig {
slugify?: (str: string) => string;
permalink?: boolean;
permalinkBefore?: boolean;
permalinkSymbol?: string;
}
interface TocConfig {
slugify?: (str: string) => string;
includeLevel?: number[];
format?: (headers: any) => any;
}
interface Plugin extends Array<any> {
0: string | Function;
1?: any;
}
interface RenderResult {
html: string;
data: object;
dataBlockString: string;
}