add syntax highlighting for mcfunction & mcscript code blocks

This commit is contained in:
Moritz Hölting 2024-08-20 22:27:14 +02:00
parent 4f7be96abe
commit 386ee37ca7
6 changed files with 1490 additions and 14 deletions

View File

@ -14,6 +14,7 @@
"@astrojs/starlight": "^0.26.1",
"astro": "^4.14.3",
"sharp": "^0.33.5",
"shiki": "^1.14.1",
"starlight-links-validator": "^0.10.1",
"typescript": "^5.4.5"
}

View File

@ -17,6 +17,9 @@ dependencies:
sharp:
specifier: ^0.33.5
version: 0.33.5
shiki:
specifier: ^1.14.1
version: 1.14.1
starlight-links-validator:
specifier: ^0.10.1
version: 0.10.1(@astrojs/starlight@0.26.1)(astro@4.14.3)
@ -696,7 +699,7 @@ packages:
resolution: {integrity: sha512-xm+hzi9BsmhkDUGuyAWIydOAWer7Cs9cj8FM0t4HXaQ+qCubprT6wJZSKUxuvFJIUsIOqk1xXFaJzGJGnWtKMg==}
dependencies:
'@expressive-code/core': 0.35.6
shiki: 1.6.4
shiki: 1.14.1
dev: false
/@expressive-code/plugin-text-markers@0.35.6:
@ -1166,10 +1169,6 @@ packages:
'@types/hast': 3.0.4
dev: false
/@shikijs/core@1.6.4:
resolution: {integrity: sha512-WTU9rzZae1p2v6LOxMf6LhtmZOkIHYYW160IuahUyJy7YXPPjyWZLR1ag+SgD22ZMxZtz1gfU6Tccc8t0Il/XA==}
dev: false
/@types/acorn@4.0.6:
resolution: {integrity: sha512-veQTnWP+1D/xbxVrPC3zHnCZRjSrKfhbMUlEA43iMZLu7EsnTtkJklIuwrCPbOi8YkvDQAiW05VQQFvvz9oieQ==}
dependencies:
@ -3814,12 +3813,6 @@ packages:
'@types/hast': 3.0.4
dev: false
/shiki@1.6.4:
resolution: {integrity: sha512-X88chM7w8jnadoZtjPTi5ahCJx9pc9f8GfEkZAEYUTlcUZIEw2D/RY86HI/LkkE7Nj8TQWkiBfaFTJ3VJT6ESg==}
dependencies:
'@shikijs/core': 1.6.4
dev: false
/signal-exit@3.0.7:
resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==}
dev: false

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,87 @@
import type { LanguageInput } from "shiki";
export const mcscriptGrammar: LanguageInput = {
name: "mcscript",
aliases: [],
displayName: "mcscript",
fileTypes: ["mcscript"],
scopeName: "source.mcscript",
patterns: [
{
name: "comment.line.double-slash.mcscript",
match: "//.*",
},
{
name: "comment.line.hash.mcscript",
match: "\\s*#.*",
},
{
name: "constant.numeric.mcscript",
match: "\\b[0-9\\.\\-]+\\b",
},
{
name: "entity.name.command.mcscript",
match: "\\b(?:advancement|ban|banlist|data|clear|clone|debug|defaultgamemode|deop|difficulty|effect|execute|experience|fill|function|gamemode|gamerule|give|help|kick|kill|list|locate|me|msg|op|pardon|pardon-ip|particle|playsound|publish|recipe|reload|replaceitem|save-all|save-off|save-on|say|scoreboard|seed|setblock|setidletimeout|setworldspawn|spawnpoint|spreadplayers|stop|stopsound|summon|tag|team|teleport|tell|tellraw|time|title|trigger|weather|whitelist|worldborder|xp)\\b",
},
{
name: "keyword.control.mcscript",
match: "\\b(?:if|then|else|unless|true|false|as|at|asat|positioned|align|dimension|rotated|anchored|while|do|forEach|for|raycast|stop|continue|switch|case|default|var|bool|boolean|tag|score|const)\\b",
},
{
name: "keyword.operator.mcscript",
match: "(\\=|\\+\\=|\\-\\=|\\*\\=|\\/\\=|\\%\\=|\\+\\+|\\-\\-|\\*|\\/|\\+|\\-|\\%|\\>|\\<|\\>\\=|\\<\\=)",
},
{
name: "keyword.operator.file.mcscript",
match: "(\\s*#file:|\\s*#extend:)(\\s+)([\\w\\d$\\/\\._-]*)",
},
{
name: "string.quoted.double.mcscript",
match: '"(?:[^\\\\]|\\\\.)*?"',
},
{
name: "string.quoted.single.mcscript",
match: "'(?:[^\\\\]|\\\\.)*?'",
},
{
name: "variable.mcscript",
match: "(\\$[\\w\\-]*)",
},
{
name: "support.function.entity.mcscript",
match: "\\b(?:@a|@p|@s|@r|@e)\\b",
},
{
name: "support.type.entity.mcscript",
match: "\\b(?:area_effect_cloud|armor_stand|arrow|bat|blaze|boat|cave_spider|chest_minecart|chicken|cod_mob|commandblock_minecart|cow|creeper|dolphin|donkey|dragon_fireball|drowned|egg|elder_guardian|ender_crystal|ender_dragon|ender_pearl|enderman|endermite|evocation_fangs|evocation_illager|eye_of_ender_signal|falling_block|fireball|fireworks_rocket|furnace_minecart|ghast|giant|guardian|hopper_minecart|horse|husk|illusion_illager|item|item_frame|leash_knot|lightning_bolt|llama|llama_spit|magma_cube|minecart|mooshroom|mule|ocelot|painting|parrot|phantom|pig|polar_bear|potion|puffer_fish|rabbit|salmon_mob|sheep|shulker|shulker_bullet|silverfish|skeleton|skeleton_horse|slime|small_fireball|snowball|snowman|spawner_minecart|spectral_arrow|spider|squid|stray|tnt|tnt_minecart|trident|tropical_fish|turtle|vex|villager|villager_golem|vindication_illager|witch|wither|wither_skeleton|wither_skull|wolf|xp_bottle|xp_orb|zombie|zombie_horse|zombie_pigman|zombie_villager)\\b",
},
],
repository: {
"$base": {},
"$self": {},
command: {
name: "entity.name.command.mcscript",
match: "\\/\\b(?:command1|command2|...)\\b",
},
keyword: {
name: "keyword.control.mcscript",
match: "\\b(?:if|else|...)\\b",
},
operator: {
name: "keyword.operator.mcscript",
match: "(\\+|\\-|\\*|\\/|...)",
},
string: {
patterns: [
{
name: "string.quoted.double.mcscript",
match: '"(?:[^\\\\]|\\\\.)*?"',
},
{
name: "string.quoted.single.mcscript",
match: "'(?:[^\\\\]|\\\\.)*?'",
},
],
},
},
};

View File

@ -1,9 +1,12 @@
import type { PluginShikiOptions } from "@astrojs/starlight/expressive-code";
import { shulkerscriptGrammar } from "./shulkerscript-grammar";
import { mcfunctionGrammar } from "./mcfunction-grammar";
import { mcscriptGrammar } from "./mcscript-grammar";
const config: PluginShikiOptions = {
const config = {
langs: [
shulkerscriptGrammar,
mcfunctionGrammar,
mcscriptGrammar,
],
};

View File

@ -1,5 +1,6 @@
import type { LanguageInput } from "shiki";
export const shulkerscriptGrammar = {
export const shulkerscriptGrammar: LanguageInput = {
name: "shulkerscript",
aliases: ["shu"],
displayName: "ShulkerScript",
@ -23,6 +24,8 @@ export const shulkerscriptGrammar = {
}
],
repository: {
"$base": {},
"$self": {},
// Groupings
functionContents: {
patterns: [