#typst #escaping #ansi #syntax-highlighting #sequences #discord #highlight


typst-ansi-hl highlights your Typst code using ANSI escape sequences

2 unstable releases

0.2.0 Jun 22, 2024
0.1.0 Apr 15, 2024

#557 in Text processing

Download history 90/week @ 2024-04-09 57/week @ 2024-04-16 129/week @ 2024-06-18 10/week @ 2024-06-25

139 downloads per month

EUPL-1.2 and LGPL-3.0-or-later

356 lines


typst-ansi-hl highlights your Typst code using ANSI escape sequences.

It is especially intended to be used to provide the otherwise missing Typst syntax highlighting in Discord.


cargo install --path .


Simply run typst-ansi-hl main.typ or pipe the source code into typst-ansi-hl. See Clipboard-based Workflow for information on how to copy Discord-compatible output to your clipboard.

Usage: typst-ansi-hl [OPTIONS] [INPUT]

          The input path. If unset, stdin is used

  -d, --discord
          Whether the input should be formatted to be Discord-compatible

  -s, --strip-ansi
          Strip all ANSI escape sequences from the input before processing. [default]

  -S, --no-strip-ansi
          Don't remove escape sequences from the input

  -c, --unwrap-codeblock
          If the input is surrounded by an ANSI codeblock as generated by this tool, remove it

  -C, --no-unwrap-codeblock
          Don't remove surrounding codeblock from the input. [default]

  -l, --soft-limit <SOFT_LIMIT>
          Softly enforce a byte size limit.

          This means that if the size limit is exceeded, less colors are used in order to get below that size limit. If it is not possible to get below that limit, the text is printed anyway.

  -m, --mode <MODE>
          The kind of input syntax

          [default: markup]
          [possible values: code, markup, math]

  -h, --help
          Print help (see a summary with '-h')

Clipboard-based Workflow

You can bind one of the following commands to a certain key bind for improved ease-of-use:

# Linux X11 (Bash/Zsh/Fish/Nushell)
xclip -selection clipboard -out | typst-ansi-hl --discord --soft-limit 2000 | xclip -selection clipboard -in

# Linux Wayland (Bash/Zsh/Fish/Nushell)
wl-paste | typst-ansi-hl --discord --soft-limit 2000 | wl-copy

# Windows (PowerShell)
Get-Clipboard | typst-ansi-hl --discord --soft-limit 2000 | Set-Clipboard


You can also use this crate as a library. See the documentation for further details.

This software is not affiliated with Typst, the brand.


~210K SLoC