contour

Types

pub type Token {
  Whitespace(String)
  Keyword(String)
  String(String)
  Number(String)
  Variant(String)
  Function(String)
  Module(String)
  Operator(String)
  Comment(String)
  Other(String)
}

Constructors

  • Whitespace(String)
  • Keyword(String)
  • String(String)
  • Number(String)
  • Variant(String)
  • Function(String)
  • Module(String)
  • Operator(String)
  • Comment(String)
  • Other(String)

Functions

pub fn to_ansi(code: String) -> String

Highlight source code using ansi colours!

TokenColour
KeywordYellow
ModuleCyan
VariantCyan
FunctionBlue
OperatorMagenta
CommentItalic grey
String, NumberGreen
Whitespace, otherNo colour

If you wish to use some other colours or other format entirely see to_tokens.

pub fn to_html(code: String) -> String

Convert Gleam code into a HTML string! Each token is wrapped in a <span> with a class indicating the type of token.

TokenCSS class
Keywordhl-keyword
Modulehl-module
Varianthl-variant
Functionhl-function
Operatorhl-operator
Commenthl-comment
Numberhl-number
Stringhl-string
Whitespace, other

Place the output within a <pre><code>...</code></pre> and add styling for these CSS classes to get highlightin on your website. Here’s some CSS you could use:

pre code .hl-comment  { color: #d4d4d4; font-style: italic }
pre code .hl-function { color: #9ce7ff }
pre code .hl-keyword  { color: #ffd596 }
pre code .hl-module   { color: #ffddfa }
pre code .hl-number   { color: #c8ffa7 }
pre code .hl-operator { color: #ffaff3 }
pre code .hl-string   { color: #c8ffa7 }
pre code .hl-variant  { color: #ffddfa }

If you wish to use some other format see to_tokens.

pub fn to_tokens(code: String) -> List(Token)

Convert Gleam source code to a list of tokens, which you can then convert into whatever format you want.

If you wish to print to the terminal using ansi colours see to_ansi.

Search Document