Word Document to Markdown

Convert a Microsoft Word document to Markdown in the browser.

Face with waiting expression Nothing to see yet!

Loading takeymakey...
TakeyMakey code
Want this tool to do something else? Edit the code below and make it do whatever you want.
import mammoth from "https://cdn.jsdelivr.net/npm/mammoth@1.9.0/+esm"

export const take = [
  {
    key: "buffer",
    type: "file",
    label: "Document",
    accept: ".doc,.docx,application/msword",
    read: "buffer",
  },
  {
    key: "stripbs",
    type: "toggle",
    label: "Strip excess backslashes",
    value: true,
  },
  {
    key: "stripnl",
    type: "toggle",
    label: "Remove excess new lines",
    value: true,
  },
]

export const make = async ({ buffer: arrayBuffer, stripbs, stripnl }) => {
  let value

  if (arrayBuffer) {
    value = (await mammoth.convertToMarkdown({ arrayBuffer })).value

    if (stripbs) {
      value = value.replace(/\\/g, "")
    }

    if (stripnl) {
      value = value.replace(/\n +/g, "\n").replace(/\n\n\s*/g, "\n\n")
    }

    return [{ type: "code", value }]
  }
}