Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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