brew install highlight
需要安装highlight工具。
用法:
转化剪贴板中的代码:
pbpaste | highlight --syntax=go --style=github -k "Fira Code" -K 36 -u "utf-8" -t 4 -O rtf | pbcopy
--syntax
指定代码语法格式,-u
指定编码,否则中文会乱码,--style
指定高亮的样式,-K
指定代码的字大小,rtf
是要转出的格式,还可以是其他的如html
。
转化代码文件:
highlight --style=github -k "Fira Code" -K 36 -u "utf-8" -t 4 -O rtf hello.go | pbcopy