md-to-docx

Convert Markdown files and strings into DOCX documents using @mohtasham/md-to-docx. Use when a user needs Markdown to Word conversion, CLI-based file conversion, options-driven styling/alignment/font family, TOC/page break handling, underline/strikethrough formatting, multi-section documents with per-section headers/footers, or programmatic conversion in Node/browser code.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "md-to-docx" with this command: npx skills add mohtashammurshid/md-to-docx/mohtashammurshid-md-to-docx-md-to-docx

md-to-docx

Use this skill to reliably produce .docx output from Markdown.

Workflow

  1. Decide the execution mode:
    • CLI mode for file-to-file conversion.
    • Programmatic mode for app code integration.
  2. Confirm input source (Markdown file or Markdown string).
  3. Confirm output target (.docx file path or browser download).
  4. Apply options only when requested (alignment, sizes, direction, font family, replacements, template, sections, page numbering).
  5. Run conversion and report resulting output path or filename.

CLI Mode

Use these commands:

npx @mohtasham/md-to-docx input.md output.docx
md-to-docx input.md output.docx
md-to-docx input.md output.docx --options options.json
md-to-docx input.md output.docx -o options.json
md-to-docx --help

CLI contract:

  • Required positional args: <input.md> <output.docx>
  • Optional options file: --options <options.json> or -o <options.json>
  • Options JSON can include the same shapes as the API: style, template, sections, and textReplacements
  • Help flags: -h or --help
  • On success, expect: DOCX created at: <absolute-path>

Programmatic Mode

import { convertMarkdownToDocx, downloadDocx } from "@mohtasham/md-to-docx";

const markdown = "# Title\n\nHello **DOCX**.";
const blob = await convertMarkdownToDocx(markdown, {
  documentType: "report",
  style: {
    fontFamily: "Trebuchet MS",
    heading1Alignment: "CENTER",
    paragraphAlignment: "JUSTIFIED",
    codeBlockAlignment: "LEFT",
    direction: "LTR"
  }
});

downloadDocx(blob, "output.docx");

Use convertMarkdownToDocx(markdown, options?) to produce a DOCX Blob. Use downloadDocx(blob, filename?) only in browser environments.

Multi-Section Documents

Use options.template for shared defaults and options.sections for per-section markdown and overrides:

const blob = await convertMarkdownToDocx("", {
  template: {
    footers: {
      default: { pageNumberDisplay: "currentAndTotal", alignment: "CENTER" }
    }
  },
  sections: [
    {
      markdown: "# Cover Page\n\nIntroduction here.",
      titlePage: true,
      headers: { first: { text: "Confidential", alignment: "RIGHT" } },
      pageNumbering: { start: 1, display: "none" }
    },
    {
      markdown: "# Chapter 1\n\nBody content.",
      style: { paragraphAlignment: "JUSTIFIED" },
      pageNumbering: { start: 1, display: "currentAndTotal" }
    }
  ]
});

Each section can override: style, headers, footers, pageNumbering, page (margins/size/orientation), titlePage, and type (break type).

Merge precedence:

  • Global style applies first
  • template provides shared section defaults
  • Per-section options win last

Use pageNumbering.display for common footer numbering modes: none, current, currentAndTotal, or currentAndSectionTotal.

Text Replacements

Use textReplacements to rewrite text before conversion:

const blob = await convertMarkdownToDocx("# Hello oldText", {
  textReplacements: [
    { find: /oldText/g, replace: "newText" },
    { find: "Hello", replace: "Hi" }
  ]
});

Markdown Features to Expect

Support includes:

  • Headings # to #####
  • Ordered/unordered lists
  • Bold, italic, underline (++text++), strikethrough (~~text~~)
  • Custom font family via fontFamily style option
  • Blockquotes
  • Tables (with inline formatting: bold, italic, code, links, strikethrough in cells)
  • Code blocks and inline code (with configurable codeBlockAlignment)
  • Links and images
  • Text replacements before rendering via textReplacements
  • COMMENT: ...
  • [TOC] on its own line
  • \pagebreak on its own line
  • Horizontal rules (---) are skipped during DOCX generation

Style Options Quick Reference

OptionValuesDefault
paragraphAlignmentLEFT, CENTER, RIGHT, JUSTIFIEDLEFT
headingAlignmentsameLEFT
heading1Alignmentheading5AlignmentsameLEFT
blockquoteAlignmentsameLEFT
codeBlockAlignmentsameLEFT
fontFamilyany font name stringCalibri
directionLTR, RTLLTR
tableLayoutautofit, fixedautofit
tocFontSizenumberlibrary default

Troubleshooting

  • If CLI fails with argument errors, re-check that exactly two positional paths are provided.
  • If options parsing fails, validate JSON syntax and ensure the root is an object.
  • If output is missing, verify destination directory permissions and path spelling.
  • If in Node and you need a file, write the returned Blob bytes to disk instead of using downloadDocx.
  • If sections produce unexpected numbering, ensure each section sets pageNumbering.start to reset counts.
  • If first-page headers or footers do not appear, set titlePage: true on that section.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

openclaw-version-monitor

监控 OpenClaw GitHub 版本更新,获取最新版本发布说明,翻译成中文, 并推送到 Telegram 和 Feishu。用于:(1) 定时检查版本更新 (2) 推送版本更新通知 (3) 生成中文版发布说明

Archived SourceRecently Updated
Coding

ask-claude

Delegate a task to Claude Code CLI and immediately report the result back in chat. Supports persistent sessions with full context memory. Safe execution: no data exfiltration, no external calls, file operations confined to workspace. Use when the user asks to run Claude, delegate a coding task, continue a previous Claude session, or any task benefiting from Claude Code's tools (file editing, code analysis, bash, etc.).

Archived SourceRecently Updated
Coding

ai-dating

This skill enables dating and matchmaking workflows. Use it when a user asks to make friends, find a partner, run matchmaking, or provide dating preferences/profile updates. The skill should execute `dating-cli` commands to complete profile setup, task creation/update, match checking, contact reveal, and review.

Archived SourceRecently Updated
Coding

clawhub-rate-limited-publisher

Queue and publish local skills to ClawHub with a strict 5-per-hour cap using the local clawhub CLI and host scheduler.

Archived SourceRecently Updated