#typst #语法高亮 #转义 #ANSI #序列 #Discord #高亮

typst-ansi-hl

typst-ansi-hl 使用ANSI转义序列突出显示您的Typst代码

2个不稳定版本

0.2.0 2024年6月22日
0.1.0 2024年4月15日

#5 in #序列

EUPL-1.2LGPL-3.0-or-later

21KB
356 代码行

typst-ansi-hl

typst-ansi-hl 使用ANSI转义序列突出显示您的Typst代码。

它特别适用于在Discord中提供其他情况下缺失的Typst语法高亮。

安装

cargo install --path .

使用

只需运行 typst-ansi-hl main.typ 或将源代码管道输入到 typst-ansi-hl。有关如何将与Discord兼容的输出复制到剪贴板的信息,请参阅 基于剪贴板的流程

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

Arguments:
  [INPUT]
          The input path. If unset, stdin is used

Options:
  -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')

基于剪贴板的流程

您可以将以下命令之一绑定到特定的按键绑定以改进易用性

# 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

您还可以将此crate用作库。有关更多详细信息,请参阅 文档

此软件与Typst品牌无关。

依赖项

~11–20MB
~206K SLoC