Convert Word, Google Docs and web pages to clean Markdown
To convert a Word document, a Google Doc, or a web page into clean Markdown, match the tool to whether your file carries embedded images. For browser selections, Google Docs, and text-heavy .docx files up to 20 MB, MiaoYan's free HTML and Word to Markdown converter strips wrapper noise and rebuilds headings, nested lists, tables, and code fences locally in your browser without uploading your file. When a .docx contains embedded screenshots you want saved to disk, run pandoc with --extract-media, and when clipping docs straight into MiaoYan on Mac, ⌘V converts structured HTML on the fly.
Why naive copy-paste turns into broken Markdown
Copying formatted text puts both text/plain and text/html onto your clipboard. Pasting text/plain discards every heading level, link URL, bold word, and table border, while feeding raw text/html into an unguarded converter preserves the markup quirks of whichever app generated it:
- Google Docs wraps your entire selection inside one
<b style="font-weight:normal;" id="docs-internal-guid-...">tag and writes real bold, italic, and strikethrough on inner<span style="font-weight:700">orfont-style:italicelements. Converters that check tag names without reading inline styles wrap the whole document in**...**and drop the inner emphasis. - Desktop Microsoft Word puts lists on the clipboard as
<p style="mso-list:l0 level1 lfo1">paragraphs starting with<span style="mso-list:Ignore">·</span>rather than<ul>or<ol>. Without reconstructing thoselevelmarkers, nested lists flatten into plain dot-prefixed paragraphs. - Web selections drag along
<svg>icons, empty heading permalink<a href="...#heading"></a>anchors that become stray URLs,<nav>bars, and code-editor<span>soup lacking<pre>tags.
Three workflows that produce clean .md files
1. Browser conversion for Google Docs, Word, and web pages
Open HTML and Word to Markdown and press ⌘V anywhere on the page, or click Open file (or drop a file) to read a .docx or .html document under 20 MB. Nothing leaves your browser and nothing is written to localStorage.
Mammoth (1.13.0) reads .docx files in memory, and both pasted HTML and Word output pass through two cleanup stages:
- A normalization pass unwraps
docs-internal-guidandfont-weight: normal<b>wrappers, turnsspan[style]weights, italics, andline-throughrules into<strong>,<em>, and<del>tags (skipping redundant bold inside headings), and rebuilds consecutivemso-listparagraphs bylevelinto nested<ul>and<ol>lists. - An allowlist sanitizer rebuilds the DOM keeping only structural tags, safe
hrefandsrcschemes,alt,colspan, andlanguage-*code classes. Scripts, styles, SVGs, forms, and frames are removed, table cell pipes become\|, spaces in URLs are percent-encoded, and code fences automatically add extra backticks whenever the code inside already contains triple backticks.
Because a .md text output cannot store binary image bytes, embedded .docx pictures and data: images are skipped and counted in the status line (1 embedded image was left out...). Click Copy Markdown, Download .md, or Save to MiaoYan on a Mac when done.
2. Command-line Pandoc when .docx files contain images
A .docx file is a ZIP archive storing images inside word/media/. To extract both clean Markdown and every embedded picture onto disk, run Pandoc inside your notes folder:
pandoc -f docx -t gfm --extract-media=i --wrap=none input.docx -o note.md
Here -f docx reads Word's styles, tables, footnotes, and equations; -t gfm writes GitHub Flavored Markdown pipe tables, task lists, and ~~strikethrough~~ instead of Pandoc grid tables; --extract-media=i unpacks images into i/media/ and rewrites paths in note.md (MiaoYan resolves relative image paths from the note's folder, covered in Markdown image syntax: insert, resize and fix paths); and --wrap=none keeps paragraphs on single lines instead of wrapping at 72 columns.
For the reverse conversion back to .docx, see Markdown to Word: Pandoc, reference.docx and MiaoYan exports. For full workspace exports from Notion or Evernote, see Export Notion and Evernote to Markdown files.
3. Pasting web pages directly into MiaoYan on Mac
When clipping documentation, blog posts, or AI web answers into MiaoYan on Mac (GitHub, App Store), ⌘V runs HtmlToMarkdown.swift with three built-in guards:
- It converts clipboard HTML only when block tags (
<h1-h6>,<table>,<ul>,<ol>,<blockquote>,<pre>) are present, so syntax-highlighted<span>code copied from Xcode or VS Code pastes cleanly as plain text. - When your cursor sits inside an existing fenced code block, HTML conversion turns off so pasting never nests a second fence inside the first.
- Copying a single heading line from a web page pastes just its words without
#marks, and empty permalink icon links are stripped.
Press ⇧⌘V (Edit > Paste and Match Style) whenever you want unformatted plain text. Because the Mac app parses clipboard HTML with Foundation's HTML tidy and does not yet include the browser tool's docs-internal-guid and mso-list pass, run Google Docs and desktop Word copies through HTML and Word to Markdown before pasting into a note.
What to check after converting
- Check merged cells in tables. GFM pipe tables cannot express
rowspan, so merged Word cells flatten row by row; review wide tables in split preview (⌘\). - Check visual headings. Paragraphs manually enlarged to bold 16pt in Word instead of using
Heading 1orHeading 2styles convert as bold paragraphs rather than##headings. - Re-save legacy
.docbinaries as.docxin Word, Pages, or LibreOffice first, since both Mammoth andpandoc -f docxexpect XML-based.docxarchives.
FAQ
Does the online HTML and Word to Markdown tool upload my .docx file?
No. Mammoth and the converter run entirely inside your browser tab, no file bytes leave your device, and nothing is kept in localStorage.
Why did pasting from Google Docs directly into a Markdown editor make everything bold?
Google Docs wraps copied HTML in <b style="font-weight:normal" id="docs-internal-guid-...">. Paste into HTML and Word to Markdown first so that outer tag is unwrapped while real inline bold and italic styles are preserved.
How do I handle .emf or .wmf clipart extracted by Pandoc?
pandoc --extract-media=i saves .emf and .wmf files to disk, though Markdown previews cannot render Windows metafiles directly. Convert them to .png with LibreOffice or ImageMagick and update the file extension in note.md.
How do spreadsheet tables from Excel or Numbers convert?
Copied spreadsheet ranges carry an HTML <table>, which both MiaoYan and /tools/html-to-markdown/ convert into a GFM pipe table; for interactive row editing and CJK column alignment, use the Markdown table generator.
