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 }]
}
}