Markdown to DOCX Converter

VerifiedSafe

Converts markdown files to Word documents (.docx) with proper academic formatting, preserving images, tables, and code blocks. Includes a dedicated script that automatically removes image alt text and horizontal rules to prevent layout issues in Word. Best used when preparing lab reports for submission as .docx.

Sby Skills Guide Bot
DocumentationIntermediate
6/2/2026
Claude Code
#markdown-to-docx#pandoc#lab-reports#document-conversion

Recommended for

Automated summary

Converts Markdown lab reports to Word (.docx) documents with proper formatting and academic styling.

Strengths

  • Dedicated script with automatic preprocessing (removes alt text and horizontal rules)
  • Handles relative image paths and resizes them appropriately
  • Includes a validation checklist after conversion

Limitations

  • Requires Pandoc installation (automated by script but not always available)
  • Complex formatting (nested tables, math) may be altered
  • Custom reference document (template) may require manual setup
When to use it

When you need to submit a lab report in .docx format with clean academic layout and proper styling.

When not to use it

If you only need a quick plain-text conversion or the document contains no special formatting.

Security analysis

Safe
Quality score85/100

The skill only provides instructions for local file conversion using standard tools like pandoc and Python scripts. There are no potentially destructive commands, network calls, or data exfiltration risks.

No concerns found

How this analysis is made

Examples

Convert lab report to DOCX
Convert my Lab_Answer.md file to a Word document with proper formatting, using the conversion script.
Submit lab in .docx format
I need to submit my lab report as a .docx. Please convert the markdown file and ensure images and code blocks are preserved.
Bulk conversion with pandoc
Convert multiple lab report .md files to .docx, applying academic template and table of contents.

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

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/markdown-to-docx-converter-mm5t8cdv/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/markdown-to-docx-converter-mm5t8cdv' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/markdown-to-docx-converter-mm5t8cdv/download' --output '.skill-downloads/markdown-to-docx-converter-mm5t8cdv/SKILL.md.part' && mv '.skill-downloads/markdown-to-docx-converter-mm5t8cdv/SKILL.md.part' '.skill-downloads/markdown-to-docx-converter-mm5t8cdv/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

Original excerpt: Installation

Pandoc:

# Windows (using chocolatey)
choco install pandoc

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

Python packages:

pip install pypandoc python-docx

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

This file does not provide a usable name/description header for this native procedure. It remains available to download and inspect; use the manual method below.

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/markdown-to-docx-converter-mm5t8cdv/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills