Convertisseur Markdown vers DOCX

VérifiéPrudence

Convertissez des rapports de laboratoire en markdown vers des documents Word formatés avec conservation des images, tableaux et blocs de code. Idéal pour les soumissions académiques.

Spar Skills Guide Bot
DocumentationIntermédiaire
2002/06/2026
Claude CodeCursorWindsurf
#markdown#docx#pandoc#conversion#lab-report

Recommandé pour

Notre avis

Convertit des fichiers Markdown en documents Word (DOCX) avec une mise en forme académique, en préservant les images, tableaux et blocs de code.

Points forts

  • Script automatisé qui nettoie le Markdown avant conversion
  • Prise en charge des chemins d'images relatifs et redimensionnement
  • Validation post-conversion pour garantir la qualité
  • Gère les métadonnées et la numérotation des sections

Limites

  • Nécessite Python et pandoc installés (script peut télécharger pandoc)
  • La mise en forme avancée (tableaux complexes, annotations) peut nécessiter une retouche manuelle
  • Ne gère pas les diagrammes ou formules LaTeX complexes
Quand l'utiliser

Utilisez cette compétence lorsque vous devez soumettre un rapport de laboratoire au format DOCX à partir d'un fichier Markdown.

Quand l'éviter

Évitez cette compétence si le document final doit rester en Markdown, ou si vous avez besoin d'une mise en page très personnalisée qui dépasse les capacités de pandoc.

Analyse de sécurité

Prudence
Score qualité85/100

The skill involves running a Python script that can download external software (pandoc) and process files. While the intent is legitimate document conversion, the script's behavior (auto-download, file modification) introduces moderate risk if the script is compromised or misused.

Points d'attention
  • Skill instructs execution of a Python script from a shared directory (scripts/convert_md_to_docx.py) that may auto-download pandoc (network access).
  • Script modifies document files (removing alt text, horizontal rules) and could potentially overwrite arbitrary files if misused.

Exemples

Basic Markdown to DOCX
Convert this markdown file to a Word document: Lab_Report.md
Lab submission with specific output name
Convert my lab answer from markdown to docx using the script and name it Lab_Answer.docx
Bulk conversion of lab reports
Convert all .md files in this folder to .docx, keeping the same filenames

name: learning-md_to_docx description: Convert markdown lab reports to Word documents with proper formatting. Use when (1) user needs to submit .docx, (2) mentions "转docx" or "convert to word", (3) preparing lab submission.

Learning Markdown to DOCX Converter

Objectives

  • Convert .md files to .docx with proper formatting
  • Preserve images, tables, and code blocks
  • Apply academic document styling

Instructions

1. Recommended: Use the Conversion Script (Best Practice)

Always use the script for lab reports:

python .shared/skills/learning-md_to_docx/scripts/convert_md_to_docx.py Lab_Answer.md

The script automatically:

  • Removes image alt text (prevents "Step 1 Code", "Step 1 Result" from appearing in Word)
  • Removes horizontal rules --- (prevents visible lines in Word)
  • Handles relative image paths
  • Provides validation checklist

2. Pre-process Markdown (if using pandoc directly)

Remove horizontal rules before conversion:

  • Horizontal rules --- in markdown become visible lines in Word
  • Remove all --- separators if clean layout is desired
  • Alternative: Use blank lines for section spacing

Remove image alt text manually:

  • Change ![Step 1 Code](path.png) to ![](path.png)
  • Alt text appears as visible captions below images in Word

3. Direct Pandoc Command (if script unavailable)

Basic command:

pandoc input.md -o output.docx --resource-path="./images"

Alternative: Python script with python-docx

from docx import Document
from docx.shared import Inches, Pt
import markdown

2. Formatting Requirements

Document structure:

  • Title: Bold, 16pt
  • Student info: Name, ID, Section, Date
  • Headings: Hierarchical (Heading 1, 2, 3)
  • Body text: 11pt, single spacing
  • Code blocks: Courier New, 10pt, gray background
  • Images: Centered, with captions

Image handling:

  • Convert relative paths to absolute before processing
  • Resize images to fit page width (max 6 inches)
  • Control captions via alt text: ![Caption text](path) becomes figure caption
  • Use empty alt text ![](path) to avoid automatic captions
  • Maintain aspect ratio

3. Conversion Steps

  1. Pre-process markdown:

    • Remove horizontal rules --- if clean layout is needed
    • Resolve relative image paths
    • Clean up formatting inconsistencies
    • Verify all images exist
  2. Convert to DOCX:

    • Use pandoc or python-docx
    • Apply formatting rules
    • Insert images with proper sizing
  3. Post-process DOCX:

    • Verify all images display correctly
    • Check page breaks
    • Ensure consistent formatting
    • Add page numbers if required

4. Pandoc Command Examples

Basic conversion:

pandoc Lab1_Template.md -o Lab1.docx

With custom styling:

pandoc Lab1_Template.md -o Lab1.docx \
  --reference-doc=academic_template.docx \
  --toc \
  --number-sections

With metadata:

pandoc Lab1_Template.md -o Lab1.docx \
  -M title="Lab 1: Zipf's Law" \
  -M author="Student Name" \
  -M date="2026-01-20"

A ready-to-use script is available: scripts/convert_md_to_docx.py

Usage:

# Basic conversion
python scripts/convert_md_to_docx.py Lab1_Template.md

# Specify output filename
python scripts/convert_md_to_docx.py Lab1_Template.md Lab1.docx

# The script will:
# - Auto-download pandoc if needed
# - Handle relative image paths
# - Auto-remove image alt text (prevents captions in Word)
# - Provide validation checklist

Features:

  • Automatic pandoc installation
  • Relative path resolution for images
  • Auto-preprocessing:
    • Removes image alt text (e.g., ![Step 6 Code](path.png)![](path.png))
    • Removes horizontal rules --- (prevents visible lines in Word)
    • This prevents alt text from appearing as captions below images in Word
  • Error handling and troubleshooting tips
  • Validation checklist after conversion

Validation

Check the generated .docx:

  • [ ] All images display correctly
  • [ ] Headings are properly formatted
  • [ ] Code blocks are readable
  • [ ] Tables are formatted correctly
  • [ ] Page layout is appropriate
  • [ ] File size is reasonable (<10MB)

Common Issues

  • Missing images: Ensure all image paths are resolved before conversion
  • Broken formatting: Use --reference-doc with proper template
  • Large file size: Compress images before conversion
  • Chinese characters: Ensure UTF-8 encoding: pandoc -f markdown+east_asian_line_breaks
  • Unwanted text below images: Image alt text appears as captions in Word. Use empty alt text ![]() or short text ![Code]() to avoid verbose captions

Installation

Pandoc:

# Windows (using chocolatey)
choco install pandoc

# Or download from: https://pandoc.org/installing.html

Python packages:

pip install pypandoc python-docx
Skills similaires