Mermaid 차트 14개를 개별 .mmd 파일로 추출 완료

- 14개 시장조사 차트를 개별 .mmd 파일로 분리
- 차트 변환 가이드 2종 추가 (README.md, 차트변환가이드.md)
- Mermaid Live Editor 활용 방법 상세 안내
- 프레젠테이션 시나리오별 차트 조합 추천
- 차트 문법 오류 수정 (차트 4번 막대 색상 파란색으로 변경)
- 추출 도구 스크립트 추가 (Python, PowerShell, Bash)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
merrycoral
2025-10-17 14:46:43 +09:00
parent 294516adfb
commit c1f116c821
21 changed files with 888 additions and 123 deletions
+96
View File
@@ -0,0 +1,96 @@
# Mermaid Syntax Checker using Docker Container
# Similar to PlantUML checker - keeps container running for better performance
param(
[Parameter(Mandatory=$true, Position=0)]
[string]$FilePath
)
# Check if file exists
if (-not (Test-Path $FilePath)) {
Write-Host "Error: File not found: $FilePath" -ForegroundColor Red
exit 1
}
# Get absolute path
$absolutePath = (Resolve-Path $FilePath).Path
$fileName = Split-Path $absolutePath -Leaf
Write-Host "`nChecking Mermaid syntax for: $fileName" -ForegroundColor Cyan
Write-Host ("=" * 60) -ForegroundColor Gray
# Check if mermaid container is running
$containerRunning = docker ps --filter "name=mermaid-cli" --format "{{.Names}}" 2>$null
if (-not $containerRunning) {
Write-Host "Error: Mermaid CLI container is not running." -ForegroundColor Red
Write-Host "Please follow the setup instructions in the Mermaid guide to start the container." -ForegroundColor Yellow
Write-Host "`nQuick setup commands:" -ForegroundColor Cyan
Write-Host ""
Write-Host "# 1. Start container with root privileges (port 48080)" -ForegroundColor Green
Write-Host "docker run -d --rm --name mermaid-cli -u root -p 48080:8080 --entrypoint sh minlag/mermaid-cli:latest -c `"while true;do sleep 3600; done`"" -ForegroundColor White
Write-Host ""
Write-Host "# 2. Install Chromium and dependencies" -ForegroundColor Green
Write-Host "docker exec mermaid-cli sh -c `"apk add --no-cache chromium chromium-chromedriver nss freetype harfbuzz ca-certificates ttf-freefont`"" -ForegroundColor White
Write-Host ""
Write-Host "# 3. Create Puppeteer configuration" -ForegroundColor Green
Write-Host "docker exec mermaid-cli sh -c `"echo '{```"executablePath```": ```"/usr/bin/chromium-browser```", ```"args```": [```"--no-sandbox```", ```"--disable-setuid-sandbox```", ```"--disable-dev-shm-usage```"]}' > /tmp/puppeteer-config.json`"" -ForegroundColor White
Write-Host ""
exit 1
}
# Set Puppeteer configuration file path
$puppeteerConfigFile = "/tmp/puppeteer-config.json"
# Generate unique temp filename
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
$processId = $PID
$tempFile = "/tmp/mermaid_${timestamp}_${processId}.mmd"
$outputFile = "/tmp/mermaid_${timestamp}_${processId}.svg"
try {
# Copy file to container
Write-Host "Copying file to container..." -ForegroundColor Gray
docker cp "$absolutePath" "mermaid-cli:$tempFile" 2>&1 | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Host "Error: Failed to copy file to container" -ForegroundColor Red
exit 1
}
# Run syntax check with Puppeteer configuration
Write-Host "Running syntax check..." -ForegroundColor Gray
$output = docker exec mermaid-cli sh -c "cd /home/mermaidcli && node_modules/.bin/mmdc -i '$tempFile' -o '$outputFile' -p '$puppeteerConfigFile' -q" 2>&1
$exitCode = $LASTEXITCODE
if ($exitCode -eq 0) {
Write-Host "`nSuccess: Mermaid syntax is valid!" -ForegroundColor Green
} else {
Write-Host "`nError: Mermaid syntax validation failed!" -ForegroundColor Red
Write-Host "`nError details:" -ForegroundColor Red
# Parse and display error messages
$errorLines = $output -split "`n"
foreach ($line in $errorLines) {
if ($line -match "Error:|Parse error|Expecting|Syntax error") {
Write-Host " $line" -ForegroundColor Red
} elseif ($line -match "line \d+|at line") {
Write-Host " $line" -ForegroundColor Yellow
} elseif ($line.Trim() -ne "") {
Write-Host " $line" -ForegroundColor DarkRed
}
}
exit 1
}
} finally {
# Clean up temp files
Write-Host "`nCleaning up..." -ForegroundColor Gray
docker exec mermaid-cli rm -f "$tempFile" "$outputFile" 2>&1 | Out-Null
}
Write-Host "`nValidation complete!" -ForegroundColor Cyan
# Note: Container is kept running for subsequent checks
# To stop: docker stop mermaid-cli && docker rm mermaid-cli
+65
View File
@@ -0,0 +1,65 @@
#!/bin/bash
# Extract mermaid charts from markdown file
INPUT_FILE="define/시장조사-차트.md"
OUTPUT_DIR="define/charts"
echo "Extracting Mermaid charts from: $INPUT_FILE"
echo "Output directory: $OUTPUT_DIR"
echo ""
# Create output directory
mkdir -p "$OUTPUT_DIR"
# Counter
chart_num=0
# Read file and extract charts
in_mermaid=false
current_chart=""
current_title=""
while IFS= read -r line || [ -n "$line" ]; do
# Check for section header (## number. title)
if [[ $line =~ ^##[[:space:]]([0-9]+)\.[[:space:]](.+)$ ]]; then
num="${BASH_REMATCH[1]}"
title="${BASH_REMATCH[2]}"
current_title=$(printf "chart%02d_%s" "$num" "${title// /_}")
current_title="${current_title//\//_}"
fi
# Check for mermaid start
if [[ $line == '```mermaid' ]]; then
in_mermaid=true
current_chart=""
continue
fi
# Check for mermaid end
if [[ $line == '```' ]] && $in_mermaid; then
# Save chart
if [ -n "$current_title" ]; then
filename="${current_title}.mmd"
echo "$current_chart" > "$OUTPUT_DIR/$filename"
echo " ✓ Saved: $filename"
((chart_num++))
fi
in_mermaid=false
current_chart=""
continue
fi
# Collect chart lines
if $in_mermaid; then
if [ -n "$current_chart" ]; then
current_chart+=$'\n'
fi
current_chart+="$line"
fi
done < "$INPUT_FILE"
echo ""
echo "✅ Successfully extracted $chart_num charts!"
echo ""
echo "Chart files saved in: $OUTPUT_DIR"
+47
View File
@@ -0,0 +1,47 @@
# Mermaid Chart Extractor
# Extracts Mermaid charts from markdown and saves them as individual .mmd files
$markdownFile = "define/시장조사-차트.md"
$outputDir = "define/charts"
Write-Host "Extracting Mermaid charts from: $markdownFile"
Write-Host "Output directory: $outputDir`n"
# Create output directory
if (-not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir | Out-Null
}
# Read markdown file
$content = Get-Content $markdownFile -Raw -Encoding UTF8
# Extract all mermaid blocks with their section headers
$pattern = '## (\d+)\. (.+?)\n\n```mermaid\n(.*?)```'
$matches = [regex]::Matches($content, $pattern, [System.Text.RegularExpressions.RegexOptions]::Singleline)
Write-Host "Found $($matches.Count) Mermaid charts`n"
# Save each chart
$count = 0
foreach ($match in $matches) {
$num = $match.Groups[1].Value
$title = $match.Groups[2].Value
$chartCode = $match.Groups[3].Value
# Clean filename
$filename = "chart$($num.PadLeft(2,'0'))_$($title.Replace(' ', '_').Replace('/', '_')).mmd"
$filepath = Join-Path $outputDir $filename
# Write mermaid code
$chartCode.Trim() | Out-File -FilePath $filepath -Encoding UTF8 -NoNewline
Write-Host " ✓ Saved: $filename"
$count++
}
Write-Host "`n✅ Successfully extracted $count charts!"
Write-Host "`nChart files saved in: $outputDir"
Write-Host "`nNext steps:"
Write-Host "1. Use Mermaid Live Editor: https://mermaid.live/"
Write-Host "2. Copy-paste each .mmd file content"
Write-Host "3. Export as PNG or SVG"
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
"""
Mermaid Chart Extractor
Extracts Mermaid charts from markdown and saves them as individual .mmd files
"""
import re
import os
from pathlib import Path
def extract_mermaid_charts(markdown_file, output_dir):
"""Extract all mermaid code blocks from markdown file"""
# Read markdown file
with open(markdown_file, 'r', encoding='utf-8') as f:
content = f.read()
# Find all mermaid code blocks
pattern = r'```mermaid\n(.*?)```'
matches = re.findall(pattern, content, re.DOTALL)
# Create output directory
os.makedirs(output_dir, exist_ok=True)
# Extract chart titles from markdown headers
title_pattern = r'## (\d+)\. (.+?)\n\n```mermaid'
titles = re.findall(title_pattern, content, re.DOTALL)
print(f"Found {len(matches)} Mermaid charts")
# Save each chart as separate .mmd file
for i, (chart_code, (num, title)) in enumerate(zip(matches, titles), 1):
# Clean filename
filename = f"chart{num:02d}_{title.replace(' ', '_').replace('/', '_')}.mmd"
filepath = os.path.join(output_dir, filename)
# Write mermaid code
with open(filepath, 'w', encoding='utf-8') as f:
f.write(chart_code.strip())
print(f" ✓ Saved: {filename}")
return len(matches)
if __name__ == "__main__":
# Configuration
markdown_file = "define/시장조사-차트.md"
output_dir = "define/charts"
print(f"Extracting Mermaid charts from: {markdown_file}")
print(f"Output directory: {output_dir}\n")
count = extract_mermaid_charts(markdown_file, output_dir)
print(f"\n✅ Successfully extracted {count} charts!")
print(f"\nNext steps:")
print(f"1. Use Mermaid Live Editor: https://mermaid.live/")
print(f"2. Copy-paste each .mmd file content")
print(f"3. Export as PNG or SVG")