mcpField
M
md-to-office

md-to-office

github.com/claude-office-skillsドキュメント5455.2k 回インストール39 週間前に更新
リポジトリ

md-to-office について

md-to-office は、Pandoc で Markdown を Office 形式などに変換するスキルです。テンプレートや変換オプションに対応し、Word、PowerPoint、PDF、HTML、LaTeX、EPUB などを出力できます。

主な機能

  1. 01Markdown を DOCX、PPTX、PDF に変換
  2. 02HTML、LaTeX、EPUB への出力
  3. 03参照テンプレートの適用
  4. 04メタデータと目次の設定
  5. 05ファイルの一括変換

活用シーン

  1. 01Markdown のメモを Word 文書に変換
  2. 02Markdown から PowerPoint スライドを作成
  3. 03テンプレートを使った PDF の生成

インストール

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

$npx skills add https://github.com/claude-office-skills/skills --skill md-to-office

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

詳細

Markdown から Office 形式への変換スキル

概要

このスキルを使うと、汎用ドキュメント変換ツールの Pandoc によって Markdown をさまざまな Office 形式に変換できます。書式や構造を保ちながら、Markdown ファイルをプロフェッショナルな Word ドキュメント、PowerPoint プレゼンテーション、PDF などに変換できます。

使い方

  1. Markdown の内容またはファイルを指定します
  2. 出力形式(docx、pptx、pdf など)を指定します
  3. 必要に応じて、スタイル設定用の参照テンプレートを指定します
  4. 最適な設定で Pandoc を使って変換します

プロンプトの例:

  • 「この README.md をプロフェッショナルな Word ドキュメントに変換してください」
  • 「Markdown のメモを PowerPoint プレゼンテーションにしてください」
  • 「カスタムスタイルを適用して、この Markdown から PDF を生成してください」
  • 「会社のテンプレートを使って、この Markdown から Word ドキュメントを作成してください」

ドメイン知識

Pandoc の基本
# Basic conversion
pandoc input.md -o output.docx
pandoc input.md -o output.pdf
pandoc input.md -o output.pptx

# With template
pandoc input.md --reference-doc=template.docx -o output.docx

# Multiple inputs
pandoc ch1.md ch2.md ch3.md -o book.docx
対応している変換
入力形式出力形式コマンド
MarkdownWordpandoc in.md -o out.docx
MarkdownPDFpandoc in.md -o out.pdf
MarkdownPowerPointpandoc in.md -o out.pptx
MarkdownHTMLpandoc in.md -o out.html
MarkdownLaTeXpandoc in.md -o out.tex
MarkdownEPUBpandoc in.md -o out.epub
Markdown から Word(.docx)への変換
基本的な変換
pandoc document.md -o document.docx
テンプレートを使う場合(参照ドキュメント)
# First create a template by converting sample
pandoc sample.md -o reference.docx

# Edit reference.docx styles in Word, then use it
pandoc input.md --reference-doc=reference.docx -o output.docx
目次を付ける場合
pandoc document.md --toc --toc-depth=3 -o document.docx
メタデータを付ける場合
pandoc document.md \
  --metadata title="My Report" \
  --metadata author="John Doe" \
  --metadata date="2024-01-15" \
  -o document.docx
Markdown から PDF への変換
LaTeX 経由(最高品質)
# Requires LaTeX installation
pandoc document.md -o document.pdf

# With custom settings
pandoc document.md \
  --pdf-engine=xelatex \
  -V geometry:margin=1in \
  -V fontsize=12pt \
  -o document.pdf
HTML/wkhtmltopdf 経由
pandoc document.md \
  --pdf-engine=wkhtmltopdf \
  --css=style.css \
  -o document.pdf
PDF のオプション
pandoc document.md \
  -V papersize:a4 \
  -V geometry:margin=2cm \
  -V fontfamily:libertinus \
  -V colorlinks:true \
  --toc \
  -o document.pdf
Markdown から PowerPoint(.pptx)への変換
基本的な変換
pandoc slides.md -o presentation.pptx
スライド向け Markdown の構成
---
title: Presentation Title
author: Author Name
date: January 2024
---

# Section Header (creates section divider)

## Slide Title

- Bullet point 1
- Bullet point 2
  - Sub-bullet

## Another Slide

Content here

::: notes
Speaker notes go here (not visible in slides)
:::

## Slide with Image

![Description](image.png){width=80%}

## Two Column Slide

:::::::::::::: {.columns}
::: {.column width="50%"}
Left column content
:::

::: {.column width="50%"}
Right column content
:::
::::::::::::::
テンプレートを使う場合
# Use corporate PowerPoint template
pandoc slides.md --reference-doc=template.pptx -o presentation.pptx
YAML フロントマター

Markdown の先頭にメタデータを追加します。

---
title: "Document Title"
author: "Author Name"
date: "2024-01-15"
abstract: "Brief description"
toc: true
toc-depth: 2
numbersections: true
geometry: margin=1in
fontsize: 11pt
documentclass: report
---

# First Chapter
...
Python との連携
import subprocess
import os

def md_to_docx(input_path, output_path, template=None):
    """Convert Markdown to Word document."""
    cmd = ['pandoc', input_path, '-o', output_path]
    
    if template:
        cmd.extend(['--reference-doc', template])
    
    subprocess.run(cmd, check=True)
    return output_path

def md_to_pdf(input_path, output_path, **options):
    """Convert Markdown to PDF with options."""
    cmd = ['pandoc', input_path, '-o', output_path]
    
    if options.get('toc'):
        cmd.append('--toc')
    
    if options.get('margin'):
        cmd.extend(['-V', f"geometry:margin={options['margin']}"])
    
    subprocess.run(cmd, check=True)
    return output_path

