Files
jiang13-bbs/frontend/components/markdown/aardioGrammar.ts
freefire 2dd9cb82b3 fix(frontend): 修复 aardio 注释着色、代码行距与折叠 hydration
注释不再被运算符拆开;去掉 grid 行 min-height;挂载后再折叠以避免 SSR/CSR 不一致。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-16 06:25:25 +08:00

118 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { LanguageRegistration } from "shiki";
/**
* aardio TextMate grammar(对齐官方 Prism / highlight.js 规则):
* https://www.aardio.com/zh-cn/docs/js/prism.js
*/
export const aardioGrammar: LanguageRegistration = {
name: "aardio",
scopeName: "source.aardio",
// 勿把 name 自身再写进 aliases,否则 Shiki 报 Circular alias
patterns: [
{ include: "#block-comment" },
{ include: "#line-comment" },
{ include: "#string-double" },
{ include: "#string-backtick" },
{ include: "#string-single" },
{ include: "#constant-underscore" },
{ include: "#class-decl" },
{ include: "#keywords" },
{ include: "#literals" },
{ include: "#function-call" },
{ include: "#numbers" },
{ include: "#operators" },
],
repository: {
"block-comment": {
name: "comment.block.aardio",
// 用明确的 /* ... */,不要 include self(会在注释内再次匹配运算符)
begin: "/\\*",
end: "\\*/",
},
"line-comment": {
name: "comment.line.double-slash.aardio",
match: "//.*$",
},
"string-double": {
name: "string.quoted.double.aardio",
begin: '"',
end: '"',
patterns: [{ name: "constant.character.escape.aardio", match: '""' }],
},
"string-backtick": {
name: "string.quoted.other.aardio",
begin: "`",
end: "`",
patterns: [{ name: "constant.character.escape.aardio", match: "``" }],
},
"string-single": {
name: "string.quoted.single.aardio",
begin: "'",
end: "'",
patterns: [
{
name: "constant.character.escape.aardio",
match: "\\\\.",
},
],
},
"constant-underscore": {
name: "constant.other.aardio",
match: "\\b_[A-Za-z]\\w*\\b",
},
"class-decl": {
begin: "\\b(class)\\b",
beginCaptures: {
"1": { name: "keyword.control.aardio" },
},
end: "(?=[{;])",
patterns: [
{
name: "entity.name.type.class.aardio",
match: "[\\w.\\\\]+",
},
],
},
keywords: {
name: "keyword.control.aardio",
match:
"\\b(?:begin|end|if|lambda|\\u03BB|else|elseif|class|function|return|while|do|namespace|select|case|catch|try|for|in|this|global|self|owner|var|def|and|not|or|break|continue|import|with|ctor|eval|type|assert|assert2|assertf|error|rget|callex|errput|loadcode|dumpcode|collectgarbage|call|invoke|tostring|topointer|tonumber|sleep|execute|setlocale|setprivilege|loadcodex|reduce|switch)\\b",
},
literals: {
name: "constant.language.aardio",
match: "\\b(?:true|false|null)\\b",
},
"function-call": {
name: "entity.name.function.aardio",
match:
"\\b(?!(?:begin|end|if|lambda|\\u03BB|else|elseif|class|function|return|while|do|namespace|select|case|catch|try|for|in|this|global|self|owner|var|def|null|and|not|or|break|continue|import|with|ctor|eval|type|assert|assert2|assertf|error|rget|callex|errput|loadcode|dumpcode|collectgarbage|call|invoke|tostring|topointer|tonumber|sleep|execute|setlocale|setprivilege|loadcodex|reduce|switch|true|false)\\b)[_$A-Za-z][_$A-Za-z0-9]*(?=\\s*\\()",
},
numbers: {
patterns: [
{
name: "constant.numeric.aardio",
match: "\\b0x[a-fA-F_\\d]+(?:\\.[a-fA-F_\\d]*)?(?:p[+-]?\\d[_\\d]*)?\\b",
},
{
name: "constant.numeric.aardio",
match: "\\b\\d+#[\\d_]+\\b",
},
{
name: "constant.numeric.aardio",
match: "\\b\\d[_\\d]*(?:\\.(?![\\w.])|\\.[_\\d]*)?(?:e[+-]?\\d[_\\d]*)?\\b",
},
{
name: "constant.numeric.aardio",
match: "\\.\\d[_\\d]*(?:e[+-]?\\d[_\\d]*)?\\b",
},
],
},
operators: {
name: "keyword.operator.aardio",
// / 与 * 用前瞻避开注释分隔符 /* */,避免把注释拆成运算符
match:
"\\.\\.|--|\\+\\+|\\*\\*=?|&&=?|\\|\\|=?|[!=]==|<<=?|>>>?=?|\\+=|-=|\\*=|/=|%=|&=|\\|=|\\^=|[=!<>]=?|[+\\-~%?:]|\\^|&|\\||/(?!\\*)|\\*(?!/)",
},
},
};