Mercurial
comparison third_party/highlight/highlight.js @ 195:f8f5004a920a
Merging back hg-web-tip
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Tue, 27 Jan 2026 06:51:44 -0800 |
| parents | a06710325c30 |
| children |
comparison
equal
deleted
inserted
replaced
| 189:14cc84ba35a0 | 195:f8f5004a920a |
|---|---|
| 8162 | 8162 |
| 8163 })(); | 8163 })(); |
| 8164 | 8164 |
| 8165 hljs.registerLanguage('x86asm', hljsGrammar); | 8165 hljs.registerLanguage('x86asm', hljsGrammar); |
| 8166 })(); | 8166 })(); |
| 8167 (function(){ | |
| 8168 var hljsGrammar = (function () { | |
| 8169 'use strict'; | |
| 8170 | |
| 8171 | |
| 8172 /* | |
| 8173 Language: Shell Session | |
| 8174 Requires: bash.js | |
| 8175 Author: TSUYUSATO Kitsune <[email protected]> | |
| 8176 Category: common | |
| 8177 Audit: 2020 | |
| 8178 */ | |
| 8179 /* | |
| 8180 Language: Bash | |
| 8181 Author: vah <[email protected]> | |
| 8182 Contributrors: Benjamin Pannell <[email protected]> | |
| 8183 Website: https://www.gnu.org/software/bash/ | |
| 8184 Category: common, scripting | |
| 8185 */ | |
| 8186 | |
| 8187 /** @type LanguageFn */ | |
| 8188 function bash(hljs) { | |
| 8189 const regex = hljs.regex; | |
| 8190 const VAR = {}; | |
| 8191 const BRACED_VAR = { | |
| 8192 begin: /\$\{/, | |
| 8193 end: /\}/, | |
| 8194 contains: [ | |
| 8195 "self", | |
| 8196 { | |
| 8197 begin: /:-/, | |
| 8198 contains: [ VAR ] | |
| 8199 } // default values | |
| 8200 ] | |
| 8201 }; | |
| 8202 Object.assign(VAR, { | |
| 8203 className: 'variable', | |
| 8204 variants: [ | |
| 8205 { begin: regex.concat(/\$[\w\d#@][\w\d_]*/, | |
| 8206 // negative look-ahead tries to avoid matching patterns that are not | |
| 8207 // Perl at all like $ident$, @ident@, etc. | |
| 8208 `(?![\\w\\d])(?![$])`) }, | |
| 8209 BRACED_VAR | |
| 8210 ] | |
| 8211 }); | |
| 8212 | |
| 8213 const SUBST = { | |
| 8214 className: 'subst', | |
| 8215 begin: /\$\(/, | |
| 8216 end: /\)/, | |
| 8217 contains: [ hljs.BACKSLASH_ESCAPE ] | |
| 8218 }; | |
| 8219 const COMMENT = hljs.inherit( | |
| 8220 hljs.COMMENT(), | |
| 8221 { | |
| 8222 match: [ | |
| 8223 /(^|\s)/, | |
| 8224 /#.*$/ | |
| 8225 ], | |
| 8226 scope: { | |
| 8227 2: 'comment' | |
| 8228 } | |
| 8229 } | |
| 8230 ); | |
| 8231 const HERE_DOC = { | |
| 8232 begin: /<<-?\s*(?=\w+)/, | |
| 8233 starts: { contains: [ | |
| 8234 hljs.END_SAME_AS_BEGIN({ | |
| 8235 begin: /(\w+)/, | |
| 8236 end: /(\w+)/, | |
| 8237 className: 'string' | |
| 8238 }) | |
| 8239 ] } | |
| 8240 }; | |
| 8241 const QUOTE_STRING = { | |
| 8242 className: 'string', | |
| 8243 begin: /"/, | |
| 8244 end: /"/, | |
| 8245 contains: [ | |
| 8246 hljs.BACKSLASH_ESCAPE, | |
| 8247 VAR, | |
| 8248 SUBST | |
| 8249 ] | |
| 8250 }; | |
| 8251 SUBST.contains.push(QUOTE_STRING); | |
| 8252 const ESCAPED_QUOTE = { | |
| 8253 match: /\\"/ | |
| 8254 }; | |
| 8255 const APOS_STRING = { | |
| 8256 className: 'string', | |
| 8257 begin: /'/, | |
| 8258 end: /'/ | |
| 8259 }; | |
| 8260 const ESCAPED_APOS = { | |
| 8261 match: /\\'/ | |
| 8262 }; | |
| 8263 const ARITHMETIC = { | |
| 8264 begin: /\$?\(\(/, | |
| 8265 end: /\)\)/, | |
| 8266 contains: [ | |
| 8267 { | |
| 8268 begin: /\d+#[0-9a-f]+/, | |
| 8269 className: "number" | |
| 8270 }, | |
| 8271 hljs.NUMBER_MODE, | |
| 8272 VAR | |
| 8273 ] | |
| 8274 }; | |
| 8275 const SH_LIKE_SHELLS = [ | |
| 8276 "fish", | |
| 8277 "bash", | |
| 8278 "zsh", | |
| 8279 "sh", | |
| 8280 "csh", | |
| 8281 "ksh", | |
| 8282 "tcsh", | |
| 8283 "dash", | |
| 8284 "scsh", | |
| 8285 ]; | |
| 8286 const KNOWN_SHEBANG = hljs.SHEBANG({ | |
| 8287 binary: `(${SH_LIKE_SHELLS.join("|")})`, | |
| 8288 relevance: 10 | |
| 8289 }); | |
| 8290 const FUNCTION = { | |
| 8291 className: 'function', | |
| 8292 begin: /\w[\w\d_]*\s*\(\s*\)\s*\{/, | |
| 8293 returnBegin: true, | |
| 8294 contains: [ hljs.inherit(hljs.TITLE_MODE, { begin: /\w[\w\d_]*/ }) ], | |
| 8295 relevance: 0 | |
| 8296 }; | |
| 8297 | |
| 8298 const KEYWORDS = [ | |
| 8299 "if", | |
| 8300 "then", | |
| 8301 "else", | |
| 8302 "elif", | |
| 8303 "fi", | |
| 8304 "time", | |
| 8305 "for", | |
| 8306 "while", | |
| 8307 "until", | |
| 8308 "in", | |
| 8309 "do", | |
| 8310 "done", | |
| 8311 "case", | |
| 8312 "esac", | |
| 8313 "coproc", | |
| 8314 "function", | |
| 8315 "select" | |
| 8316 ]; | |
| 8317 | |
| 8318 const LITERALS = [ | |
| 8319 "true", | |
| 8320 "false" | |
| 8321 ]; | |
| 8322 | |
| 8323 // to consume paths to prevent keyword matches inside them | |
| 8324 const PATH_MODE = { match: /(\/[a-z._-]+)+/ }; | |
| 8325 | |
| 8326 // http://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html | |
| 8327 const SHELL_BUILT_INS = [ | |
| 8328 "break", | |
| 8329 "cd", | |
| 8330 "continue", | |
| 8331 "eval", | |
| 8332 "exec", | |
| 8333 "exit", | |
| 8334 "export", | |
| 8335 "getopts", | |
| 8336 "hash", | |
| 8337 "pwd", | |
| 8338 "readonly", | |
| 8339 "return", | |
| 8340 "shift", | |
| 8341 "test", | |
| 8342 "times", | |
| 8343 "trap", | |
| 8344 "umask", | |
| 8345 "unset" | |
| 8346 ]; | |
| 8347 | |
| 8348 const BASH_BUILT_INS = [ | |
| 8349 "alias", | |
| 8350 "bind", | |
| 8351 "builtin", | |
| 8352 "caller", | |
| 8353 "command", | |
| 8354 "declare", | |
| 8355 "echo", | |
| 8356 "enable", | |
| 8357 "help", | |
| 8358 "let", | |
| 8359 "local", | |
| 8360 "logout", | |
| 8361 "mapfile", | |
| 8362 "printf", | |
| 8363 "read", | |
| 8364 "readarray", | |
| 8365 "source", | |
| 8366 "sudo", | |
| 8367 "type", | |
| 8368 "typeset", | |
| 8369 "ulimit", | |
| 8370 "unalias" | |
| 8371 ]; | |
| 8372 | |
| 8373 const ZSH_BUILT_INS = [ | |
| 8374 "autoload", | |
| 8375 "bg", | |
| 8376 "bindkey", | |
| 8377 "bye", | |
| 8378 "cap", | |
| 8379 "chdir", | |
| 8380 "clone", | |
| 8381 "comparguments", | |
| 8382 "compcall", | |
| 8383 "compctl", | |
| 8384 "compdescribe", | |
| 8385 "compfiles", | |
| 8386 "compgroups", | |
| 8387 "compquote", | |
| 8388 "comptags", | |
| 8389 "comptry", | |
| 8390 "compvalues", | |
| 8391 "dirs", | |
| 8392 "disable", | |
| 8393 "disown", | |
| 8394 "echotc", | |
| 8395 "echoti", | |
| 8396 "emulate", | |
| 8397 "fc", | |
| 8398 "fg", | |
| 8399 "float", | |
| 8400 "functions", | |
| 8401 "getcap", | |
| 8402 "getln", | |
| 8403 "history", | |
| 8404 "integer", | |
| 8405 "jobs", | |
| 8406 "kill", | |
| 8407 "limit", | |
| 8408 "log", | |
| 8409 "noglob", | |
| 8410 "popd", | |
| 8411 "print", | |
| 8412 "pushd", | |
| 8413 "pushln", | |
| 8414 "rehash", | |
| 8415 "sched", | |
| 8416 "setcap", | |
| 8417 "setopt", | |
| 8418 "stat", | |
| 8419 "suspend", | |
| 8420 "ttyctl", | |
| 8421 "unfunction", | |
| 8422 "unhash", | |
| 8423 "unlimit", | |
| 8424 "unsetopt", | |
| 8425 "vared", | |
| 8426 "wait", | |
| 8427 "whence", | |
| 8428 "where", | |
| 8429 "which", | |
| 8430 "zcompile", | |
| 8431 "zformat", | |
| 8432 "zftp", | |
| 8433 "zle", | |
| 8434 "zmodload", | |
| 8435 "zparseopts", | |
| 8436 "zprof", | |
| 8437 "zpty", | |
| 8438 "zregexparse", | |
| 8439 "zsocket", | |
| 8440 "zstyle", | |
| 8441 "ztcp" | |
| 8442 ]; | |
| 8443 | |
| 8444 const GNU_CORE_UTILS = [ | |
| 8445 "chcon", | |
| 8446 "chgrp", | |
| 8447 "chown", | |
| 8448 "chmod", | |
| 8449 "cp", | |
| 8450 "dd", | |
| 8451 "df", | |
| 8452 "dir", | |
| 8453 "dircolors", | |
| 8454 "ln", | |
| 8455 "ls", | |
| 8456 "mkdir", | |
| 8457 "mkfifo", | |
| 8458 "mknod", | |
| 8459 "mktemp", | |
| 8460 "mv", | |
| 8461 "realpath", | |
| 8462 "rm", | |
| 8463 "rmdir", | |
| 8464 "shred", | |
| 8465 "sync", | |
| 8466 "touch", | |
| 8467 "truncate", | |
| 8468 "vdir", | |
| 8469 "b2sum", | |
| 8470 "base32", | |
| 8471 "base64", | |
| 8472 "cat", | |
| 8473 "cksum", | |
| 8474 "comm", | |
| 8475 "csplit", | |
| 8476 "cut", | |
| 8477 "expand", | |
| 8478 "fmt", | |
| 8479 "fold", | |
| 8480 "head", | |
| 8481 "join", | |
| 8482 "md5sum", | |
| 8483 "nl", | |
| 8484 "numfmt", | |
| 8485 "od", | |
| 8486 "paste", | |
| 8487 "ptx", | |
| 8488 "pr", | |
| 8489 "sha1sum", | |
| 8490 "sha224sum", | |
| 8491 "sha256sum", | |
| 8492 "sha384sum", | |
| 8493 "sha512sum", | |
| 8494 "shuf", | |
| 8495 "sort", | |
| 8496 "split", | |
| 8497 "sum", | |
| 8498 "tac", | |
| 8499 "tail", | |
| 8500 "tr", | |
| 8501 "tsort", | |
| 8502 "unexpand", | |
| 8503 "uniq", | |
| 8504 "wc", | |
| 8505 "arch", | |
| 8506 "basename", | |
| 8507 "chroot", | |
| 8508 "date", | |
| 8509 "dirname", | |
| 8510 "du", | |
| 8511 "echo", | |
| 8512 "env", | |
| 8513 "expr", | |
| 8514 "factor", | |
| 8515 // "false", // keyword literal already | |
| 8516 "groups", | |
| 8517 "hostid", | |
| 8518 "id", | |
| 8519 "link", | |
| 8520 "logname", | |
| 8521 "nice", | |
| 8522 "nohup", | |
| 8523 "nproc", | |
| 8524 "pathchk", | |
| 8525 "pinky", | |
| 8526 "printenv", | |
| 8527 "printf", | |
| 8528 "pwd", | |
| 8529 "readlink", | |
| 8530 "runcon", | |
| 8531 "seq", | |
| 8532 "sleep", | |
| 8533 "stat", | |
| 8534 "stdbuf", | |
| 8535 "stty", | |
| 8536 "tee", | |
| 8537 "test", | |
| 8538 "timeout", | |
| 8539 // "true", // keyword literal already | |
| 8540 "tty", | |
| 8541 "uname", | |
| 8542 "unlink", | |
| 8543 "uptime", | |
| 8544 "users", | |
| 8545 "who", | |
| 8546 "whoami", | |
| 8547 "yes" | |
| 8548 ]; | |
| 8549 | |
| 8550 return { | |
| 8551 name: 'Bash', | |
| 8552 aliases: [ | |
| 8553 'sh', | |
| 8554 'zsh' | |
| 8555 ], | |
| 8556 keywords: { | |
| 8557 $pattern: /\b[a-z][a-z0-9._-]+\b/, | |
| 8558 keyword: KEYWORDS, | |
| 8559 literal: LITERALS, | |
| 8560 built_in: [ | |
| 8561 ...SHELL_BUILT_INS, | |
| 8562 ...BASH_BUILT_INS, | |
| 8563 // Shell modifiers | |
| 8564 "set", | |
| 8565 "shopt", | |
| 8566 ...ZSH_BUILT_INS, | |
| 8567 ...GNU_CORE_UTILS | |
| 8568 ] | |
| 8569 }, | |
| 8570 contains: [ | |
| 8571 KNOWN_SHEBANG, // to catch known shells and boost relevancy | |
| 8572 hljs.SHEBANG(), // to catch unknown shells but still highlight the shebang | |
| 8573 FUNCTION, | |
| 8574 ARITHMETIC, | |
| 8575 COMMENT, | |
| 8576 HERE_DOC, | |
| 8577 PATH_MODE, | |
| 8578 QUOTE_STRING, | |
| 8579 ESCAPED_QUOTE, | |
| 8580 APOS_STRING, | |
| 8581 ESCAPED_APOS, | |
| 8582 VAR | |
| 8583 ] | |
| 8584 }; | |
| 8585 } | |
| 8586 } | |
| 8587 return bash; | |
| 8588 })(); | |
| 8589 | |
| 8590 hljs.registerLanguage('bash', hljsGrammar); | |
| 8591 })(); |