第 19 天:突出重点!🔖
今天我想和大家分享一个很棒的小库,它可以为代码类输出着色。是的,今天不开玩笑,这是一个非常严肃的库:cli-highlight👔。
您知道该怎么做:例如使用“deno add npm:cli-highlight”进行安装,并创建一个文件,例如“main.ts”:
import { highlight } from "cli-highlight"; const code = JSON.stringify( [ { category: "Christmas", jokes: [ { question: "What do you call Santa when he stops moving?", answer: "Santa Pause!", }, { question: "Why did the Christmas tree go to therapy?", answer: "It had too many hang-ups!", }, ], }, { category: "Winter", jokes: [ { question: "How do snowmen get around?", answer: "By riding an *icicle*!", }, ], }, { category: "Gifts", jokes: [ { question: "What do you call a bankrupt Santa?", answer: "Saint *Nickel*-less!", }, { question: "Why was the gift so good at music?", answer: "It had great *wrap* skills!", }, ], }, ], null, 2 ); console.log(highlight(code, { language: "json" }));
使用 `deno run -A ./main.ts` 运行并享受可读的输出:

它支持 192 种语言,就像浏览器荧光笔一样:
[ "1c", "abnf", "accesslog", "actionscript", "ada", "angelscript", "apache", "applescript", "arcade", "arduino", "armasm", "asciidoc", "aspectj", "autohotkey", "autoit", "avrasm", "awk", "axapta", "bash", "basic", "bnf", "brainfuck", "c", "cal", "capnproto", "ceylon", "clean", "clojure-repl", "clojure", "cmake", "coffeescript", "coq", "cos", "cpp", "crmsh", "crystal", "csharp", "csp", "css", "d", "dart", "delphi", "diff", "django", "dns", "dockerfile", "dos", "dsconfig", "dts", "dust", "ebnf", "elixir", "elm", "erb", "erlang-repl", "erlang", "excel", "fix", "flix", "fortran", "fsharp", "gams", "gauss", "gcode", "gherkin", "glsl", "gml", "go", "golo", "gradle", "graphql", "groovy", "haml", "handlebars", "haskell", "haxe", "hsp", "http", "hy", "inform7", "ini", "irpf90", "isbl", "java", "javascript", "jboss-cli", "json", "julia-repl", "julia", "kotlin", "lasso", "latex", "ldif", "leaf", "less", "lisp", "livecodeserver", "livescript", "llvm", "lsl", "lua", "makefile", "markdown", "mathematica", "matlab", "maxima", "mel", "mercury", "mipsasm", "mizar", "mojolicious", "monkey", "moonscript", "n1ql", "nestedtext", "nginx", "nim", "nix", "node-repl", "nsis", "objectivec", "ocaml", "openscad", "oxygene", "parser3", "perl", "pf", "pgsql", "php-template", "php", "plaintext", "pony", "powershell", "processing", "profile", "prolog", "properties", "protobuf", "puppet", "purebasic", "python-repl", "python", "q", "qml", "r", "reasonml", "rib", "roboconf", "routeros", "rsl", "ruby", "ruleslanguage", "rust", "sas", "scala", "scheme", "scilab", "scss", "shell", "smali", "smalltalk", "sml", "sqf", "sql", "stan", "stata", "step21", "stylus", "subunit", "swift", "taggerscript", "tap", "tcl", "thrift", "tp", "twig", "typescript", "vala", "vbnet", "vbscript-html", "vbscript", "verilog", "vhdl", "vim", "wasm", "wren", "x86asm", "xl", "xml", "xquery", "yaml", "zephir" ]
喜欢这些内容,并且希望全年能有更多这样的内容吗?
