diff --git a/modules/scala/scala-interpreter/src/main/java/almond/internals/HtmlAnsiOutputStream.java b/modules/scala/scala-interpreter/src/main/java/almond/internals/HtmlAnsiOutputStream.java index eff25abd0..75773a4af 100644 --- a/modules/scala/scala-interpreter/src/main/java/almond/internals/HtmlAnsiOutputStream.java +++ b/modules/scala/scala-interpreter/src/main/java/almond/internals/HtmlAnsiOutputStream.java @@ -22,6 +22,8 @@ public void close() throws IOException { private static final String[] ANSI_COLOR_MAP = {"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white",}; + private static final String[] RGB_COLOR_MAP = {"black", "red", + "rgb(0, 187, 0)", "yellow", "blue", "magenta", "rgb(0, 187, 187)", "white",}; private static final byte[] BYTES_QUOT = """.getBytes(); private static final byte[] BYTES_AMP = "&".getBytes(); @@ -118,11 +120,18 @@ protected void processDefaultTextColor() throws IOException { @Override protected void processSetForegroundColor(int color, boolean bright) throws IOException { + // hard-coded color are for nteract (where the ansi-* classes are defined), and it might be useful from nbviewer too + // ansi-* classes are for jupyterlab (and classic too I think) + writeAttribute("span style=\"color: " + RGB_COLOR_MAP[color] + "\""); writeAttribute("span class=\"ansi-" + ANSI_COLOR_MAP[color] + "-fg\""); } @Override protected void processSetBackgroundColor(int color, boolean bright) throws IOException { + String extra = ""; + if (color == 7) + extra = "; color: rgb(255, 255, 255);"; + writeAttribute("span style=\"background-color: " + RGB_COLOR_MAP[color] + extra + "\""); writeAttribute("span class=\"ansi-" + ANSI_COLOR_MAP[color] + "-bg\""); } } diff --git a/modules/scala/scala-interpreter/src/main/scala/almond/Execute.scala b/modules/scala/scala-interpreter/src/main/scala/almond/Execute.scala index dde82722b..9fc05b532 100644 --- a/modules/scala/scala-interpreter/src/main/scala/almond/Execute.scala +++ b/modules/scala/scala-interpreter/src/main/scala/almond/Execute.scala @@ -255,7 +255,7 @@ final class Execute( haos.close() val html = s"""
- |
${baos.toString("UTF-8")}
+ |
${baos.toString("UTF-8")}
|
""".stripMargin log.debug(s"HTML: $html") val d = r.add( diff --git a/modules/scala/scala-kernel-api/src/main/scala/almond/display/PrettyPrint.scala b/modules/scala/scala-kernel-api/src/main/scala/almond/display/PrettyPrint.scala index 389450b96..9758da337 100644 --- a/modules/scala/scala-kernel-api/src/main/scala/almond/display/PrettyPrint.scala +++ b/modules/scala/scala-kernel-api/src/main/scala/almond/display/PrettyPrint.scala @@ -45,13 +45,14 @@ final class PrettyPrint private( """
""" else "" - extra + """
"""
+    // pre and div are for jupyterlab, code is for nteract
+    extra + """"
       else ""
-    "
" + extra + "
" + extra } private def html: String =