I want to prevent the ModalDialog from formatting my strings
I have multiple text snippets that look similar to
const p = "\"_id\": " "\"\"" ",\n "
"\"name\": " "zzInheritanceBaseElements" ",\n "
"\"style\": " "@settings {\n include: person, loop;\n}\n\n/* Persons */\nelement[\"element type\"=\"person\"] {\n icon: user;\n icon-color: #c29999;\n padding: 0;\n color: #D57C2D;\n}\n\nelement[\"element type\"=\"Person\"] {\n icon: user;\n icon-color: #c29999;\n}\n\nelement:focus {\n shadow-size: 1.9;\n shadow-color: #e1eab6;\n shadow-opacity: 1;\n}\n\nelement[image] {\n icon: false;\n size: 130;\n}\n\nelement[!image] {\n size: 130;\n}\n\n"
"},"
When I open them in the Modal I get
"_id": "",
"name": zzInheritanceBaseElements,
"style": @settings {
include: person, loop;
}
/* Persons */
element["element type"="person"] {
icon: user;
icon-color: #c29999;
padding: 0;
color: #D57C2D;
}
element["element type"="Person"] {
icon: user;
icon-color: #c29999;
}
element:focus {
shadow-size: 1.9;
shadow-color: #e1eab6;
shadow-opacity: 1;
}
element[image] {
icon: false;
size: 130;
}
element[!image] {
size: 130;
}
},
I am trying to create a string by concatenating multiple strings together then downloading it from the ModalDailog with
<script>
const formatYmd = date => date.toISOString().slice(0, 10);
formatYmd(new Date());
const filename = "Kumu" "_" formatYmd(new Date()) ".json"; // If you want to change the filename, please modify this.
const a = document.createElement("a");
document.body.appendChild(a);
a.download = filename;
a.href = <?= temp ?>;
a.click();
google.script.host.close();
</script>
I need the resultant string to be in the original format
How to prevent the ModalDialog from formatting my strings
Thanks
CodePudding user response:
I believe your goal is as follows.
You want to download your variable of
p
as a text file using Google Apps Script and dialog.You want to keep the text of the variable as follows.
"\"_id\": \"\",\n \"name\": zzInheritanceBaseElements,\n \"style\": @settings {\n include: person, loop;\n}\n\n/* Persons */\nelement[\"element type\"=\"person\"] {\n icon: user;\n icon-color: #c29999;\n padding: 0;\n color: #D57C2D;\n}\n\nelement[\"element type\"=\"Person\"] {\n icon: user;\n icon-color: #c29999;\n}\n\nelement:focus {\n shadow-size: 1.9;\n shadow-color: #e1eab6;\n shadow-opacity: 1;\n}\n\nelement[image] {\n icon: false;\n size: 130;\n}\n\nelement[!image] {\n size: 130;\n}\n\n},"
In this case, how about the following sample script?
Google Apps Script side:
function openDialog() {
const p = "\"_id\": " "\"\"" ",\n "
"\"name\": " "zzInheritanceBaseElements" ",\n "
"\"style\": " "@settings {\n include: person, loop;\n}\n\n/* Persons */\nelement[\"element type\"=\"person\"] {\n icon: user;\n icon-color: #c29999;\n padding: 0;\n color: #D57C2D;\n}\n\nelement[\"element type\"=\"Person\"] {\n icon: user;\n icon-color: #c29999;\n}\n\nelement:focus {\n shadow-size: 1.9;\n shadow-color: #e1eab6;\n shadow-opacity: 1;\n}\n\nelement[image] {\n icon: false;\n size: 130;\n}\n\nelement[!image] {\n size: 130;\n}\n\n"
"},";
var template = HtmlService.createTemplateFromFile('index'); // Please modify this to your HTML filename.
template.temp = `data:${MimeType.TEXT_PLAIN};base64,${Utilities.base64Encode(JSON.stringify(p))}`;
SpreadsheetApp.getUi().showModalDialog(template.evaluate(), 'sample');
}
- When this script is run for your Javascript, a text file including the above text data is downloaded.