mcpField
W
word-formatter

word-formatter

github.com/didixuxuドキュメント8639 回インストール22 週間前に更新
リポジトリ

word-formatter について

word-formatterは、DOCX、TXT、Markdownの草稿を整ったWordやPDFに仕上げる文書整形スキルです。文書の種類を分析し、再構成の度合いを選べるほか、チャートやイラストも追加できます。

主な機能

  1. 01文書の種類と内容の分析
  2. 023段階の処理レベル
  3. 03ビジネス・モダン・学術スタイル
  4. 04チャートとイラストの計画
  5. 05DOCXとPDFで出力

活用シーン

  1. 01議事録やレポートの整理
  2. 02草稿を体裁の整ったWord文書に変換
  3. 03データの多い文書へのチャート追加

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/didixuxu/didi-skills --skill word-formatter

インストール後、Claude Code で/word-formatterを入力して読み込まれたか確認します。

同梱ファイルformatter.pystyles/styles.json

詳細

Word Formatter

乱雑なドキュメントを、インテリジェントなレイアウトと自動生成画像を活用して、プロフェッショナルな形式の Word/PDF ファイルに変換します。

使用する場面

  • ユーザーから、整理が必要な Word ドキュメント(.docx)またはテキストファイルが提供された場合
  • ドキュメントの「書式を整える」「見栄えをよくする」「再構成する」よう依頼された場合
  • プレーンテキストの内容にビジュアルやグラフを追加する必要がある場合
  • メモや下書きをプロフェッショナルなドキュメントに変換する場合

ワークフロー

1. Analyze Document → 2. User Chooses Level → 3. Format → 4. Generate Images → 5. Output

ステップ 1:ドキュメントを分析する

入力ファイルを読み込み、次の項目を検出します。

# Content type detection keywords
CONTENT_TYPES = {
    "meeting_notes": ["会议", "议程", "参会", "决议", "行动项", "meeting", "agenda"],
    "report": ["报告", "总结", "分析", "数据", "report", "analysis", "summary"],
    "study_notes": ["笔记", "学习", "知识点", "概念", "notes", "learning"],
    "proposal": ["方案", "计划", "目标", "预算", "proposal", "plan", "budget"]
}

# Style mapping
STYLE_MAP = {
    "meeting_notes": "business_formal",
    "report": "business_formal",
    "study_notes": "modern_minimal",
    "proposal": "academic"
}

分析結果をユーザーに提示します:

检测结果:
- 文档类型: [类型]
- 建议风格: [风格]
- 字数: [X] 字
- 检测到数据: [是/否]

ステップ 2:ユーザーが処理レベルを選択する

ユーザーに次のいずれかを選択してもらいます。

レベル説明
書式設定のみ原文の内容を維持し、書式スタイルのみを調整します
軽度の再構成小見出しの追加、段落の調整、つなぎの補足を行います
大幅な再構成内容の書き換え、表現の改善、論理の補足を行う場合があります

ステップ 3:書式を適用する

スタイルの定義

ビジネスフォーマル(商务正式):

BUSINESS_STYLE = {
    "title_font": "Microsoft YaHei",
    "title_size": 22,
    "heading1_size": 16,
    "heading2_size": 14,
    "body_size": 11,
    "line_spacing": 1.5,
    "colors": {
        "primary": "#1a365d",    # Deep blue
        "accent": "#2b6cb0",     # Medium blue
        "text": "#2d3748"        # Dark gray
    }
}

モダンミニマル(简约现代):

MODERN_STYLE = {
    "title_font": "PingFang SC",
    "title_size": 24,
    "heading1_size": 18,
    "heading2_size": 14,
    "body_size": 11,
    "line_spacing": 1.8,
    "colors": {
        "primary": "#1a202c",    # Near black
        "accent": "#4a5568",     # Gray
        "text": "#2d3748"
    }
}

アカデミック(学术风格):

ACADEMIC_STYLE = {
    "title_font": "SimSun",
    "title_size": 18,
    "heading1_size": 15,
    "heading2_size": 13,
    "body_size": 12,
    "line_spacing": 1.5,
    "colors": {
        "primary": "#1a202c",
        "accent": "#4a5568",
        "text": "#000000"
    }
}
ドキュメント構成
def structure_document(content, level):
    """
    Structure document based on processing level
    """
    if level == "format_only":
        # Keep original structure, apply styles
        return apply_styles(content)

    elif level == "light_restructure":
        # Add headings, reorder paragraphs, add transitions
        sections = detect_sections(content)
        sections = add_subheadings(sections)
        sections = add_transitions(sections)
        return apply_styles(sections)

    elif level == "deep_restructure":
        # Rewrite unclear parts, add logic, improve flow
        sections = detect_sections(content)
        sections = rewrite_unclear(sections)
        sections = add_missing_logic(sections)
        sections = optimize_expression(sections)
        return apply_styles(sections)

ステップ 4:画像を生成する

画像の判断ロジック
def decide_images(content):
    """
    Decide what images to generate based on content
    """
    images = []

    # Check for data → Charts
    if contains_data(content):
        data_sections = extract_data(content)
        for section in data_sections:
            chart_type = suggest_chart_type(section)
            images.append({
                "type": "chart",
                "chart_type": chart_type,
                "data": section
            })

    # Check for concepts → AI illustrations
    concepts = extract_key_concepts(content)
    if concepts:
        images.append({
            "type": "illustration",
            "concept": concepts[0],
            "style": get_document_style()
        })

    # Add cover image
    images.append({
        "type": "cover",
        "title": get_document_title(content),
        "style": get_document_style()
    })

    return images
