|
|
--- |
|
|
title: '代码块' |
|
|
description: 'MCPHub 文档中代码块的编写和展示指南' |
|
|
--- |
|
|
|
|
|
|
|
|
|
|
|
在 MCPHub 文档中使用内联代码来标记命令、配置键、文件名或短代码片段: |
|
|
|
|
|
```md |
|
|
使用 `mcphub start` 命令启动服务器,配置 `MCPHUB_PORT` 环境变量。 |
|
|
``` |
|
|
|
|
|
使用 `mcphub start` 命令启动服务器,配置 `MCPHUB_PORT` 环境变量。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MCPHub 支持多种编程语言的语法高亮: |
|
|
|
|
|
````md |
|
|
```javascript |
|
|
// JavaScript 示例 |
|
|
const mcpClient = new MCPClient({ |
|
|
endpoint: process.env.MCPHUB_ENDPOINT, |
|
|
apiKey: process.env.MCPHUB_API_KEY, |
|
|
}); |
|
|
``` |
|
|
```` |
|
|
|
|
|
```javascript |
|
|
// JavaScript 示例 |
|
|
const mcpClient = new MCPClient({ |
|
|
endpoint: process.env.MCPHUB_ENDPOINT, |
|
|
apiKey: process.env.MCPHUB_API_KEY, |
|
|
}); |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```typescript |
|
|
interface MCPServerConfig { |
|
|
id: string; |
|
|
name: string; |
|
|
endpoint: string; |
|
|
capabilities: string[]; |
|
|
metadata?: Record<string, any>; |
|
|
} |
|
|
|
|
|
class MCPServer implements MCPServerConfig { |
|
|
constructor( |
|
|
public id: string, |
|
|
public name: string, |
|
|
public endpoint: string, |
|
|
public capabilities: string[], |
|
|
) {} |
|
|
} |
|
|
``` |
|
|
```` |
|
|
|
|
|
```typescript |
|
|
interface MCPServerConfig { |
|
|
id: string; |
|
|
name: string; |
|
|
endpoint: string; |
|
|
capabilities: string[]; |
|
|
metadata?: Record<string, any>; |
|
|
} |
|
|
|
|
|
class MCPServer implements MCPServerConfig { |
|
|
constructor( |
|
|
public id: string, |
|
|
public name: string, |
|
|
public endpoint: string, |
|
|
public capabilities: string[], |
|
|
) {} |
|
|
} |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```python |
|
|
import requests |
|
|
from typing import Dict, List, Optional |
|
|
|
|
|
class MCPHubClient: |
|
|
def __init__(self, endpoint: str, api_key: str): |
|
|
self.endpoint = endpoint |
|
|
self.api_key = api_key |
|
|
self.headers = { |
|
|
'Authorization': f'Bearer {api_key}', |
|
|
'Content-Type': 'application/json' |
|
|
} |
|
|
|
|
|
def create_server(self, config: Dict) -> Dict: |
|
|
response = requests.post( |
|
|
f'{self.endpoint}/api/servers', |
|
|
json=config, |
|
|
headers=self.headers |
|
|
) |
|
|
return response.json() |
|
|
``` |
|
|
```` |
|
|
|
|
|
```python |
|
|
import requests |
|
|
from typing import Dict, List, Optional |
|
|
|
|
|
class MCPHubClient: |
|
|
def __init__(self, endpoint: str, api_key: str): |
|
|
self.endpoint = endpoint |
|
|
self.api_key = api_key |
|
|
self.headers = { |
|
|
'Authorization': f'Bearer {api_key}', |
|
|
'Content-Type': 'application/json' |
|
|
} |
|
|
|
|
|
def create_server(self, config: Dict) -> Dict: |
|
|
response = requests.post( |
|
|
f'{self.endpoint}/api/servers', |
|
|
json=config, |
|
|
headers=self.headers |
|
|
) |
|
|
return response.json() |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```yaml title="mcphub.yml" |
|
|
server: |
|
|
port: 3000 |
|
|
host: 0.0.0.0 |
|
|
|
|
|
database: |
|
|
type: postgresql |
|
|
host: localhost |
|
|
port: 5432 |
|
|
database: mcphub |
|
|
username: mcphub_user |
|
|
password: secure_password |
|
|
|
|
|
mcp: |
|
|
servers: |
|
|
- id: ai-assistant |
|
|
name: AI Assistant Server |
|
|
endpoint: https://ai.example.com |
|
|
capabilities: |
|
|
- chat |
|
|
- completion |
|
|
- id: data-processor |
|
|
name: Data Processing Server |
|
|
endpoint: https://data.example.com |
|
|
capabilities: |
|
|
- analysis |
|
|
- transformation |
|
|
|
|
|
routing: |
|
|
strategy: round_robin |
|
|
health_check: |
|
|
enabled: true |
|
|
interval: 30s |
|
|
timeout: 5s |
|
|
|
|
|
logging: |
|
|
level: info |
|
|
format: json |
|
|
file: /var/log/mcphub/app.log |
|
|
``` |
|
|
```` |
|
|
|
|
|
```yaml title="mcphub.yml" |
|
|
server: |
|
|
port: 3000 |
|
|
host: 0.0.0.0 |
|
|
|
|
|
database: |
|
|
type: postgresql |
|
|
host: localhost |
|
|
port: 5432 |
|
|
database: mcphub |
|
|
username: mcphub_user |
|
|
password: secure_password |
|
|
|
|
|
mcp: |
|
|
servers: |
|
|
- id: ai-assistant |
|
|
name: AI Assistant Server |
|
|
endpoint: https://ai.example.com |
|
|
capabilities: |
|
|
- chat |
|
|
- completion |
|
|
- id: data-processor |
|
|
name: Data Processing Server |
|
|
endpoint: https://data.example.com |
|
|
capabilities: |
|
|
- analysis |
|
|
- transformation |
|
|
|
|
|
routing: |
|
|
strategy: round_robin |
|
|
health_check: |
|
|
enabled: true |
|
|
interval: 30s |
|
|
timeout: 5s |
|
|
|
|
|
logging: |
|
|
level: info |
|
|
format: json |
|
|
file: /var/log/mcphub/app.log |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```json title="package.json" |
|
|
{ |
|
|
"name": "@mcphub/server", |
|
|
"version": "2.1.0", |
|
|
"description": "Model Context Protocol Hub Server", |
|
|
"main": "dist/index.js", |
|
|
"scripts": { |
|
|
"start": "node dist/index.js", |
|
|
"dev": "tsx watch src/index.ts", |
|
|
"build": "tsc", |
|
|
"test": "jest", |
|
|
"test:watch": "jest --watch", |
|
|
"lint": "eslint src/**/*.ts", |
|
|
"migrate": "prisma migrate deploy" |
|
|
}, |
|
|
"dependencies": { |
|
|
"@prisma/client": "^5.7.0", |
|
|
"express": "^4.18.2", |
|
|
"helmet": "^7.1.0", |
|
|
"cors": "^2.8.5", |
|
|
"jsonwebtoken": "^9.0.2", |
|
|
"bcryptjs": "^2.4.3", |
|
|
"winston": "^3.11.0" |
|
|
}, |
|
|
"devDependencies": { |
|
|
"@types/node": "^20.10.0", |
|
|
"@types/express": "^4.17.21", |
|
|
"typescript": "^5.3.0", |
|
|
"tsx": "^4.6.0", |
|
|
"jest": "^29.7.0", |
|
|
"eslint": "^8.55.0" |
|
|
} |
|
|
} |
|
|
``` |
|
|
```` |
|
|
|
|
|
```json title="package.json" |
|
|
{ |
|
|
"name": "@mcphub/server", |
|
|
"version": "2.1.0", |
|
|
"description": "Model Context Protocol Hub Server", |
|
|
"main": "dist/index.js", |
|
|
"scripts": { |
|
|
"start": "node dist/index.js", |
|
|
"dev": "tsx watch src/index.ts", |
|
|
"build": "tsc", |
|
|
"test": "jest", |
|
|
"test:watch": "jest --watch", |
|
|
"lint": "eslint src/**/*.ts", |
|
|
"migrate": "prisma migrate deploy" |
|
|
}, |
|
|
"dependencies": { |
|
|
"@prisma/client": "^5.7.0", |
|
|
"express": "^4.18.2", |
|
|
"helmet": "^7.1.0", |
|
|
"cors": "^2.8.5", |
|
|
"jsonwebtoken": "^9.0.2", |
|
|
"bcryptjs": "^2.4.3", |
|
|
"winston": "^3.11.0" |
|
|
}, |
|
|
"devDependencies": { |
|
|
"@types/node": "^20.10.0", |
|
|
"@types/express": "^4.17.21", |
|
|
"typescript": "^5.3.0", |
|
|
"tsx": "^4.6.0", |
|
|
"jest": "^29.7.0", |
|
|
"eslint": "^8.55.0" |
|
|
} |
|
|
} |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```dockerfile title="Dockerfile" |
|
|
FROM node:18-alpine AS builder |
|
|
|
|
|
WORKDIR /app |
|
|
|
|
|
|
|
|
COPY package*.json ./ |
|
|
COPY tsconfig.json ./ |
|
|
|
|
|
|
|
|
RUN npm ci --only=production |
|
|
|
|
|
|
|
|
COPY src/ ./src/ |
|
|
|
|
|
|
|
|
RUN npm run build |
|
|
|
|
|
|
|
|
FROM node:18-alpine AS production |
|
|
|
|
|
WORKDIR /app |
|
|
|
|
|
|
|
|
RUN addgroup -g 1001 -S nodejs |
|
|
RUN adduser -S mcphub -u 1001 |
|
|
|
|
|
|
|
|
COPY --from=builder /app/dist ./dist |
|
|
COPY --from=builder /app/node_modules ./node_modules |
|
|
COPY --from=builder /app/package*.json ./ |
|
|
|
|
|
|
|
|
USER mcphub |
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ |
|
|
CMD node dist/health-check.js |
|
|
|
|
|
EXPOSE 3000 |
|
|
|
|
|
CMD ["node", "dist/index.js"] |
|
|
``` |
|
|
```` |
|
|
|
|
|
```dockerfile title="Dockerfile" |
|
|
FROM node:18-alpine AS builder |
|
|
|
|
|
WORKDIR /app |
|
|
|
|
|
|
|
|
COPY package*.json ./ |
|
|
COPY tsconfig.json ./ |
|
|
|
|
|
|
|
|
RUN npm ci --only=production |
|
|
|
|
|
|
|
|
COPY src/ ./src/ |
|
|
|
|
|
|
|
|
RUN npm run build |
|
|
|
|
|
|
|
|
FROM node:18-alpine AS production |
|
|
|
|
|
WORKDIR /app |
|
|
|
|
|
|
|
|
RUN addgroup -g 1001 -S nodejs |
|
|
RUN adduser -S mcphub -u 1001 |
|
|
|
|
|
|
|
|
COPY --from=builder /app/dist ./dist |
|
|
COPY --from=builder /app/node_modules ./node_modules |
|
|
COPY --from=builder /app/package*.json ./ |
|
|
|
|
|
|
|
|
USER mcphub |
|
|
|
|
|
|
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ |
|
|
CMD node dist/health-check.js |
|
|
|
|
|
EXPOSE 3000 |
|
|
|
|
|
CMD ["node", "dist/index.js"] |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```bash |
|
|
|
|
|
git clone https://github.com/mcphub/mcphub.git |
|
|
cd mcphub |
|
|
|
|
|
|
|
|
npm install |
|
|
|
|
|
|
|
|
cp .env.example .env |
|
|
|
|
|
|
|
|
npm run db:setup |
|
|
|
|
|
|
|
|
npm run dev |
|
|
|
|
|
|
|
|
npm run build |
|
|
|
|
|
|
|
|
npm start |
|
|
``` |
|
|
```` |
|
|
|
|
|
```bash |
|
|
|
|
|
git clone https://github.com/mcphub/mcphub.git |
|
|
cd mcphub |
|
|
|
|
|
|
|
|
npm install |
|
|
|
|
|
|
|
|
cp .env.example .env |
|
|
|
|
|
|
|
|
npm run db:setup |
|
|
|
|
|
|
|
|
npm run dev |
|
|
|
|
|
|
|
|
npm run build |
|
|
|
|
|
|
|
|
npm start |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```powershell |
|
|
|
|
|
|
|
|
git clone https://github.com/mcphub/mcphub.git |
|
|
Set-Location mcphub |
|
|
|
|
|
|
|
|
npm install |
|
|
|
|
|
|
|
|
Copy-Item .env.example .env |
|
|
|
|
|
|
|
|
npm run dev |
|
|
``` |
|
|
```` |
|
|
|
|
|
```powershell |
|
|
|
|
|
|
|
|
git clone https://github.com/mcphub/mcphub.git |
|
|
Set-Location mcphub |
|
|
|
|
|
|
|
|
npm install |
|
|
|
|
|
|
|
|
Copy-Item .env.example .env |
|
|
|
|
|
|
|
|
npm run dev |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```bash |
|
|
|
|
|
docker run -d \ |
|
|
--name mcphub \ |
|
|
-p 3000:3000 \ |
|
|
-e NODE_ENV=production \ |
|
|
-e DATABASE_URL=postgresql://user:pass@host:5432/mcphub \ |
|
|
-e JWT_SECRET=your-secret-key \ |
|
|
mcphub/server:latest |
|
|
|
|
|
|
|
|
docker logs mcphub |
|
|
|
|
|
|
|
|
docker exec -it mcphub sh |
|
|
|
|
|
|
|
|
docker stop mcphub |
|
|
|
|
|
|
|
|
docker-compose up -d |
|
|
``` |
|
|
```` |
|
|
|
|
|
```bash |
|
|
|
|
|
docker run -d \ |
|
|
--name mcphub \ |
|
|
-p 3000:3000 \ |
|
|
-e NODE_ENV=production \ |
|
|
-e DATABASE_URL=postgresql://user:pass@host:5432/mcphub \ |
|
|
-e JWT_SECRET=your-secret-key \ |
|
|
mcphub/server:latest |
|
|
|
|
|
|
|
|
docker logs mcphub |
|
|
|
|
|
|
|
|
docker exec -it mcphub sh |
|
|
|
|
|
|
|
|
docker stop mcphub |
|
|
|
|
|
|
|
|
docker-compose up -d |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```bash |
|
|
|
|
|
curl -X POST https://api.mcphub.io/api/servers \ |
|
|
-H "Authorization: Bearer YOUR_API_TOKEN" \ |
|
|
-H "Content-Type: application/json" \ |
|
|
-d '{ |
|
|
"name": "AI Assistant Server", |
|
|
"endpoint": "https://ai.example.com", |
|
|
"capabilities": ["chat", "completion"], |
|
|
"groupId": "production" |
|
|
}' |
|
|
|
|
|
|
|
|
curl -X GET "https://api.mcphub.io/api/servers?limit=10&active=true" \ |
|
|
-H "Authorization: Bearer YOUR_API_TOKEN" |
|
|
|
|
|
|
|
|
curl -X PUT https://api.mcphub.io/api/servers/server-123 \ |
|
|
-H "Authorization: Bearer YOUR_API_TOKEN" \ |
|
|
-H "Content-Type: application/json" \ |
|
|
-d '{ |
|
|
"name": "Updated AI Assistant", |
|
|
"active": true |
|
|
}' |
|
|
|
|
|
|
|
|
curl -X DELETE https://api.mcphub.io/api/servers/server-123 \ |
|
|
-H "Authorization: Bearer YOUR_API_TOKEN" |
|
|
``` |
|
|
```` |
|
|
|
|
|
```bash |
|
|
|
|
|
curl -X POST https://api.mcphub.io/api/servers \ |
|
|
-H "Authorization: Bearer YOUR_API_TOKEN" \ |
|
|
-H "Content-Type: application/json" \ |
|
|
-d '{ |
|
|
"name": "AI Assistant Server", |
|
|
"endpoint": "https://ai.example.com", |
|
|
"capabilities": ["chat", "completion"], |
|
|
"groupId": "production" |
|
|
}' |
|
|
|
|
|
|
|
|
curl -X GET "https://api.mcphub.io/api/servers?limit=10&active=true" \ |
|
|
-H "Authorization: Bearer YOUR_API_TOKEN" |
|
|
|
|
|
|
|
|
curl -X PUT https://api.mcphub.io/api/servers/server-123 \ |
|
|
-H "Authorization: Bearer YOUR_API_TOKEN" \ |
|
|
-H "Content-Type: application/json" \ |
|
|
-d '{ |
|
|
"name": "Updated AI Assistant", |
|
|
"active": true |
|
|
}' |
|
|
|
|
|
|
|
|
curl -X DELETE https://api.mcphub.io/api/servers/server-123 \ |
|
|
-H "Authorization: Bearer YOUR_API_TOKEN" |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```http |
|
|
POST /api/servers HTTP/1.1 |
|
|
Host: api.mcphub.io |
|
|
Authorization: Bearer YOUR_API_TOKEN |
|
|
Content-Type: application/json |
|
|
|
|
|
{ |
|
|
"name": "AI Assistant Server", |
|
|
"endpoint": "https://ai.example.com", |
|
|
"capabilities": ["chat", "completion"], |
|
|
"groupId": "production" |
|
|
} |
|
|
``` |
|
|
```` |
|
|
|
|
|
```http |
|
|
POST /api/servers HTTP/1.1 |
|
|
Host: api.mcphub.io |
|
|
Authorization: Bearer YOUR_API_TOKEN |
|
|
Content-Type: application/json |
|
|
|
|
|
{ |
|
|
"name": "AI Assistant Server", |
|
|
"endpoint": "https://ai.example.com", |
|
|
"capabilities": ["chat", "completion"], |
|
|
"groupId": "production" |
|
|
} |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```sql |
|
|
-- 查询活跃的 MCP 服务器 |
|
|
SELECT |
|
|
id, |
|
|
name, |
|
|
endpoint, |
|
|
status, |
|
|
created_at |
|
|
FROM mcp_servers |
|
|
WHERE status = 'active' |
|
|
ORDER BY created_at DESC; |
|
|
|
|
|
-- 统计每个组的服务器数量 |
|
|
SELECT |
|
|
g.name as group_name, |
|
|
COUNT(s.id) as server_count |
|
|
FROM server_groups g |
|
|
LEFT JOIN mcp_servers s ON g.id = s.group_id |
|
|
GROUP BY g.id, g.name |
|
|
ORDER BY server_count DESC; |
|
|
|
|
|
-- 查询最近的错误日志 |
|
|
SELECT |
|
|
timestamp, |
|
|
level, |
|
|
message, |
|
|
metadata |
|
|
FROM logs |
|
|
WHERE level = 'error' |
|
|
AND timestamp >= NOW() - INTERVAL '1 hour' |
|
|
ORDER BY timestamp DESC |
|
|
LIMIT 50; |
|
|
``` |
|
|
```` |
|
|
|
|
|
```sql |
|
|
-- 查询活跃的 MCP 服务器 |
|
|
SELECT |
|
|
id, |
|
|
name, |
|
|
endpoint, |
|
|
status, |
|
|
created_at |
|
|
FROM mcp_servers |
|
|
WHERE status = 'active' |
|
|
ORDER BY created_at DESC; |
|
|
|
|
|
-- 统计每个组的服务器数量 |
|
|
SELECT |
|
|
g.name as group_name, |
|
|
COUNT(s.id) as server_count |
|
|
FROM server_groups g |
|
|
LEFT JOIN mcp_servers s ON g.id = s.group_id |
|
|
GROUP BY g.id, g.name |
|
|
ORDER BY server_count DESC; |
|
|
|
|
|
-- 查询最近的错误日志 |
|
|
SELECT |
|
|
timestamp, |
|
|
level, |
|
|
message, |
|
|
metadata |
|
|
FROM logs |
|
|
WHERE level = 'error' |
|
|
AND timestamp >= NOW() - INTERVAL '1 hour' |
|
|
ORDER BY timestamp DESC |
|
|
LIMIT 50; |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
始终为代码块指定正确的语言: |
|
|
|
|
|
````md |
|
|
````javascript // ✅ 正确 |
|
|
```js // ✅ 也可以 |
|
|
```; // ❌ 避免无语言标识 |
|
|
```` |
|
|
```` |
|
|
|
|
|
|
|
|
|
|
|
为配置文件和示例添加文件名: |
|
|
|
|
|
````md |
|
|
```yaml title="docker-compose.yml" |
|
|
version: '3.8' |
|
|
services: |
|
|
mcphub: |
|
|
image: mcphub/server:latest |
|
|
``` |
|
|
```` |
|
|
|
|
|
|
|
|
|
|
|
使用行号高亮重要代码: |
|
|
|
|
|
````md |
|
|
```javascript {3,7-9} |
|
|
const express = require('express'); |
|
|
const app = express(); |
|
|
const port = process.env.PORT || 3000; // 重要:端口配置 |
|
|
|
|
|
app.get('/health', (req, res) => { |
|
|
res.json({ status: 'ok' }); |
|
|
}); |
|
|
app.listen(port, () => { |
|
|
// 重要:服务器启动 |
|
|
console.log(`Server running on port ${port}`); |
|
|
}); // 重要:结束 |
|
|
``` |
|
|
```` |
|
|
|
|
|
|
|
|
|
|
|
添加有意义的中文注释: |
|
|
|
|
|
```javascript |
|
|
// 初始化 MCPHub 客户端 |
|
|
const client = new MCPHubClient({ |
|
|
endpoint: 'https://api.mcphub.io', |
|
|
apiKey: process.env.API_KEY, |
|
|
timeout: 30000, // 30 秒超时 |
|
|
retries: 3, // 重试 3 次 |
|
|
}); |
|
|
|
|
|
// 配置路由策略 |
|
|
client.setRoutingStrategy({ |
|
|
type: 'weighted', // 加权轮询 |
|
|
healthCheck: true, // 启用健康检查 |
|
|
fallback: 'round_robin', // 降级策略 |
|
|
}); |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
展示完整的错误处理: |
|
|
|
|
|
```javascript |
|
|
try { |
|
|
const server = await mcpClient.createServer({ |
|
|
name: 'AI Assistant', |
|
|
endpoint: 'https://ai.example.com', |
|
|
}); |
|
|
|
|
|
console.log('服务器创建成功:', server.id); |
|
|
} catch (error) { |
|
|
if (error.code === 'DUPLICATE_SERVER') { |
|
|
console.log('服务器已存在,跳过创建'); |
|
|
} else if (error.code === 'INVALID_ENDPOINT') { |
|
|
console.error('无效的端点地址:', error.message); |
|
|
} else { |
|
|
console.error('创建失败:', error.message); |
|
|
throw error; // 重新抛出未知错误 |
|
|
} |
|
|
} |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
MCPHub 文档支持以下编程语言的语法高亮: |
|
|
|
|
|
- **JavaScript/TypeScript**: `javascript`, `js`, `typescript`, `ts` |
|
|
- **Python**: `python`, `py` |
|
|
- **Shell/Bash**: `bash`, `shell`, `sh` |
|
|
- **PowerShell**: `powershell`, `ps1` |
|
|
- **SQL**: `sql`, `postgresql`, `mysql` |
|
|
- **YAML**: `yaml`, `yml` |
|
|
- **JSON**: `json` |
|
|
- **XML**: `xml` |
|
|
- **HTML**: `html` |
|
|
- **CSS**: `css` |
|
|
- **Dockerfile**: `dockerfile` |
|
|
- **Go**: `go` |
|
|
- **Rust**: `rust` |
|
|
- **Java**: `java` |
|
|
- **C#**: `csharp`, `cs` |
|
|
- **PHP**: `php` |
|
|
- **Ruby**: `ruby` |
|
|
- **HTTP**: `http` |
|
|
- **Markdown**: `markdown`, `md` |
|
|
|
|
|
````` |
|
|
|
|
|
|
|
|
|
|
|
````md |
|
|
```javascript |
|
|
console.log('Hello World'); |
|
|
````` |
|
|
|
|
|
````` |
|
|
|
|
|
|
|
|
|
|
|
我们使用 [Prism](https://prismjs.com/) 来语法高亮显示。Prism 支持 [各种编程语言](https://prismjs.com/#supported-languages)。 |
|
|
|
|
|
要添加语法高亮显示,请在代码块的第一行指定语言。 |
|
|
|
|
|
````md |
|
|
```python |
|
|
def hello(): |
|
|
print("Hello World") |
|
|
``` |
|
|
````` |
|
|
|
|
|
```python |
|
|
def hello(): |
|
|
print("Hello World") |
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
<CodeGroup> |
|
|
|
|
|
```bash npm |
|
|
npm i mintlify |
|
|
``` |
|
|
|
|
|
```bash yarn |
|
|
yarn add mintlify |
|
|
``` |
|
|
|
|
|
```bash pnpm |
|
|
pnpm add mintlify |
|
|
``` |
|
|
|
|
|
</CodeGroup> |
|
|
|
|
|
`CodeGroup` 允许您将多个代码块组合在一起,并为它们提供选项卡。 |
|
|
|
|
|
````md |
|
|
<CodeGroup> |
|
|
|
|
|
```bash npm |
|
|
npm i mintlify |
|
|
``` |
|
|
|
|
|
```bash yarn |
|
|
yarn add mintlify |
|
|
``` |
|
|
|
|
|
```bash pnpm |
|
|
pnpm add mintlify |
|
|
``` |
|
|
|
|
|
</CodeGroup> |
|
|
```` |
|
|
|
|
|
|
|
|
|
|
|
您也可以为代码块设置标题: |
|
|
|
|
|
```javascript hello.js |
|
|
const hello = 'world'; |
|
|
console.log(hello); |
|
|
``` |
|
|
|
|
|
````md |
|
|
```javascript hello.js |
|
|
const hello = 'world'; |
|
|
console.log(hello); |
|
|
``` |
|
|
```` |
|
|
|