Skip to content

工具和插件

选择合适的工具和插件可以大大提升 Markdown 的编写效率和文档质量。本指南介绍各类型工具,帮助您构建完整的 Markdown 工作流。

编辑器推荐

专业代码编辑器

Visual Studio Code

特点:免费、跨平台、插件丰富

markdown
推荐插件:
- Markdown All in One:全功能 Markdown 支持
- Markdown Preview Enhanced:增强预览功能
- markdownlint:语法检查和规范
- Paste Image:快速粘贴图片
- Table Editor:可视化表格编辑
- Math to Image:数学公式转图片

配置示例

json
{
  "markdown.preview.fontSize": 14,
  "markdown.preview.lineHeight": 1.6,
  "markdown.extension.toc.levels": "1..6",
  "markdown.extension.print.absoluteImgPath": false,
  "[markdown]": {
    "editor.wordWrap": "on",
    "editor.lineNumbers": "on",
    "editor.quickSuggestions": false
  }
}

Typora

特点:所见即所得、界面简洁、主题丰富

markdown
主要功能:
- 实时预览编辑
- 数学公式支持
- 图表绘制集成
- 导出多种格式
- 图片自动复制
- 表格可视化编辑

Mark Text

特点:开源、实时预览、性能优秀

markdown
核心特性:
- 实时预览渲染
- 专注模式
- 数学公式支持
- 流程图支持
- 多种导出格式
- 自定义主题

在线编辑器

StackEdit

特点:基于浏览器、云同步、协作功能

markdown
功能亮点:
- 实时同步到 Google Drive、Dropbox
- 发布到 GitHub、博客平台
- 离线编辑支持
- 数学公式和图表
- 协作编辑
- 版本历史

Dillinger

特点:简洁界面、多平台集成

markdown
集成平台:
- GitHub
- Dropbox
- Google Drive
- OneDrive
- 支持导出 HTML、PDF
- 实时预览

HackMD

特点:团队协作、演示功能

markdown
协作特性:
- 多人实时编辑
- 评论系统
- 版本控制
- 权限管理
- 演示模式
- 书籍模式

预览和转换工具

静态站点生成器

VitePress

特点:Vue 生态、性能优秀、现代化

javascript
// .vitepress/config.js
export default {
  title: 'My Documentation',
  description: 'A VitePress site',
  
  themeConfig: {
    nav: [
      { text: 'Home', link: '/' },
      { text: 'Guide', link: '/guide/' }
    ],
    
    sidebar: {
      '/guide/': [
        {
          text: 'Getting Started',
          items: [
            { text: 'Introduction', link: '/guide/introduction' },
            { text: 'Installation', link: '/guide/installation' }
          ]
        }
      ]
    }
  },
  
  markdown: {
    math: true,
    mermaid: true,
    lineNumbers: true
  }
}

GitBook

特点:美观界面、团队协作、版本管理

markdown
功能特色:
- 现代化阅读体验
- 团队协作编辑
- 多格式导出
- 搜索功能
- 集成分析
- API 文档生成

Docusaurus

特点:Facebook 开源、React 生态、多语言支持

javascript
// docusaurus.config.js
module.exports = {
  title: 'My Site',
  tagline: 'The tagline of my site',
  url: 'https://your-docusaurus-test-site.com',
  
  presets: [
    [
      '@docusaurus/preset-classic',
      {
        docs: {
          sidebarPath: require.resolve('./sidebars.js'),
          editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/',
        },
        blog: {
          showReadingTime: true,
          editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/blog/',
        },
        theme: {
          customCss: require.resolve('./src/css/custom.css'),
        },
      },
    ],
  ],
  
  themeConfig: {
    navbar: {
      title: 'My Site',
      logo: {
        alt: 'My Site Logo',
        src: 'img/logo.svg',
      },
    },
  },
};

格式转换工具

Pandoc

特点:万能转换器、命令行工具、格式丰富

bash
# Markdown 转 PDF
pandoc document.md -o document.pdf

# Markdown 转 Word
pandoc document.md -o document.docx

# Markdown 转 HTML(自定义样式)
pandoc document.md -s --css=style.css -o document.html

