防止 ModalDialog 格式化我的字符串

Prevent the ModalDialog from formatting my strings

我想阻止 ModalDialog 格式化我的字符串

我有多个类似于

的文本片段
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" + 
    "},"

当我在模式中打开它们时,我得到

  "_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;
}

},

我正在尝试通过将多个字符串连接在一起然后使用

从 ModalDailog 下载它来创建一个字符串
<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>

我需要结果字符串在 original format

如何防止 ModalDialog 格式化我的字符串

谢谢

我相信你的目标如下。

  • 您想使用 Google Apps 脚本和对话框将 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},"
    

在这种情况下,下面的示例脚本怎么样?

Google Apps 脚本端:

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');
}
  • 当此脚本是 运行 用于您的 Javascript 时,将下载包含上述文本数据的文本文件。