({
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,
},
{
type: "import",
value: "https://cdn.jsdelivr.net/npm/mammoth@1.4.17/mammoth.browser.js",
},
],
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 }]
}
},
})