Vditor Markdown Editor
repository·master·Indexed 11 days ago
https://github.com/vanessa219/vditorA versatile, browser-based Markdown editor implemented in TypeScript. It supports three editing modes—WYSIWYG, Instant Rendering (IR), and Split-screen (SV)—and integrates with Vue, React, Angular, and Svelte. Vditor features extensive syntax support including CommonMark, GFM, Mermaid diagrams, MathJax/KaTeX, ECharts, and WaveDrom. Version 3.11.3 provides a rich feature set with multi-theme switching, multi-language support, and customizable toolbars.
What's inside Vditor
- Vditor is a browser-side Markdown editor built with TypeScript. It is designed to adapt to various application scenarios by providing three distinct editing modes. It supports modern Markdown specifications (CommonMark and GFM) and includes extensive support for advanced syntax like mathematical formulas, charts, and mind maps. It is compatible with native JavaScript and major frameworks including Vue, React, Angular, and Svelte.
Overview of Vditor Markdown Editor
masterVditor is a browser-based Markdown editor designed to adapt to various application scenarios. It is implemented in TypeScript and supports integration with native JavaScript as well as modern frameworks like Vue, React, Angular, and Svelte.
Key capabilities include:
- Three Editing Modes: WYSIWYG (What You See Is What You Get), IR (Instant Rendering), and SV (Split-screen Preview).
- Extensive Syntax Support: CommonMark and GFM specifications, plus extensions like Mermaid diagrams, MathJax/KaTeX for math, ECharts for charts, and WaveDrom for digital waveforms.
- Rich Feature Set: Outline support, mind maps, task lists, image lazy loading, multi-theme switching (Black, White, Green), and multi-language support (Chinese, English, Korean).
Configure Vditor Editor Themes
masterVditor supports different themes for the editor, the rendered content, and code blocks.
Editor Themes
Built-in themes:
classic,dark.- Set via
options.themeduring initialization. - Update via
setTheme()after initialization. - Customize by modifying variables in
index.less.
Content Themes
Applies to the HTML output of Markdown. Built-in themes:
ant-design,light,dark,wechat.- Requirement: The display element must have
class="vditor-reset". - Set via
options.preview.themeduring initialization. - Update via
setTheme()orsetContentTheme().
Code Block Themes
Built-in themes:
githuband 36 others.- Set via
options.preview.hljsduring initialization. - Update via
setTheme()orsetCodeTheme().
- Set via
Vditor Syntax and Extension Support
masterVditor supports a wide array of Markdown syntaxes and specialized extensions:
Core Specifications
- CommonMark: Full support for headers, code blocks, HTML blocks, lists, emphasis, links, images, etc.
- GFM (GitHub Flavored Markdown): Tables, task lists, strikethrough, and auto-links.
Specialized Extensions
- Diagrams & Charts:
- Flowcharts, Sequence diagrams, and Gantt charts via Mermaid.
- Graphviz rendering.
- Line charts, Pie charts, and Mind maps via ECharts.
- Digital waveforms via WaveDrom.
- UML diagrams via PlantUML.
- Mathematics: Math blocks and inline math via MathJax and KaTeX.
- Music: Sheet music via abc.js.
- Other:
- YAML Front Matter.
- Footnotes and Table of Contents (ToC).
- Chinese context optimizations (e.g., automatic spacing between Chinese and English characters).
Understand Vditor editing modes
masterVditor provides three modes to suit different user preferences and application needs:
- WYSIWYG (
wysiwyg): A rich-text style mode friendly to users unfamiliar with Markdown, while remaining seamless for experienced users. - Instant Rendering (
ir): An elegant mode similar to Typora, where Markdown is rendered immediately as you type. - Split View (
sv): A traditional mode where the editing area and the preview area are separated, ideal for large-screen typesetting.
Most features associated with these modes can be enabled or disabled via configuration switches.
- WYSIWYG (
Understand Vditor's three editing modes
masterVditor provides three distinct modes to cater to different user expertise and screen real estate:
- WYSIWYG (What You See Is What You Get): Best for users unfamiliar with Markdown syntax. It provides a rich-text-like experience where formatting is applied immediately.
- IR (Instant Rendering): Designed for advanced Markdown users (similar to Typora). It provides an elegant experience where the syntax is rendered into its visual form as you type.
- SV (Split-screen Preview): The traditional Markdown approach. It features a separate editing area and a preview area, which is ideal for large screens and traditional layout workflows.
Configure Vditor themes
masterVditor supports four theme sets:
and-design,classic,dark, andwechat.- You can customize styles using Less/CSS.
- Theme colors can be modified by changing variables in
index.less. - To display content more effectively, add
class="vditor-reset"(for classic theme) orclass="vditor-reset vditor-reset--dark"(for dark theme) to the content display element.
Upgrade Vditor
masterWhen upgrading Vditor to a new version, it is critical to carefully review the Upgrade section in the CHANGELOG to identify breaking changes or necessary migrations.Markdown Syntax Guide for Vditor
masterVditor supports a wide range of Markdown syntax for rich text editing. Key features include:
- Basic Formatting: Bold (
**text**), Italics (*text*), Strikethrough (~~text~~), and Inline Code (`code`). - Links: Standard hyperlinks
[text](url "title")and reference-style links[text][ref]with[ref]: urldefinitions. - Mentions: Use
@usernameto mention users (requires a space after the username). - Emojis: Support for standard emojis via
:syntax (e.g.,:smile:). Custom emoji sets can be pre-registered in settings. - Headings: Supports H1 through H6 using
#syntax. Note: A space is required after the#character. It is recommended to use H3 or lower for post content to avoid conflicting with site-level H1/H2. - Lists: Supports unordered lists, ordered lists, and task checkboxes (
- [x],- [ ]). - Tables: Standard Markdown table syntax.
- Footnotes: Use
[^1]for references and[^1]: definitionfor the footnote content. - Details/Summary: HTML
<details>and<summary>tags for collapsible content.
- **bold** - *italic* - ~~strikethrough~~ - `code tag` - [hyperlink](https://www.google.com "google") - [^1] [^1]: Footnote definition.- Basic Formatting: Bold (
Install Vditor via npm
masterTo use Vditor in a CommonJS or module-based environment, install it using npm:
npm install vditor --saveSet up a local development environment
masterTo develop on Vditor, ensure you have the Node.js LTS version installed. Follow these steps to run the project locally:
- Download and unzip the latest source code.
- Run
npm installin the root directory to install dependencies. - Run
npm run startto launch a local server athttp://localhost:9000. - After making modifications, run
npm run buildto package the code into thedistdirectory.
npm install npm run start npm run buildInitialize Vditor in CommonJS/TypeScript
masterImport
Vditorand its associated styles, then instantiate it by passing an element ID and an options object.import Vditor from 'vditor' import "~vditor/src/assets/less/index" const vditor = new Vditor(id, {options...})