グラフの生成
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['PingFang SC', 'Microsoft YaHei']

def generate_chart(data, chart_type, style):
    """
    Generate chart matching document style
    """
    colors = style["colors"]

    fig, ax = plt.subplots(figsize=(10, 6))

    if chart_type == "bar":
        ax.bar(data["labels"], data["values"], color=colors["primary"])
    elif chart_type == "pie":
        ax.pie(data["values"], labels=data["labels"],
               colors=[colors["primary"], colors["accent"], "#e2e8f0"])
    elif chart_type == "line":
        ax.plot(data["x"], data["y"], color=colors["primary"], linewidth=2)

    ax.set_title(data["title"], fontsize=14, color=colors["text"])

    return fig
AI イラストの生成

generate-image スキルを使用します。

Prompt template for business style:
"Professional business illustration of [concept],
flat design, corporate blue color scheme,
minimalist, clean background, vector style"

Prompt template for modern style:
"Modern minimalist illustration of [concept],
geometric shapes, black and white with accent color,
clean lines, abstract, professional"

Prompt template for academic style:
"Educational diagram illustrating [concept],
clean and simple, textbook style,
labeled components, neutral colors"
画像の確認

画像の計画をユーザーに提示します。

配图方案:
1. 封面图: [主题描述]
2. 数据图表: [图表类型] - [数据来源段落]
3. 概念插图: [概念名称]

请选择:
A) 全部生成
B) 部分修改 (请指定)
C) 跳过配图

ステップ 5:ファイルを出力する

Word ドキュメントを生成する
from docx import Document
from docx.shared import Pt, Inches, RGBColor
from docx.enum.text import WD_ALIGN_PARAGRAPH

def create_word_document(content, images, style):
    doc = Document()

    # Set page margins
    for section in doc.sections:
        section.top_margin = Inches(1)
        section.bottom_margin = Inches(1)
        section.left_margin = Inches(1.25)
        section.right_margin = Inches(1.25)

    # Add cover image if exists
    if images.get("cover"):
        doc.add_picture(images["cover"], width=Inches(6))
        doc.add_page_break()

    # Add content with styles
    for element in content:
        if element["type"] == "title":
            p = doc.add_heading(element["text"], level=0)
            p.alignment = WD_ALIGN_PARAGRAPH.CENTER
        elif element["type"] == "heading1":
            doc.add_heading(element["text"], level=1)
        elif element["type"] == "heading2":
            doc.add_heading(element["text"], level=2)
        elif element["type"] == "paragraph":
            p = doc.add_paragraph(element["text"])
            p.paragraph_format.line_spacing = style["line_spacing"]
        elif element["type"] == "image":
            doc.add_picture(element["path"], width=Inches(5))

    return doc
PDF に変換する
# Using LibreOffice (cross-platform)
libreoffice --headless --convert-to pdf --outdir [output_dir] [docx_file]

# Or using docx2pdf (requires MS Word on Windows/Mac)
# pip install docx2pdf
from docx2pdf import convert

def export_pdf(docx_path):
    pdf_path = docx_path.replace('.docx', '.pdf')
    convert(docx_path, pdf_path)
    return pdf_path
出力ファイル名
def get_output_paths(input_path):
    base = os.path.splitext(input_path)[0]
    return {
        "docx": f"{base}_formatted.docx",
        "pdf": f"{base}_formatted.pdf"
    }

一連の操作の流れ

User: /word-formatter /path/to/messy_document.docx

Claude: 正在分析文档...

检测结果:
- 文档类型: 工作报告
- 建议风格: 商务正式
- 字数: 2,350 字
- 检测到数据: 是 (3处数据可视化)

请选择处理程度:
A) 仅排版 - 保持原文,调整格式
B) 轻度重组 - 添加小标题,优化结构
C) 深度重构 - 可重写内容,优化表达

User: B

Claude: 好的,将进行轻度重组。正在处理...

配图方案:
1. 封面图: 商务风格的工作报告封面
2. 柱状图: 季度销售数据对比
3. 饼图: 市场份额分布
4. 概念插图: 增长策略示意图

请选择:
A) 全部生成
B) 部分修改
C) 跳过配图

User: A

Claude: 正在生成配图...
[生成图片中...]

完成!输出文件:
- /path/to/messy_document_formatted.docx
- /path/to/messy_document_formatted.pdf

需要调整吗?

依存関係

# Required Python packages
pip install python-docx matplotlib docx2pdf pillow

# For PDF conversion (alternative to docx2pdf)
# macOS: brew install --cask libreoffice
# Ubuntu: sudo apt install libreoffice

エラー処理

エラー対処方法
ファイルが存在しないパスを確認するようユーザーに案内します
未対応の形式.docx、.txt、.md のみ対応しています
画像の生成に失敗該当の画像をスキップして処理を続行します
PDF への変換に失敗Word のみを出力し、依存関係のインストールを案内します

ヒント

  • 入力ドキュメントの構造が整っているほど、書式設定の効果が高まります
  • 大幅な再構成モードでは、Claude がドキュメントの論理構成の改善を試みます
  • 挿入する画像には、ドキュメントのスタイルに合った配色が自動的に適用されます
  • 複数回実行して、段階的に最適化できます

コメント