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 整理創建