# 批量转换
find . -name "*.md" -exec pandoc {} -o {}.pdf \;

# 使用模板
pandoc document.md --template=template.html -o output.html

# 生成目录
pandoc document.md --toc --toc-depth=3 -o document.pdf

markdownlint

特点:语法检查、规范统一、自动修复

bash
# 安装
npm install -g markdownlint-cli

# 检查单个文件
markdownlint README.md

# 检查目录
markdownlint docs/

# 自动修复
markdownlint --fix *.md

# 使用配置文件
markdownlint --config .markdownlint.json docs/

配置示例

json
{
  "default": true,
  "MD013": {
    "line_length": 120,
    "code_blocks": false,
    "tables": false
  },
  "MD033": {
    "allowed_elements": ["div", "span", "img", "a"]
  },
  "MD041": false
}

图片和媒体工具

图片处理工具

PicGo

特点:自动上传、多平台支持、插件扩展

markdown
支持平台:
- 七牛云
- 腾讯云 COS
- 又拍云
- GitHub
- 阿里云 OSS
- Imgur
- 自定义上传

配置示例

json
{
  "picBed": {
    "uploader": "github",
    "github": {
      "repo": "username/image-repo",
      "token": "your_github_token",
      "path": "images/",
      "customUrl": "https://cdn.jsdelivr.net/gh/username/image-repo",
      "branch": "main"
    }
  },
  "settings": {
    "autoRename": true,
    "uploadNotification": true
  }
}

ImageOptim / TinyPNG

特点:图片压缩、减小体积、保持质量

bash
# 使用 ImageOptim CLI
imageoptim *.png *.jpg

# 使用 TinyPNG API
curl --user api:YOUR_API_KEY \
     --data-binary @original.png \
     --output compressed.png \
     https://api.tinify.com/shrink

图表生成工具

draw.io (diagrams.net)

特点:免费、功能强大、多格式导出

markdown
应用场景:
- 系统架构图
- 流程图设计
- UML 图表
- 网络拓扑图
- 思维导图
- 原型设计

Excalidraw

特点:手绘风格、协作编辑、简单易用

markdown
特色功能:
- 手绘风格图表
- 实时协作
- 离线使用
- 导出 PNG/SVG
- 库管理
- 无限画布

文档管理平台

团队协作工具

Notion

特点:一体化工作空间、数据库功能、模板丰富

markdown
文档功能:
- 层级化页面结构
- 实时协作编辑
- 数据库集成
- 模板系统
- 多媒体支持
- API 集成

Confluence

特点:企业级、权限管理、集成能力强

markdown
企业特性:
- 高级权限控制
- 审批工作流
- 品牌自定义
- 企业集成
- 高级搜索
- 分析报告

GitBook

特点:开发者友好、版本控制、美观界面

markdown
核心优势:
- Git 集成
- 版本历史
- 团队协作
- 自定义域名
- 搜索功能
- 分析数据

发布平台

GitHub Pages

特点:免费托管、版本控制、自定义域名

yaml
# .github/workflows/deploy.yml
name: Deploy to GitHub Pages

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    
    - name: Setup Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '16'
        
    - name: Install dependencies
      run: npm install
      
    - name: Build
      run: npm run build
      
    - name: Deploy
      uses: peaceiris/actions-gh-pages@v3
      with:
        github_token: ${{ secrets.GITHUB_TOKEN }}
        publish_dir: ./dist

Netlify

特点:快速部署、CDN 加速、表单处理

toml
# netlify.toml
[build]
  publish = "dist"
  command = "npm run build"

