{"_id":"mammoth-plus","_rev":"2-41944f776517c9feea98bed2dc11c38a","name":"mammoth-plus","dist-tags":{"latest":"2.0.2"},"versions":{"2.0.0":{"name":"mammoth-plus","version":"2.0.0","author":{"name":"heweifeng","email":"iheweifeng@gmail.com"},"description":"Convert Word documents from docx to rich HTML and Markdown","keywords":["docx","html","office","word","math","MathML","style","markdown","md"],"main":"./lib/index.js","repository":{"type":"git","url":"git+https://github.com/ihwf/mammoth-plus.git"},"dependencies":{"argparse":"~1.0.3","bluebird":"~3.4.0","clone":"^2.1.2","dingbat-to-unicode":"^1.0.1","jszip":"^3.7.1","lop":"^0.4.1","omml2mathml":"^1.3.0","path-is-absolute":"^1.0.0","sax":"~1.1.1","underscore":"^1.13.1","xmlbuilder":"^10.0.0","xmldom":"^0.6.0"},"devDependencies":{"browserify":"~13.0.1","browserify-prepend-licenses":"~1.0.0","duck":"^0.1.12","eslint":"2.13.1","hamjest":"2.13.0","mocha":"~2.2.5","temp":"^0.9.4","uglify-js":"~3.17.4"},"browser":{"./lib/unzip.js":"./browser/unzip.js","./lib/docx/files.js":"./browser/docx/files.js"},"bin":{"mammoth-plus":"bin/mammoth-plus"},"scripts":{"pretest":"eslint lib test","test":"mocha 'test/**/*.tests.js'","prepare":"make mammoth-plus.browser.min.js"},"license":"BSD-2-Clause","types":"./lib/index.d.ts","gitHead":"4d0ddde28bc97130931348ad45a1539afd04a8d1","bugs":{"url":"https://github.com/ihwf/mammoth-plus/issues"},"homepage":"https://github.com/ihwf/mammoth-plus#readme","_id":"mammoth-plus@2.0.0","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-ZyoE2BjYgfCoSXFvOZI2Hbc+5S+kS9B6KqbsPcRBEmfxLWNjfg2+szRmnWyd2DrvwcBlDhfO3kKTXhiWWFo2mw==","shasum":"c5175f2bb157e39194ba3f846e79b60fe7140d84","tarball":"https://registry.npmjs.org/mammoth-plus/-/mammoth-plus-2.0.0.tgz","fileCount":512,"unpackedSize":9091718,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC/c7UtAyScIjilbX7ZoGzUMcwLftJqqT3eJ5t35CHwagIhAMXBZpgdwkcHt0yL4h3F1sqRCKb+sjCK6fM4aXcgxHxh"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjkt9WACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmo6WBAAm91Vwjuxw+EBU8vWtRO4N7viL2kjkHNsdMoMcbMlaKedJURz\r\neDQjGNRqfWr9rT90TrvoKnFMbCpb+pV9Y4m5nw3JobgYZ+3tdxZcGXjT0juB\r\n6FzbmGG27plLYA5au4xp6zKuZb7HRAdHPTiIUievZWJzBrtnKg1AnrTaTwHn\r\nSs7bM7k0nJEGdyYaZxFoFL8yNxNa4lk5aN42LjrqyT20+uYIR+7dCv5DZzW+\r\nvqF/qhtJhoy0XzfNuUzCSq0g6n/tiEP6RZQOfWB/MKGhpMwDbbdOF/8u+23b\r\nl4Zg5lhevdacGcqMTzOpB/+zHxRbQc7wxCNBDVM9jE4ij6ygWuNToe5mL7Gx\r\nrq2ejWPMiCSVn/3JTUiYhWBdqiqvR2mazSTyLruYE0Yf3nM5XmjjhJ8olLdF\r\ns+o6mwsnAlRir92+Ib+oJCW/xifqeu6jqMjXV2jg3rTKUoT3+nqjbKsL+ZJ5\r\n1pMqnHf1sPC+bI5hTYsSOyNuAU1/maYVJ0HAlqVTNfK24rj3FYezzsemmvm6\r\nZfZchPfHQL8fBRxVgrQbmtq1PygbK2PO1SKqdCSalyQ66sIqfpC6cb3qakdL\r\nSj4xfC4aZFd8tV82QiQuIfCiFXl8O0zSKqE2m5Uf1X/3zMV8WrEiUPphA4vH\r\nzOKI85wGcvclmkQUQm5suXm/AvgMFPgKcvc=\r\n=zxd/\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"heweifeng","email":"iheweifeng@gmail.com"},"directories":{},"maintainers":[{"name":"heweifeng","email":"iheweifeng@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mammoth-plus_2.0.0_1670569814666_0.003635261782572341"},"_hasShrinkwrap":false},"2.0.1":{"name":"mammoth-plus","version":"2.0.1","author":{"name":"heweifeng","email":"iheweifeng@gmail.com"},"description":"Convert Word documents from docx to rich HTML and Markdown","keywords":["docx","html","office","word","math","MathML","style","markdown","md"],"main":"./lib/index.js","repository":{"type":"git","url":"git+https://github.com/ihwf/mammoth-plus.git"},"dependencies":{"argparse":"~1.0.3","bluebird":"~3.4.0","clone":"^2.1.2","dingbat-to-unicode":"^1.0.1","jszip":"^3.7.1","lop":"^0.4.1","omml2mathml":"^1.3.0","path-is-absolute":"^1.0.0","sax":"~1.1.1","underscore":"^1.13.1","xmlbuilder":"^10.0.0","xmldom":"^0.6.0"},"devDependencies":{"browserify":"~13.0.1","browserify-prepend-licenses":"~1.0.0","duck":"^0.1.12","eslint":"2.13.1","hamjest":"2.13.0","mocha":"~2.2.5","temp":"^0.9.4","uglify-js":"~3.17.4"},"browser":{"./lib/unzip.js":"./browser/unzip.js","./lib/docx/files.js":"./browser/docx/files.js"},"bin":{"mammoth-plus":"bin/mammoth-plus"},"scripts":{"pretest":"eslint lib test","test":"mocha 'test/**/*.tests.js'","prepare":"make mammoth-plus.browser.min.js"},"license":"BSD-2-Clause","types":"./lib/index.d.ts","gitHead":"ddce45ac1da5e3d3caccefbc3bedbdb2a4ff2c9d","bugs":{"url":"https://github.com/ihwf/mammoth-plus/issues"},"homepage":"https://github.com/ihwf/mammoth-plus#readme","_id":"mammoth-plus@2.0.1","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-bjzh8gr1Ckj/L9SAH/uuUAU65p4JPosOP4D2N6K8aBozV7e5aaHQ3w/NveWDVOniBm9j575G268DzlQQ9UF4lw==","shasum":"a3bdde886280a108b2bf1268665f3f70f6083cdb","tarball":"https://registry.npmjs.org/mammoth-plus/-/mammoth-plus-2.0.1.tgz","fileCount":52,"unpackedSize":2193599,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG2W24bhdB4wNRd8YVTLLv1Pw2hdeHvQ+YbrsKgYuBvjAiEApoIcA1WTllpC74bpKtSbrrRq3nNHnKb9nEY8RaoFCgM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjkuSfACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqA4g/+N0yrY0BAME0dqzlIT2VL8h+q1e3pW9QgmuNtD1/Jg7WxbuMT\r\nEeGWGCbwqXOJ1XMRLvJb0vnZuoHcu3eWLW35UrH4rrRrDh9KbDA2tt4vb2cs\r\nfoCffKurzNSjVklfbjeYeTzo2rZ/EubsylUonrBoMC7qFHojotTnIKC5rMiR\r\n4LO4BVeMcAMpPOTYMHrX92CNL0S+wRvtCNa0xh2wHXJiwJnjf0wtsv+AALs5\r\nvU1AXYVdKRtfpqL/1b3NdBtLMTliQpHQPhjRTJVGDWohJoUAmv/ALgfUl9fQ\r\n1Nr2wW8ZWh66+sK7V7D5AkkVN8UHycaMsbpgBRcISgYJBk4G0zmQK1ZyU012\r\nmtCqtqsMHoN7LGOyxPF9hVWbzmchX4vIvIzyXJPZa2jRwAWcRHRRfP1zjBPL\r\nzDEYLzohagqVFFppv6rXk55tXZLpVBqHirDalOGKCGOB2oaPcU+Ie0FAGVBF\r\n5CfzQHS5K2FWqMuW5uU2KNsSel2iMXPSJpKYfzh2iiHlLmx073Rhxg3PqrNH\r\nliY5fHm/s/6dXKoomv0Xb3IqZlEs9oh6tzl9ebyV94D8QGLa33dDu20EbZ2X\r\nKYk8abaaPZL+oG3Z78U5FLQh+IyJB0tbzIfjB0vnwCCS1WIVIjAzP+ito3yb\r\n6bklVXj8dzve1XeHEt2iEwLAQvdYJyBORLU=\r\n=vcwA\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"heweifeng","email":"iheweifeng@gmail.com"},"directories":{},"maintainers":[{"name":"heweifeng","email":"iheweifeng@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mammoth-plus_2.0.1_1670571167356_0.017102790668201973"},"_hasShrinkwrap":false},"2.0.2":{"name":"mammoth-plus","version":"2.0.2","author":{"name":"heweifeng","email":"iheweifeng@gmail.com"},"description":"Convert Word documents from docx to rich HTML and Markdown","keywords":["docx","html","office","word","math","MathML","style","markdown","md"],"main":"./dist/mammoth-plus.min.js","repository":{"type":"git","url":"git+https://github.com/ihwf/mammoth-plus.git"},"dependencies":{"argparse":"~1.0.3","bluebird":"~3.4.0","clone":"^2.1.2","dingbat-to-unicode":"^1.0.1","jszip":"^3.7.1","lop":"^0.4.1","omml2mathml":"^1.3.0","path-is-absolute":"^1.0.0","sax":"~1.1.1","underscore":"^1.13.1","xmlbuilder":"^10.0.0","xmldom":"^0.6.0"},"devDependencies":{"browserify":"~13.0.1","browserify-prepend-licenses":"~1.0.0","duck":"^0.1.12","eslint":"2.13.1","hamjest":"2.13.0","mocha":"~2.2.5","temp":"^0.9.4","uglify-js":"~3.17.4"},"browser":{"./lib/unzip.js":"./browser/unzip.js","./lib/docx/files.js":"./browser/docx/files.js"},"bin":{"mammoth-plus":"bin/mammoth-plus"},"scripts":{"pretest":"eslint lib test","test":"mocha 'test/**/*.tests.js'","prepare":"make mammoth-plus.min.js"},"license":"BSD-2-Clause","gitHead":"408215deba8dd3b0fc5e56a451fdba0f3772f394","bugs":{"url":"https://github.com/ihwf/mammoth-plus/issues"},"homepage":"https://github.com/ihwf/mammoth-plus#readme","_id":"mammoth-plus@2.0.2","_nodeVersion":"16.14.2","_npmVersion":"8.5.0","dist":{"integrity":"sha512-mLfW0T+WWKCi/Zy/JXXQurXi8SS3wWwNLlbccP1AljtuvLiX8sFo9yN6F4ZNekdLMl4HXHwx9dK0YmedDmJg4g==","shasum":"56c1b82ccc6eb0c36a89b230564769b3af58120a","tarball":"https://registry.npmjs.org/mammoth-plus/-/mammoth-plus-2.0.2.tgz","fileCount":52,"unpackedSize":2193599,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC/tw4uJypK/sJUTWyrJw7anDbjRqrhxUBH9Ei3sLpuMAIhALdTfvIn8Lbi4YMhSLQaKS9AQZhts9VxoPeJqtKLmRg4"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjkvEfACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrBUxAAosp91JMmT7/czdm5Wp2xZI9gvpuzHQyijFKwe9NHGR2UlGqY\r\n4xJFidIY/GmUed53vyEwULwuO0FHBVdjqOSJze1z6/0XwV70bHSjA4EX4jVW\r\nwbZw7zm8kOtbU5recuoBmFKDsNl5Sf57zduxVBky+Filagppy9IX+/fD1Mxe\r\nHJBi2UsSuc53ZhOybdz/4IN6Nn0JDTXrJZC8/+Zci5uW+cneXK10Igqg0m5e\r\nwHVC+39KwRf1cTeYWEUfAV7cP/qehv/vfI8/Q8eZEq35juWoJO3HhxkMd7iC\r\n8i+jXInnvp4q23qESPB0+zpvwchjYslUOaEQaYGUav/eJocOD7eC/BE/tkn5\r\n4qhExKkjhm9kccTRuTh/oZdAiEu+CWgat8C/WYs0kdQaoJxE0LBlkUXCWx3s\r\nhEqfYssr2L9bApdDYHQM/bUerLW77ZqGJXqRTieMYYpibhbcjoElfhxduAop\r\nt0z8oEyUi4cAcHQ9LxRcKANV6pxgl1uQflPmTqB4P1unC+84bB8KO3ojgbaj\r\nGlFyGdLuk/wZ+cz/TitQiuxoRrohMmQGwfnPLWH0U0rmpk+NsBTup+Z/+byF\r\nEj8yqVoCygS12/Ct+G5DfibKXmrAQ5h8S/gXFKcogQ36c15AZmW2/wdGLXl4\r\nulwrjBPH1aFXp4mOoBSz4wZv3KZJ8Bgi0Qo=\r\n=NuLN\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"heweifeng","email":"iheweifeng@gmail.com"},"directories":{},"maintainers":[{"name":"heweifeng","email":"iheweifeng@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mammoth-plus_2.0.2_1670574366860_0.06145720055116999"},"_hasShrinkwrap":false}},"time":{"created":"2022-12-09T07:10:14.665Z","2.0.0":"2022-12-09T07:10:14.921Z","modified":"2022-12-09T08:26:07.208Z","2.0.1":"2022-12-09T07:32:47.573Z","2.0.2":"2022-12-09T08:26:07.123Z"},"maintainers":[{"name":"heweifeng","email":"iheweifeng@gmail.com"}],"description":"Convert Word documents from docx to rich HTML and Markdown","homepage":"https://github.com/ihwf/mammoth-plus#readme","keywords":["docx","html","office","word","math","MathML","style","markdown","md"],"repository":{"type":"git","url":"git+https://github.com/ihwf/mammoth-plus.git"},"author":{"name":"heweifeng","email":"iheweifeng@gmail.com"},"bugs":{"url":"https://github.com/ihwf/mammoth-plus/issues"},"license":"BSD-2-Clause","readme":"# mammoth-plus .docx to HTML converter\n\nmammoth-plus is inspired by [Mammoth](https://github.com/mwilliamson/mammoth.js) and based on [Mammoth(v1.5.1)](https://github.com/mwilliamson/mammoth.js).\n\nmammoth-plus expands some features that [Mammoth](https://github.com/mwilliamson/mammoth.js) do not have, such as support math, styling, image size...\n\nThe following features are currently supported:\n\n-   Headings.\n\n-   Lists.\n\n-   Customisable mapping from your own docx styles to HTML.\n    For instance, you could convert `WarningHeading` to `h1.warning` by providing an appropriate style mapping.\n\n-   Tables.\n    The formatting of the table itself, such as borders, is currently ignored,\n    but the formatting of the text is treated the same as in the rest of the document.\n\n-   Footnotes and endnotes.\n\n-   Images.\n\n-   Bold, italics, underlines, strikethrough, superscript, subscript, font color, text highlight color and text align.\n\n-   Links.\n\n-   Line breaks.\n\n-   Text boxes. The contents of the text box are treated as a separate paragraph\n    that appears after the paragraph containing the text box.\n\n-   Comments.\n\n-   math.\n\n## Web demo\n\nThe easiest way to try out mammoth-plus is to use the web demo:\n\n-   Clone this repository\n-   Run `make setup`\n-   Open `browser-demo/index.html` in a web browser\n\n## Installation\n\n    npm install mammoth-plus\n\n## Usage\n\n### Library\n\nmammoth-plus can be required/import in the usual way:\n\n```javascript\nvar mammothPlus = require('mammoth-plus')\n// or\nimport mammothPlus from 'mammoth-plus'\n```\n\nIf not use module system,\nto generate a standalone JavaScript file for the browser,\nuse `mammoth-plus.min.js` (generate using `make setup` if it is not already present).\n`mammothPlus` is set as a window global.\n\n#### Basic conversion\n\nTo convert an existing .docx file to HTML, use `mammothPlus.convertToHtml`:\n\n```javascript\nvar mammothPlus = require('mammoth-plus')\n\nmammothPlus\n    .convertToHtml({\n        path: 'path/to/document.docx', // in node.js\n        arrayBuffer: 'array buffer containing a .docx file' // in browser\n    })\n    .then(function (result) {\n        var html = result.value // The generated HTML\n        var messages = result.messages // Any messages, such as warnings during conversion\n    })\n    .done()\n```\n\nNote that `mammothPlus.convertToHtml` returns a [promise](http://promises-aplus.github.io/promises-spec/).\n\nYou can also extract the raw text of the document by using `mammothPlus.extractRawText`.\nThis will ignore all formatting in the document.\nEach paragraph is followed by two newlines.\n\n```javascript\nmammothPlus\n    .extractRawText({\n        path: 'path/to/document.docx', // in node.js\n        arrayBuffer: 'array buffer containing a .docx file' // in browser\n    })\n    .then(function (result) {\n        var text = result.value // The raw text\n        var messages = result.messages\n    })\n    .done()\n```\n\n#### Custom style map\n\nBy default,\nmammoth-plus maps some common .docx styles to HTML elements.\nFor instance,\na paragraph with the style name `Heading 1` is converted to a `h1` element.\nYou can pass in a custom map for styles by passing an options object with a `styleMap` property as a second argument to `convertToHtml`.\nA description of the syntax for style maps can be found in the section [\"Writing style maps\"](#writing-style-maps).\nFor instance, if paragraphs with the style name `Section Title` should be converted to `h1` elements,\nand paragraphs with the style name `Subsection Title` should be converted to `h2` elements:\n\n```javascript\nvar mammothPlus = require('mammoth-plus')\n\nvar options = {\n    styleMap: [\n        \"p[style-name='Section Title'] => h1:fresh\",\n        \"p[style-name='Subsection Title'] => h2:fresh\"\n    ]\n}\nmammothPlus.convertToHtml(\n    {\n        path: 'path/to/document.docx', // in node.js\n        arrayBuffer: 'array buffer containing a .docx file' // in browser\n    },\n    options\n)\n```\n\nTo more easily support style maps stored in text files,\n`styleMap` can also be a string.\nEach line is treated as a separate style mapping,\nignoring blank lines and lines starting with `#`:\n\n```javascript\nvar options = {\n    styleMap:\n        \"p[style-name='Section Title'] => h1:fresh\\n\" +\n        \"p[style-name='Subsection Title'] => h2:fresh\"\n}\n```\n\nUser-defined style mappings are used in preference to the default style mappings.\nTo stop using the default style mappings altogether,\nset `options.includeDefaultStyleMap` to `false`:\n\n```javascript\nvar options = {\n    styleMap: [\n        \"p[style-name='Section Title'] => h1:fresh\",\n        \"p[style-name='Subsection Title'] => h2:fresh\"\n    ],\n    includeDefaultStyleMap: false\n}\n```\n\n#### Custom image handlers\n\nBy default, images are converted to `<img>` elements with the source included inline in the `src` attribute.\nThis behaviour can be changed by setting the `convertImage` option to an [image converter](#image-converters) .\n\nFor instance, the following would replicate the default behaviour:\n\n```javascript\nvar options = {\n    convertImage: mammothPlus.images.imgElement(function (image) {\n        return image.read('base64').then(function (imageBuffer) {\n            return {\n                src: 'data:' + image.contentType + ';base64,' + imageBuffer\n            }\n        })\n    })\n}\n```\n\n#### Bold\n\nBy default, bold text is wrapped in `<strong>` tags.\nThis behaviour can be changed by adding a style mapping for `b`.\nFor instance, to wrap bold text in `<em>` tags:\n\n```javascript\nvar mammothPlus = require('mammoth-plus')\n\nvar options = {\n    styleMap: ['b => em']\n}\nmammothPlus.convertToHtml(\n    {\n        path: 'path/to/document.docx', // in node.js\n        arrayBuffer: 'array buffer containing a .docx file' // in browser\n    },\n    options\n)\n```\n\n#### Italic\n\nBy default, italic text is wrapped in `<em>` tags.\nThis behaviour can be changed by adding a style mapping for `i`.\nFor instance, to wrap italic text in `<strong>` tags:\n\n```javascript\nvar mammothPlus = require('mammoth-plus')\n\nvar options = {\n    styleMap: ['i => strong']\n}\nmammothPlus.convertToHtml(\n    {\n        path: 'path/to/document.docx', // in node.js\n        arrayBuffer: 'array buffer containing a .docx file' // in browser\n    },\n    options\n)\n```\n\n#### Underline\n\nBy default, the underlining of any text is ignored since underlining can be confused with links in HTML documents.\nThis behaviour can be changed by adding a style mapping for `u`.\nFor instance, suppose that a source document uses underlining for emphasis.\nThe following will wrap any explicitly underlined source text in `<em>` tags:\n\n```javascript\nvar mammothPlus = require('mammoth-plus')\n\nvar options = {\n    styleMap: ['u => em']\n}\nmammothPlus.convertToHtml(\n    {\n        path: 'path/to/document.docx', // in node.js\n        arrayBuffer: 'array buffer containing a .docx file' // in browser\n    },\n    options\n)\n```\n\n#### Strikethrough\n\nBy default, strikethrough text is wrapped in `<s>` tags.\nThis behaviour can be changed by adding a style mapping for `strike`.\nFor instance, to wrap strikethrough text in `<del>` tags:\n\n```javascript\nvar mammothPlus = require('mammoth-plus')\n\nvar options = {\n    styleMap: ['strike => del']\n}\nmammothPlus.convertToHtml(\n    {\n        path: 'path/to/document.docx', // in node.js\n        arrayBuffer: 'array buffer containing a .docx file' // in browser\n    },\n    options\n)\n```\n\n#### Comments\n\nBy default, comments are ignored.\nTo include comments in the generated HTML,\nadd a style mapping for `comment-reference`.\nFor instance:\n\n```javascript\nvar mammothPlus = require('mammoth-plus')\n\nvar options = {\n    styleMap: ['comment-reference => sup']\n}\nmammothPlus.convertToHtml(\n    {\n        path: 'path/to/document.docx', // in node.js\n        arrayBuffer: 'array buffer containing a .docx file' // in browser\n    },\n    options\n)\n```\n\nComments will be appended to the end of the document,\nwith links to the comments wrapped using the specified style mapping.\n\n### CLI\n\nYou can convert docx files by passing the path to the docx file and the output file.\nFor instance:\n\n    mammoth-plus document.docx output.html\n\nIf no output file is specified, output is written to stdout instead.\n\nThe output is an HTML fragment, rather than a full HTML document, encoded with UTF-8.\nSince the encoding is not explicitly set in the fragment,\nopening the output file in a web browser may cause Unicode characters to be rendered incorrectly if the browser doesn't default to UTF-8.\n\n#### Images\n\nBy default, images are included inline in the output HTML.\nIf an output directory is specified by `--output-dir`,\nthe images are written to separate files instead.\nFor instance:\n\n    mammoth-plus document.docx --output-dir=output-dir\n\nExisting files will be overwritten if present.\n\n#### Styles\n\nA custom style map can be read from a file using `--style-map`.\nFor instance:\n\n    mammoth-plus document.docx output.html --style-map=custom-style-map\n\nWhere `custom-style-map` looks something like:\n\n    p[style-name='Aside Heading'] => div.aside > h2:fresh\n    p[style-name='Aside Text'] => div.aside > p:fresh\n\nA description of the syntax for style maps can be found in the section [\"Writing style maps\"](#writing-style-maps).\n\n#### Markdown\n\nMarkdown support is deprecated.\nGenerating HTML and using a separate library to convert the HTML to Markdown is recommended,\nand is likely to produce better results.\n\nUsing `--output-format=markdown` will cause Markdown to be generated.\nFor instance:\n\n    mammoth-plus document.docx --output-format=markdown\n\n### API\n\n#### `mammothPlus.convertToHtml(input, options)`\n\nConverts the source document to HTML.\n\n-   `input`: an object describing the source document.\n    On node.js, the following inputs are supported:\n\n    -   `{path: path}`, where `path` is the path to the .docx file.\n    -   `{buffer: buffer}`, where `buffer` is a node.js Buffer containing a .docx file.\n\n    In the browser, the following inputs are supported:\n\n    -   `{arrayBuffer: arrayBuffer}`, where `arrayBuffer` is an array buffer containing a .docx file.\n\n-   `options` (optional): options for the conversion.\n    May have the following properties:\n\n    -   `styleMap`: controls the mapping of Word styles to HTML.\n        If `options.styleMap` is a string,\n        each line is treated as a separate style mapping,\n        ignoring blank lines and lines starting with `#`:\n        If `options.styleMap` is an array,\n        each element is expected to be a string representing a single style mapping.\n        See [\"Writing style maps\"](#writing-style-maps) for a reference to the syntax for style maps.\n\n    -   `includeEmbeddedStyleMap`: by default,\n        if the document contains an embedded style map, then it is combined with the default style map.\n        To ignore any embedded style maps,\n        set `options.includeEmbeddedStyleMap` to `false`.\n\n    -   `includeDefaultStyleMap`: by default,\n        the style map passed in `styleMap` is combined with the default style map.\n        To stop using the default style map altogether,\n        set `options.includeDefaultStyleMap` to `false`.\n\n    -   `convertImage`: by default, images are converted to `<img>` elements with the source included inline in the `src` attribute.\n        Set this option to an [image converter](#image-converters) to override the default behaviour.\n\n    -   `ignoreEmptyParagraphs`: by default, empty paragraphs are ignored.\n        Set this option to `false` to preserve empty paragraphs in the output.\n\n    -   `idPrefix`:\n        a string to prepend to any generated IDs,\n        such as those used by bookmarks, footnotes and endnotes.\n        Defaults to an empty string.\n\n    -   `transformDocument`: if set,\n        this function is applied to the document read from the docx file before the conversion to HTML.\n        The API for document transforms should be considered unstable.\n        See [document transforms](#document-transforms).\n\n-   Returns a promise containing a result.\n    This result has the following properties:\n\n    -   `value`: the generated HTML\n\n    -   `messages`: any messages, such as errors and warnings, generated during the conversion\n\n#### `mammothPlus.convertToMarkdown(input, options)`\n\nMarkdown support is deprecated.\nGenerating HTML and using a separate library to convert the HTML to Markdown is recommended,\nand is likely to produce better results.\n\nConverts the source document to Markdown.\nThis behaves the same as `convertToHtml`,\nexcept that the `value` property of the result contains Markdown rather than HTML.\n\n#### `mammothPlus.extractRawText(input)`\n\nExtract the raw text of the document.\nThis will ignore all formatting in the document.\nEach paragraph is followed by two newlines.\n\n-   `input`: an object describing the source document.\n    On node.js, the following inputs are supported:\n\n    -   `{path: path}`, where `path` is the path to the .docx file.\n    -   `{buffer: buffer}`, where `buffer` is a node.js Buffer containing a .docx file.\n\n    In the browser, the following inputs are supported:\n\n    -   `{arrayBuffer: arrayBuffer}`, where `arrayBuffer` is an array buffer containing a .docx file.\n\n-   Returns a promise containing a result.\n    This result has the following properties:\n\n    -   `value`: the raw text\n\n    -   `messages`: any messages, such as errors and warnings\n\n#### `mammothPlus.embedStyleMap(input, styleMap)`\n\nGiven an existing docx file,\n`embedStyleMap` will generate a new docx file with the passed style map embedded.\nWhen the new docx file is read by mammoth-plus,\nit will use the embedded style map.\n\n-   `input`: an object describing the source document.\n    On node.js, the following inputs are supported:\n\n    -   `{path: path}`, where `path` is the path to the .docx file.\n    -   `{buffer: buffer}`, where `buffer` is a node.js Buffer containing a .docx file.\n\n    In the browser, the following inputs are supported:\n\n    -   `{arrayBuffer: arrayBuffer}`, where `arrayBuffer` is an array buffer containing a .docx file.\n\n-   `styleMap`: the style map to embed.\n\n-   Returns a promise.\n    Call `toBuffer()` on the value inside the promise to get a `Buffer` representing the new document.\n\nFor instance:\n\n```javascript\nmammothPlus\n    .embedStyleMap(\n        { path: sourcePath },\n        \"p[style-name='Section Title'] => h1:fresh\"\n    )\n    .then(function (docx) {\n        fs.writeFile(destinationPath, docx.toBuffer(), callback)\n    })\n```\n\n#### Messages\n\nEach message has the following properties:\n\n-   `type`: a string representing the type of the message, such as `\"warning\"` or\n    `\"error\"`\n\n-   `message`: a string containing the actual message\n\n-   `error` (optional): the thrown exception that caused this message, if any\n\n#### Image converters\n\nAn image converter can be created by calling `mammothPlus.images.imgElement(func)`.\nThis creates an `<img>` element for each image in the original docx.\n`func` should be a function that has one argument `image`.\nThis argument is the image element being converted,\nand has the following properties:\n\n-   `read([encoding])`: read the image file with the specified encoding.\n    If no encoding is specified, a `Buffer` is returned.\n\n-   `contentType`: the content type of the image, such as `image/png`.\n\n`func` should return an object (or a promise of an object) of attributes for the `<img>` element.\nAt a minimum, this should include the `src` attribute.\nIf any alt text is found for the image,\nthis will be automatically added to the element's attributes.\n\nFor instance, the following replicates the default image conversion:\n\n```javascript\nmammothPlus.images.imgElement(function (image) {\n    return image.read('base64').then(function (imageBuffer) {\n        return {\n            src: 'data:' + image.contentType + ';base64,' + imageBuffer\n        }\n    })\n})\n```\n\n`mammothPlus.images.dataUri` is the default image converter.\n\n### Document transforms\n\n**The API for document transforms should be considered unstable,\nand may change between any versions.\nIf you rely on this behaviour,\nyou should pin to a specific version of mammoth-plus.js,\nand test carefully before updating.**\n\nmammoth-plus allows a document to be transformed before it is converted.\nFor instance,\nsuppose that document has not been semantically marked up,\nbut you know that any centre-aligned paragraph should be a heading.\nYou can use the `transformDocument` argument to modify the document appropriately:\n\n```javascript\nfunction transformElement(element) {\n    if (element.children) {\n        var children = _.map(element.children, transformElement)\n        element = { ...element, children: children }\n    }\n\n    if (element.type === 'paragraph') {\n        element = transformParagraph(element)\n    }\n\n    return element\n}\n\nfunction transformParagraph(element) {\n    if (element.alignment === 'center' && !element.styleId) {\n        return { ...element, styleId: 'Heading2' }\n    } else {\n        return element\n    }\n}\n\nvar options = {\n    transformDocument: transformElement\n}\n```\n\nThe return value of `transformDocument` is used during HTML generation.\n\nThe above can be written more succinctly using the helper `mammothPlus.transforms.paragraph`:\n\n```javascript\nfunction transformParagraph(element) {\n    if (element.alignment === 'center' && !element.styleId) {\n        return { ...element, styleId: 'Heading2' }\n    } else {\n        return element\n    }\n}\n\nvar options = {\n    transformDocument: mammothPlus.transforms.paragraph(transformParagraph)\n}\n```\n\nOr if you want paragraphs that have been explicitly set to use monospace fonts to represent code:\n\n```javascript\nconst monospaceFonts = ['consolas', 'courier', 'courier new']\n\nfunction transformParagraph(paragraph) {\n    var runs = mammothPlus.transforms.getDescendantsOfType(paragraph, 'run')\n    var isMatch =\n        runs.length > 0 &&\n        runs.every(function (run) {\n            return (\n                run.font &&\n                monospaceFonts.indexOf(run.font.toLowerCase()) !== -1\n            )\n        })\n    if (isMatch) {\n        return {\n            ...paragraph,\n            styleId: 'code',\n            styleName: 'Code'\n        }\n    } else {\n        return paragraph\n    }\n}\n\nvar options = {\n    transformDocument: mammothPlus.transforms.paragraph(transformParagraph),\n    styleMap: [\"p[style-name='Code'] => pre:separator('\\n')\"]\n}\n```\n\n#### `mammothPlus.transforms.paragraph(transformParagraph)`\n\nReturns a function that can be used as the `transformDocument` option.\nThis will apply the function `transformParagraph` to each paragraph element.\n`transformParagraph` should return the new paragraph.\n\n#### `mammothPlus.transforms.run(transformRun)`\n\nReturns a function that can be used as the `transformDocument` option.\nThis will apply the function `transformRun` to each run element.\n`transformRun` should return the new run.\n\n#### `mammothPlus.transforms.getDescendants(element)`\n\nGets all descendants of an element.\n\n#### `mammothPlus.transforms.getDescendantsOfType(element, type)`\n\nGets all descendants of a particular type of an element.\nFor instance, to get all runs within an element `paragraph`:\n\n```javascript\nvar runs = mammothPlus.transforms.getDescendantsOfType(paragraph, 'run')\n```\n\n## Writing style maps\n\nA style map is made up of a number of style mappings separated by new lines.\nBlank lines and lines starting with `#` are ignored.\n\nA style mapping has two parts:\n\n-   On the left, before the arrow, is the document element matcher.\n-   On the right, after the arrow, is the HTML path.\n\nWhen converting each paragraph,\nmammoth-plus finds the first style mapping where the document element matcher matches the current paragraph.\nmammoth-plus then ensures the HTML path is satisfied.\n\n### Freshness\n\nWhen writing style mappings, it's helpful to understand mammoth-plus's notion of freshness.\nWhen generating, mammoth-plus will only close an HTML element when necessary.\nOtherwise, elements are reused.\n\nFor instance, suppose one of the specified style mappings is `p[style-name='Heading 1'] => h1`.\nIf mammoth-plus encounters a .docx paragraph with the style name `Heading 1`,\nthe .docx paragraph is converted to a `h1` element with the same text.\nIf the next .docx paragraph also has the style name `Heading 1`,\nthen the text of that paragraph will be appended to the _existing_ `h1` element,\nrather than creating a new `h1` element.\n\nIn most cases, you'll probably want to generate a new `h1` element instead.\nYou can specify this by using the `:fresh` modifier:\n\n`p[style-name='Heading 1'] => h1:fresh`\n\nThe two consecutive `Heading 1` .docx paragraphs will then be converted to two separate `h1` elements.\n\nReusing elements is useful in generating more complicated HTML structures.\nFor instance, suppose your .docx contains asides.\nEach aside might have a heading and some body text,\nwhich should be contained within a single `div.aside` element.\nIn this case, style mappings similar to `p[style-name='Aside Heading'] => div.aside > h2:fresh` and\n`p[style-name='Aside Text'] => div.aside > p:fresh` might be helpful.\n\n### Document element matchers\n\n#### Paragraphs, runs and tables\n\nMatch any paragraph:\n\n```\np\n```\n\nMatch any run:\n\n```\nr\n```\n\nMatch any table:\n\n```\ntable\n```\n\nTo match a paragraph, run or table with a specific style,\nyou can reference the style by name.\nThis is the style name that is displayed in Microsoft Word or LibreOffice.\nFor instance, to match a paragraph with the style name `Heading 1`:\n\n```\np[style-name='Heading 1']\n```\n\nYou can also match a style name by prefix.\nFor instance, to match a paragraph where the style name starts with `Heading`:\n\n```\np[style-name^='Heading']\n```\n\nStyles can also be referenced by style ID.\nThis is the ID used internally in the .docx file.\nTo match a paragraph or run with a specific style ID,\nappend a dot followed by the style ID.\nFor instance, to match a paragraph with the style ID `Heading1`:\n\n```\np.Heading1\n```\n\n#### Bold\n\nMatch explicitly bold text:\n\n```\nb\n```\n\nNote that this matches text that has had bold explicitly applied to it.\nIt will not match any text that is bold because of its paragraph or run style.\n\n#### Italic\n\nMatch explicitly italic text:\n\n```\ni\n```\n\nNote that this matches text that has had italic explicitly applied to it.\nIt will not match any text that is italic because of its paragraph or run style.\n\n#### Underline\n\nMatch explicitly underlined text:\n\n```\nu\n```\n\nNote that this matches text that has had underline explicitly applied to it.\nIt will not match any text that is underlined because of its paragraph or run style.\n\n#### Strikethough\n\nMatch explicitly struckthrough text:\n\n```\nstrike\n```\n\nNote that this matches text that has had strikethrough explicitly applied to it.\nIt will not match any text that is struckthrough because of its paragraph or run style.\n\n#### All caps\n\nMatch explicitly all caps text:\n\n```\nall-caps\n```\n\nNote that this matches text that has had all caps explicitly applied to it.\nIt will not match any text that is all caps because of its paragraph or run style.\n\n#### Small caps\n\nMatch explicitly small caps text:\n\n```\nsmall-caps\n```\n\nNote that this matches text that has had small caps explicitly applied to it.\nIt will not match any text that is small caps because of its paragraph or run style.\n\n#### Ignoring document elements\n\nUse `!` to ignore a document element.\nFor instance, to ignore any paragraph with the style `Comment`:\n\n```\np[style-name='Comment'] => !\n```\n\n### HTML paths\n\n#### Single elements\n\nThe simplest HTML path is to specify a single element.\nFor instance, to specify an `h1` element:\n\n```\nh1\n```\n\nTo give an element a CSS class,\nappend a dot followed by the name of the class:\n\n```\nh1.section-title\n```\n\nTo require that an element is fresh, use `:fresh`:\n\n```\nh1:fresh\n```\n\nModifiers must be used in the correct order:\n\n```\nh1.section-title:fresh\n```\n\n#### Separators\n\nTo specify a separator to place between the contents of paragraphs that are collapsed together,\nuse `:separator('SEPARATOR STRING')`.\n\nFor instance, suppose a document contains a block of code where each line of code is a paragraph with the style `Code Block`.\nWe can write a style mapping to map such paragraphs to `<pre>` elements:\n\n```\np[style-name='Code Block'] => pre\n```\n\nSince `pre` isn't marked as `:fresh`,\nconsecutive `pre` elements will be collapsed together.\nHowever, this results in the code all being on one line.\nWe can use `:separator` to insert a newline between each line of code:\n\n```\np[style-name='Code Block'] => pre:separator('\\n')\n```\n\n#### Nested elements\n\nUse `>` to specify nested elements.\nFor instance, to specify `h2` within `div.aside`:\n\n```\ndiv.aside > h2\n```\n\nYou can nest elements to any depth.\n","readmeFilename":"README.md"}