How to use the mammoth.images function in mammoth

To help you get started, we’ve selected a few mammoth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GitbookIO / gitbook-convert / src / converters / docx.js View on Github external
toHTML() {
        const d = Promise.defer();

        // counter for default name (altText unavailable)
        let imgCounter = 0;

        // imgExporter exports inline images to the assets folder and apply src attribute to HTML correctly
        const imgExporter = mammoth.images.inline((element) => {
            return element.read()
            .then((imageBuffer) => {
                // Set image file name
                let imgFilename;

                // Use altText for image name
                if (Boolean(element.altText)) {
                    imgFilename = element.altText;

                    // Remove extension in altText if is equal to contentType
                    const contentType = `image/${path.extname(imgFilename).slice(1)}`;
                    if (element.contentType === contentType) {
                        imgFilename = imgFilename.split('.').slice(0, -1).join('.');
                    }

                    // Shorten if too long

mammoth

Convert Word documents from docx to simple HTML and Markdown

BSD-2-Clause
Latest version published 26 days ago

Package Health Score

78 / 100
Full package analysis