[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

[build.environment]
  NODE_VERSION = "16"

Vercel

特点:零配置部署、全球CDN、预览部署

json
{
  "builds": [
    {
      "src": "package.json",
      "use": "@vercel/static-build",
      "config": {
        "distDir": "dist"
      }
    }
  ],
  "routes": [
    {
      "handle": "filesystem"
    },
    {
      "src": "/(.*)",
      "dest": "/index.html"
    }
  ]
}

自动化工具

CI/CD 集成

GitHub Actions

工作流示例

yaml
name: Documentation Build and Deploy

on:
  push:
    branches: [ main ]
    paths: [ 'docs/**' ]
  pull_request:
    branches: [ main ]
    paths: [ 'docs/**' ]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    
    - name: Lint Markdown
      uses: articulate/actions-markdownlint@v1
      with:
        config: .markdownlint.json
        files: 'docs/**/*.md'

  build:
    needs: lint
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    
    - name: Setup Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '16'
        cache: 'npm'
        
    - name: Install dependencies
      run: npm ci
      
    - name: Build VitePress
      run: npm run docs:build
      
    - name: Upload artifact
      uses: actions/upload-pages-artifact@v1
      with:
        path: docs/.vitepress/dist

  deploy:
    needs: build
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    steps:
    - name: Deploy to GitHub Pages
      id: deployment
      uses: actions/deploy-pages@v1

Pre-commit Hooks

配置文件 .pre-commit-config.yaml

yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-added-large-files
      
  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.32.2
    hooks:
      - id: markdownlint
        args: ['--fix']
        
  - repo: https://github.com/psf/black
    rev: 22.10.0
    hooks:
      - id: black
        language_version: python3
        
  - repo: local
    hooks:
      - id: docs-build
        name: Build documentation
        entry: npm run docs:build
        language: system
        files: '^docs/.*\.md$'
        pass_filenames: false

文档生成工具

API 文档自动生成

javascript
// 使用 JSDoc 生成 API 文档
/**
 * 创建新用户
 * @param {Object} userData - 用户数据
 * @param {string} userData.name - 用户姓名
 * @param {string} userData.email - 邮箱地址
 * @param {string} [userData.role=user] - 用户角色
 * @returns {Promise<Object>} 创建的用户对象
 * @example
 * const user = await createUser({
 *   name: '张三',
 *   email: 'zhangsan@example.com'
 * });
 */
async function createUser(userData) {
  // 实现代码...
}
bash
# 生成文档
jsdoc src/ -d docs/api/ -c jsdoc.conf.json

OpenAPI/Swagger 文档

yaml
# openapi.yaml
openapi: 3.0.0
info:
  title: 用户管理 API
  version: 1.0.0
  description: 用户管理系统的 RESTful API

paths:
  /users:
    post:
      summary: 创建新用户
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateUserRequest'
      responses:
        '201':
          description: 用户创建成功
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/User'

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
          example: "12345"
        name:
          type: string
          example: "张三"
        email:
          type: string
          format: email
          example: "zhangsan@example.com"
    
    CreateUserRequest:
      type: object
      required:
        - name
        - email
      properties:
        name:
          type: string
        email:
          type: string
          format: email
        role:
          type: string
          default: "user"

性能优化工具

构建优化

图片优化脚本

javascript
// optimize-images.js
const sharp = require('sharp');
const fs = require('fs');
const path = require('path');

async function optimizeImages(dir) {
  const files = fs.readdirSync(dir);
  
  for (const file of files) {
    const filePath = path.join(dir, file);
    const stat = fs.statSync(filePath);
    
    if (stat.isDirectory()) {
      await optimizeImages(filePath);
    } else if (/\.(jpg|jpeg|png)$/i.test(file)) {
      const outputPath = filePath.replace(/\.(jpg|jpeg|png)$/i, '.webp');
      
      await sharp(filePath)
        .webp({ quality: 80 })
        .toFile(outputPath);
        
      console.log(`优化: ${file} -> ${path.basename(outputPath)}`);
    }
  }
}

optimizeImages('./docs/assets/images');

文档构建脚本

javascript
// build-docs.js
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');

function buildDocs() {
  console.log('📝 开始构建文档...');
  
  // 1. 检查 Markdown 语法
  console.log('🔍 检查 Markdown 语法...');
  execSync('markdownlint docs/', { stdio: 'inherit' });
  
  // 2. 优化图片
  console.log('🖼️ 优化图片...');
  execSync('node optimize-images.js', { stdio: 'inherit' });
  
  // 3. 构建静态站点
  console.log('🏗️ 构建静态站点...');
  execSync('vitepress build docs', { stdio: 'inherit' });
  
  // 4. 生成站点地图
  console.log('🗺️ 生成站点地图...');
  generateSitemap();
  
  console.log('✅ 文档构建完成!');
}

function generateSitemap() {
  const baseUrl = 'https://yoursite.com';
  const pages = findMarkdownFiles('./docs');
  
  const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${pages.map(page => `  <url>
    <loc>${baseUrl}${page}</loc>
    <lastmod>${new Date().toISOString().split('T')[0]}</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.8</priority>
  </url>`).join('\n')}
</urlset>`;

  fs.writeFileSync('./docs/.vitepress/dist/sitemap.xml', sitemap);
}

function findMarkdownFiles(dir, basePath = '') {
  const files = [];
  const items = fs.readdirSync(dir);
  
  for (const item of items) {
    const fullPath = path.join(dir, item);
    const relativePath = path.join(basePath, item);
    
    if (fs.statSync(fullPath).isDirectory()) {
      files.push(...findMarkdownFiles(fullPath, relativePath));
    } else if (item.endsWith('.md') && item !== 'README.md') {
      const urlPath = relativePath
        .replace(/\.md$/, '.html')
        .replace(/\\/g, '/');
      files.push('/' + urlPath);
    }
  }
  
  return files;
}

buildDocs();

工具选择指南

按需求选择工具

markdown
## 个人博客写作
推荐组合:
- 编辑器:Typora 或 Mark Text
- 部署:GitHub Pages + Jekyll
- 图片:PicGo + GitHub
- 版本:Git

## 团队文档协作
推荐组合:
- 平台:Notion 或 GitBook
- 编辑器:VS Code + 插件
- 版本:Git + GitHub
- 自动化:GitHub Actions

## 技术文档网站
推荐组合:
- 生成器:VitePress 或 Docusaurus
- 编辑器:VS Code
- 部署:Netlify 或 Vercel
- 图表:Mermaid + draw.io

## API 文档
推荐组合:
- 工具:Swagger/OpenAPI
- 生成:Redoc 或 SwaggerUI
- 集成:Postman
- 测试:Newman

## 学术论文
推荐组合:
- 编辑器:Typora + Pandoc
- 公式:MathJax/KaTeX
- 引用:Zotero
- 转换:Pandoc LaTeX

成本对比

工具类型免费选项付费选项企业版本
编辑器VS Code, Mark TextTypora (¥89)-
托管GitHub PagesNetlify Pro (¥190/月)企业定制
协作GitHubNotion (¥64/月/人)Confluence (¥42/月/人)
图床GitHub七牛云 (¥0.1/GB)企业私有云
域名github.io自定义域名 (¥60/年)企业域名

相关语法

总结建议

新手推荐配置

markdown
🚀 快速开始套装:
1. 编辑器:VS Code + Markdown All in One
2. 预览:实时预览插件
3. 版本:Git + GitHub
4. 部署:GitHub Pages
5. 图片:直接上传到仓库

💰 成本:完全免费
⏱️ 学习时间:1-2 小时
🎯 适合:个人博客、小型项目文档

进阶推荐配置

markdown
⚡ 专业套装:
1. 编辑器:Typora + VS Code
2. 生成器:VitePress
3. 图床:PicGo + 云存储
4. 协作:GitHub + Issues
5. 自动化:GitHub Actions
6. 监控:Google Analytics

💰 成本:¥200-500/年
⏱️ 学习时间:1-2 天
🎯 适合:技术团队、开源项目

企业级配置

markdown
🏢 企业套装:
1. 平台:Confluence 或 GitBook
2. 编辑:VS Code + 团队插件
3. 版本:企业级 Git
4. 部署:私有云 + CDN
5. 协作:完整权限管理
6. 集成:CI/CD + 监控告警

💰 成本:¥5000-20000/年
⏱️ 部署时间:1-2 周
🎯 适合:大型企业、产品文档

通过合理选择和配置这些工具,您可以构建一个高效、专业的 Markdown 文档工作流,大大提升文档创建和维护的效率。

由 Markdownlang.com 整理创建