const fs = require('fs');
const path = require('path');

var mammoth = require("mammoth");

var options = {
    styleMap: [
        "p.JBPCar => p.jbp",
        "r.JBPCar => span.jbp",
        "p.JBPNegroCar => p.jbp.black",
        "r.JBPNegroCar => span.jbp.black",
        "p.CitaBiblica => p.bible-quote",
        "p.CitaBiblicaCar => p.bible-quote",
        "r.CitaBiblicaCar => span.bible-quote",
        "p.JBPAzul => p.jbp.blue",
        "p.JBPAzulCar => p.jbp.blue",
        "r.JBPAzulCar => span.jbp.blue",
        "p.WMBMorado => p.wmb.purple"
    ]
};

mammoth.convertToHtml({path: "./testdocstyles.docx"}, options)
    .then(function(result){
        var html = result.value; // The generated HTML
        var messages = result.messages; // Any messages, such as warnings during conversion
        console.log( messages )
        writeFile( html )
    })
    .catch(function(error) {
        console.error(error);
    });


function writeFile(data) {
    fs.writeFile(`./test.html`, data, (err) => {
    if (err) {
        console.error("Error writing file:", err);
        return;
    }
    console.log("File has been written successfully!");
    });
}