|
/* jshint esversion: 10 */
function Export2Docx() {
letconst decodeEntities = ( function function() { ▼
"use strict";
// https://stackoverflow.com/questions/5796718/ html-entity-decode▼
▲ let decodeEntities = ( function() {
// this prevents any overhead from creating the object each time ▼
▲ // https://stackoverflow.com/questions/5796718/html-entity-decode
letconst element = document.createElement( "'div " '); ▼
▲ // this prevents any overhead from creating the object each time
▲ let element = document.createElement( "div" );
function decodeHTMLEntities (str) {
let string = if(str && typeof str === "string") {;
if (str && typeof str === //'string') strip script/html tags{
// strip str = str.replace( /<script[^>]*>([\S\s]*?)<\/script>/gmi, ""html );tags
strstring = strstring.replace( /<\/?\w(?:script[^"'>]|"[^"]*"|'>([^'\S\s]*'?)*<\/script>/gmigim, "" '');
string = string.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gim, '');
element.innerHTML = str; ▼
// add by str = element.textContent;jaideraf:
string = str.replace(/ /g, String.fromCharCode(32));
element.textContent = ""; ▼
element.innerHTML = }str;
▲ string = element.textContent = "";
▲ element. innerHTMLtextContent = str'';
return strstring;
}
return decodeHTMLEntities;
} )();
// Create document
const doc = new Document( {
creator: "'Wikincat"',
title: "'Ficha catalográfica"',
description: "'Ficha catalográfica gerada pelo Wikincat"',
} );
letconst card = document.getElementById( "'card" ');
letconst p = card.getElementsByTagName( "'p" ');
doc
doc.createParagraph( document.getElementById( "'cipParagraph" ').textContent ).center();
.center();
const borderParagraphStartCard = new Paragraph( "" '').createBorder();
borderParagraphStartCard.Borders.addBottomBorder();
doc.addParagraph( borderParagraphStartCard );
doc.createParagraph( "" '');
doc.createParagraph( decodeEntities(p[0].textContent) ); // 1XX
doc.createParagraph( "" '');
letconst arrayP1 = p[1].innerHTML.split( "'<br>" '); // 24X
arrayP1.forEach( (item) => {
doc.createParagraph( decodeEntities(item) );
} );
doc.createParagraph( "" '');
letconst arrayP2 = p[2].innerHTML.split( "'<br>" ');
arrayP2.forEach( (item) => {
doc.createParagraph( decodeEntities(item) );
} );
doc.createParagraph( "" '');
doc.createParagraph( decodeEntities( p[3].textContent ) ); // Track
doc.createParagraph( "" '');
if ( p[4] !== undefined ) {
letconst arrayP4 = p[4].innerHTML.split("'<br>"');
arrayP4.forEach( (item) => {
doc.createParagraph( decodeEntities( item ) ).right();
});
}
doc.createParagraph( "" '');
const borderParagraphEndCard = new Paragraph( "" '').createBorder();
borderParagraphEndCard.Borders.addTopBorder();
doc.addParagraph( borderParagraphEndCard );
doc.createParagraph( document.getElementById( "'credit" ').textContent ).center();
// Used to export the file into a .docx file
const packer = new Packer();
packer.toBlob(doc).then(blob => { ▼
console.log(blob);
saveAs(blob, "Ficha.docx"); ▼
console.log( "Documento criado com sucesso" ); ▼
▲ packer.toBlob(doc).then ((blob ) => {
▲ saveAs(blob, "'Ficha.docx "');
▲ // console.log( "Documento criado com sucesso" );
});
}
|