toCssString method

String toCssString()

Returns the contents of a CSS stylesheet that will display this error message above the current page.

Implementation

String toCssString() {
  // Don't render the error message in Unicode for the inline comment, since
  // we can't be sure the user's default encoding is UTF-8.
  var wasAscii = term_glyph.ascii;
  term_glyph.ascii = true;
  var commentMessage = toString(color: false)
      // Replace comment-closing sequences in the error message with
      // visually-similar sequences that won't actually close the comment.
      .replaceAll("*/", "*∕")
      // If the original text contains CRLF newlines, replace them with LF
      // newlines to match the rest of the document.
      .replaceAll("\r\n", "\n");
  term_glyph.ascii = wasAscii;

  // For the string comment, render all non-US-ASCII characters as escape
  // sequences so that they'll show up even if the HTTP headers are set
  // incorrectly.
  var stringMessage = StringBuffer();
  for (var rune in SassString(toString(color: false)).toString().runes) {
    if (rune > 0x7F) {
      stringMessage
        ..writeCharCode($backslash)
        ..write(rune.toRadixString(16))
        ..writeCharCode($space);
    } else {
      stringMessage.writeCharCode(rune);
    }
  }

  return """
/* ${commentMessage.split("\n").join("\n * ")} */

body::before {
font-family: "Source Code Pro", "SF Mono", Monaco, Inconsolata, "Fira Mono",
    "Droid Sans Mono", monospace, monospace;
white-space: pre;
display: block;
padding: 1em;
margin-bottom: 1em;
border-bottom: 2px solid black;
content: $stringMessage;
}""";
}