ANSIColoredPrinters converts a text qualified by ANSI escape codes to another format. Currently, plain text and HTML output are supported.


The package can be installed with the Julia package manager. Run:

import Pkg

or, from the Julia REPL, type ] to enter the Pkg REPL mode and run:

pkg> add ANSIColoredPrinters


All you need to do is to pass an IO object, which contains a text qualified with ANSI escape codes as the first argument of the constructor of a printer (e.g. HTMLPrinter).

On environments which support MIME"text/html" display (e.g. this Documenter's HTML output), the text is displayed as HTML with its ANSI escape codes are translated into HTML elements by HTMLPrinter.

using ANSIColoredPrinters
using Crayons

buf = IOBuffer()
Crayons.print_logo(buf) # this outputs ANSI escape codes.

printer = HTMLPrinter(buf, root_class="documenter-example-output")

   ██████╗██████╗  █████╗ ██╗   ██╗ ██████╗ ███╗   ██╗███████╗
  ██╔════╝██╔══██╗██╔══██╗╚██╗ ██╔╝██╔═══██╗████╗  ██║██╔════╝
  ██║     ██████╔╝███████║ ╚████╔╝ ██║   ██║██╔██╗ ██║███████╗
  ██║     ██╔══██╗██╔══██║  ╚██╔╝  ██║   ██║██║╚██╗██║╚════██║
  ╚██████╗██║  ██║██║  ██║   ██║   ╚██████╔╝██║ ╚████║███████║
   ╚═════╝╚═╝  ╚═╝╚═╝  ╚═╝   ╚═╝    ╚═════╝ ╚═╝  ╚═══╝╚══════╝

Perhaps your browser is displaying a colored logo, but the HTMLPrinter actually outputs HTML code that looks like:

<pre class="documenter-example-output">

   <span class="sgr91">██████╗</span><span class="sgr92">███...

In addition, the colors and text styles are controlled by the CSS in the host document (e.g. default.css).