htmlEscape = function(plainText) {
    if (preserveSpacesAndTabs) {
      const html = goog.html.SafeHtml.htmlEscape(plainText);
      let modifiedHtml =
          goog.html.SafeHtml
              .unwrap(html)
              // Leading space is converted into a non-breaking space, and
              // spaces following whitespace are converted into non-breaking
              // spaces. This must happen first, to ensure we preserve spaces
              // after newlines.
              .replace(/(^|[\n\r\t\ ])\ /g, '$1&#160;')
              // Preserve tabs by using style="white-space:pre"
              .replace(/(\t+)/g, '<span style="white-space:pre">$1</span>');
      if (preserveNewlines) {
        modifiedHtml = goog.string.newLineToBr(modifiedHtml);
      }
      return goog.html.uncheckedconversions
          .safeHtmlFromStringKnownToSatisfyTypeContract(
              goog.string.Const.from('Escaped plain text'), modifiedHtml);
    } else if (preserveNewlines) {
      return goog.html.SafeHtml.htmlEscapePreservingNewlines(plainText);
    } else {
      return goog.html.SafeHtml.htmlEscape(plainText);
    }
  }
@param {string} plainText
@return {!goog.html.SafeHtml} html