def md_to_pptx(input_path, output_path, template=None):
    """Convert Markdown to PowerPoint."""
    cmd = ['pandoc', input_path, '-o', output_path]
    
    if template:
        cmd.extend(['--reference-doc', template])
    
    subprocess.run(cmd, check=True)
    return output_path
pypandoc(Python ラッパー)
import pypandoc

# Simple conversion
output = pypandoc.convert_file('input.md', 'docx', outputfile='output.docx')

# With options
output = pypandoc.convert_file(
    'input.md', 
    'docx',
    outputfile='output.docx',
    extra_args=['--toc', '--reference-doc=template.docx']
)

# From string
md_content = "# Hello\n\nThis is markdown."
output = pypandoc.convert_text(md_content, 'docx', format='md', outputfile='output.docx')

ベストプラクティス

  1. テンプレートを使う:一貫したブランディングを適用するため、参照ドキュメントを作成します
  2. 見出しを構成する:見出しレベルを統一して使います(スライドには ##、セクションには #)
  3. 段階的にテストする:まず小さなセクションを変換し、書式を確認します
  4. メタデータを含める:ドキュメントのプロパティには YAML フロントマターを使います
  5. 画像を適切に扱う:相対パスを使い、寸法を指定します

よくあるパターン

一括変換
import subprocess
from pathlib import Path

def batch_convert(input_dir, output_format, output_dir=None):
    """Convert all markdown files in a directory."""
    input_path = Path(input_dir)
    output_path = Path(output_dir) if output_dir else input_path
    
    for md_file in input_path.glob('*.md'):
        output_file = output_path / md_file.with_suffix(f'.{output_format}').name
        subprocess.run([
            'pandoc', str(md_file), '-o', str(output_file)
        ], check=True)
        print(f"Converted: {md_file.name} -> {output_file.name}")

batch_convert('./docs', 'docx', './output')
レポート生成ツール
def generate_report(title, sections, output_path, template=None):
    """Generate Word report from structured data."""
    
    # Build markdown
    md_content = f"""---
title: "{title}"
date: "{datetime.now().strftime('%B %d, %Y')}"
---

"""
    for section_title, content in sections.items():
        md_content += f"# {section_title}\n\n{content}\n\n"
    
    # Write temp file
    with open('temp_report.md', 'w') as f:
        f.write(md_content)
    
    # Convert
    cmd = ['pandoc', 'temp_report.md', '-o', output_path, '--toc']
    if template:
        cmd.extend(['--reference-doc', template])
    
    subprocess.run(cmd, check=True)
    os.remove('temp_report.md')

例

例 1:技術ドキュメント
import subprocess

# Create comprehensive markdown
doc = """---
title: "API Documentation"
author: "Dev Team"
date: "2024-01-15"
toc: true
toc-depth: 2
---

# Introduction

This document describes the REST API for our service.

## Authentication

All API requests require an API key in the header:

Authorization: Bearer YOUR_API_KEY


## Endpoints

### GET /users

Retrieve all users.

**Response:**

| Field | Type | Description |
|-------|------|-------------|
| id | integer | User ID |
| name | string | Full name |
| email | string | Email address |

### POST /users

Create a new user.

**Request Body:**

```json
{
  "name": "John Doe",
  "email": "[email protected]"
}

エラーコード

コード意味
400リクエストが不正です
401認証されていません
404見つかりません
500サーバーエラー
"""

Markdown を保存

with open('api_docs.md', 'w') as f: f.write(doc)

Word に変換

subprocess.run([ 'pandoc', 'api_docs.md', '-o', 'api_documentation.docx', '--toc', '--reference-doc', 'company_template.docx' ], check=True)

PDF に変換

subprocess.run([ 'pandoc', 'api_docs.md', '-o', 'api_documentation.pdf', '--toc', '-V', 'geometry:margin=1in', '-V', 'fontsize=11pt' ], check=True)


### Example 2: Presentation from Markdown
```python
slides_md = """---
title: "Q4 Business Review"
author: "Sales Team"
date: "January 2024"
---

# Overview

## Agenda

- Q4 Performance Summary
- Regional Highlights
- 2024 Outlook
- Q&A

# Q4 Performance

## Key Metrics

- Revenue: $12.5M (+15% YoY)
- New Customers: 250
- Retention Rate: 94%

## Regional Performance

:::::::::::::: {.columns}
::: {.column width="50%"}
**North America**

- Revenue: $6.2M
- Growth: +18%
:::

::: {.column width="50%"}
**Europe**

- Revenue: $4.1M
- Growth: +12%
:::
::::::::::::::

# 2024 Outlook

## Strategic Priorities

1. Expand APAC presence
2. Launch new product line
3. Improve customer onboarding

## Revenue Targets

| Quarter | Target |
|---------|--------|
| Q1 | $13M |
| Q2 | $14M |
| Q3 | $15M |
| Q4 | $16M |

# Thank You

## Questions?

Contact: [email protected]
"""

with open('presentation.md', 'w') as f:
    f.write(slides_md)

subprocess.run([
    'pandoc', 'presentation.md',
    '-o', 'q4_review.pptx',
    '--reference-doc', 'company_slides.pptx'
], check=True)

制限事項

  • 複雑な Word の書式は完全には変換されない場合があります
  • PDF への変換には LaTeX または wkhtmltopdf が必要です
  • PowerPoint のアニメーションには対応していません
  • 高度な表は手動で調整が必要な場合があります
  • 画像の配置は難しい場合があります

インストール

# macOS
brew install pandoc

# Ubuntu/Debian
sudo apt-get install pandoc

# Windows
choco install pandoc

# Python wrapper
pip install pypandoc

リソース

コメント