Q:

Malformed html error thrown from html based object in appscript

I've hit a wall on an issue when I try to display the content.text object in apps script, it returns a malformed html error specifically regarding my fetch to a GET request of
https://www.cloudconnect.xxx...

I get everything I need, but the content.text bit which is throwing a malformed html error in apps script. I'd like to use the html and return the documents as is with proper formatting and believe that I can properly parse this html to apps script using htmloutput as it needs to be sanitized, but I believe it's what's throwing the malformed html object. How can I proceed without escaping html characters? How can I properly parse this? Has anyone been successful at this by any chance?
Example of content.text:
<body>
    <!-- [DocumentBodyStart:a63392fa-f859-4513-867e-1f3d2714b006] -->
    <div class=\"jive-rendered-content\">
        <p>Hi,team!</p>
        <p style=\"min-height: 8pt; padding: 0px;\">&#160;</p>
        <p>When executing attest () of SafetyNet Attestation API, apkPackageName is obtained as a parameter.</p>
        <p>I ran this API several times.</p>
        <p>As a result, the apkPackageName parameter was missing only once.</p>
        <p>In all other execution results, the parameter apkPackageName is present and will not occur again.</p>
        <p style=\"min-height: 8pt; padding: 0px;\">&#160;</p>
        <p>Why can't I get the apkPackageName when running the SafetyNet Attestation API on a device that has not been
            tampered with?</p>
        <p style=\"min-height: 8pt; padding: 0px;\">&#160;</p>
        <p>device : Kyocera 704KC</p>
        <p style=\"min-height: 8pt; padding: 0px;\">&#160;</p>
        <p>Regards,</p>
    </div><!-- [DocumentBodyEnd:a63392fa-f859-4513-867e-1f3d2714b006] -->
</body>

Would anyone have any pointers on how to proceed from here? My goal is to obtain the text from the content.text object, which I can see on any regular editor, but not in apps script for some reason while using the html format that it returns as is.
Code.gs
function doGet(request) { 
  return HtmlService.createTemplateFromFile('Page').evaluate();
}

function include(filename) { 
  var finalRequest = UrlFetchApp.fetch('https://www.cloudconnect.xxx...');

  var data = finalRequest.toString().replace("throw 'allowIllegalResourceCall is false.';", "").trim(); 

  data = JSON.parse(data);

  var returnedData = [];

  for(var i in data.list){
    var content = data.list[i];
    var content_subject = JSON.stringify(content.subject);
    var content_text = JSON.stringify(content.content.text);
    returnedData.push(content_subject + "<br />" + "<br />" + textBody(content_text));
  }
  return returnedData;
}

function textBody(content){ // <-- where the error throws on the content_text object
  return HtmlService.createHtmlOutput(content);
}

var entityMap = {
  '&': '&amp;',
  '<': '&lt;',
  '>': '&gt;',
  '"': '&quot;',
  "'": '&#39;',
  '/': '&#x2F;',
  '`': '&#x60;',
  '=': '&#x3D;'
};

function escapeHtml(string) {
  return String(string).replace(/[&<>"'`=\/]/g, function (s) {
    return entityMap[s];
  });
}

function myFunction() {
  Logger.log(HtmlService
      .createTemplateFromFile('Page')
      .getCode());
}

Page.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= include('Stylesheet'); ?>
  </head>
   <body>
  <script>
  var responseSubject;
  var responseContent;
    function displayData(responseSubject, responseContent) {
        document.getElementById('output').innerHTML = responseSubject + <br> + responseContent + <br>;
    } 
    google.script.run.withFailureHandler(displayData).withSuccessHandler(displayData).include();
    </script>
  </body>
</html>

Update
I have hit a wall returning the Exception: Cannot call SpreadsheetApp.getUi() from this context. (line 21, file "Code")
Code.gs

function doGet(request) { 
  return HtmlService.createTemplateFromFile('Page').evaluate();
}

function include(filename) { 
  var finalRequest = UrlFetchApp.fetch('https://www.cloudconnect.xxx....');

  var data = finalRequest.toString().replace("throw 'allowIllegalResourceCall is false.';", "").trim(); 

  data = JSON.parse(data);

  var returnedData = [];

  for(var i in data.list){
    var content = data.list[i];
    var contentSubject = JSON.stringify(content.subject);
    var contentText = JSON.stringify(content.content.text);
    returnedData.push(contentSubject + "<br/>" + "<br/>");
    var fixedContent = escapeHtml(contentText);// fixes the malformed Html error
    var ui = HtmlService.createHtmlOutput(fixedContent);//the attempt to read the onlick event and load the content text - but it throws the error: Exception: Cannot call SpreadsheetApp.getUi() from this context. (line 21, file "Code")
    SpreadsheetApp.getUi().showModelessDialog(ui);
    Logger.log("returnedData is: " + returnedData);
  }
  return returnedData;
}

var entityMap = {
  '&': '&amp;',
  '<': '&lt;',
  '>': '&gt;',
  '"': '&quot;',
  "'": '&#39;',
  '/': '&#x2F;',
  '`': '&#x60;',
  '=': '&#x3D;'
};

function escapeHtml(string) {
  return String(string).replace(/[&<>"'`=\/]/g, function (s) {
    return entityMap[s];
  });
}

function myFunction() {
  Logger.log(HtmlService
             .createTemplateFromFile('Page')
      .getCode());
}

//function contentBody(responseContent){ <-- realized I can't do this from a custom function
  //var html = responseContent;
  //var ui = HtmlService.createHtmlOutput(html);
  //SpreadsheetApp.getUi().showModelessDialog(ui); 
//}

Page.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <?!= include('Stylesheet'); ?>
    <script>
    var responseSubject;
    var responseContent;

    function displaySubjects(responseSubject) {
        document.getElementById('output').addEventListener('click', getContentBody).innerHTML = responseSubject;
    } 
    google.script.run.withFailureHandler(displaySubjects).withSuccessHandler(displaySubjects).include();

    //function displayContentText(responseContent){
        //document.getElementById('projection').innerHTML = responseContent;
    //}
    //google.script.run.withFailureHandler(displayContentText).withSuccessHandler(displayContentText).contentBody();
    </script>
  </head>
   <body>
    <p id = "output"></p>
    <p id = "projection"></p>
  </body>
</html>

My goal here is to add a click listener to the subjects and have them load the content text through the Html service. 
Any help would be highly appreciated please.
Cheers!

A:

This works:
function htmltest() {
  var html='<body><!--[DocumentBodyStart:a63392fa-f859-4513-867e-1f3d2714b006]--><div class="jive-rendered-content"><p>Hi,team!</p><p style="min-height:8pt;padding:0px;">&#160;</p><p>When executing at test() of Safety NetAttestationAPI, apkPackageName is obtained as a parameter.</p><p>I ran this API several times.</p><p>As a result,the apkPackageName parameter was missing only once.</p><p>In all other execution results,the parameter apkPackageName is present and will not occur again.</p><p style="min-height:8pt;padding:0px;">&#160;</p><p>Whycan\'t I get the apkPackageName when running the Safety NetAttestation API on a device that has not been tampered with?</p><p style="min-height:8pt;padding:0px;">&#160;</p><p>device:Kyocera704KC</p><p style="min-height:8pt;padding:0px;">&#160;</p><p>Regards,</p></div><!--[DocumentBodyEnd:a63392fa-f859-4513-867e-1f3d2714b006]--></body>';
  var ui=HtmlService.createHtmlOutput(html).setHeight(500);
  SpreadsheetApp.getUi().showModelessDialog(ui, "HTML Test");
}

Here's what I get when I run it just that way it is.

