diff --git a/src/routes/mods/[id]/+page.svelte b/src/routes/mods/[id]/+page.svelte index e4474b3..c80a4c6 100644 --- a/src/routes/mods/[id]/+page.svelte +++ b/src/routes/mods/[id]/+page.svelte @@ -30,6 +30,44 @@ data.mod.versions.forEach(version => version.download_link) export let form: ActionData; + + const colorTags: { [key: string]: string } = { + a: "#9632ff", + b: "#4a52e1", + g: "#40e348", + l: "#60abef", + j: "#32c8ff", + y: "#ffff00", + o: "#ffa54b", + r: "#ff5a5a", + p: "#ff00ff" + } + + function toHex6(str: string): string { + const hex = str.startsWith("#") ? str.slice(1) : str; + switch (hex.length) { + case 1: + return "#" + hex[0] + hex[0] + hex[0] + hex[0] + hex[0] + hex[0]; + case 2: + return "#" + hex[0] + hex[1] + hex[0] + hex[1] + hex[0] + hex[1]; + case 3: + return "#" + hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; + default: + return "#" + hex.padStart(6, "0"); + } + } + + function convertColorTags(text: string): string { + return text.replace(//g, (_: string, color: string) => { + return `color-tag{${toHex6(color)}(`; + }).replace(//g, (_: string, color: string) => { + return colorTags[color] ? `color-tag{${colorTags[color]}(` : "color-tag{#ffffff("; + }).replace(/<\/c[a-z]?>/g, ")}/color-tag"); + } + + function parseColorTags(text: string): string { + return text.replace(/color-tag\{(#[0-9a-f]{6})\(/g, "").replace(/\)\}\/color-tag/g, ""); + } @@ -58,7 +96,7 @@

- {#each data.mod.developers as dev, index} + {#each data.mod.developers.sort((a, b) => a.is_owner ? -1 : b.is_owner ? 1 : 0) as dev, index} {index > 0 ? ', ' : ''}{dev.display_name} {/each}

@@ -79,12 +117,18 @@
- + { + const description = document.getElementById("description")?.getElementsByClassName("markdown").item(0); + if (description) description.innerHTML = parseColorTags(description.innerHTML); + }} />
- + { + const changelog = document.getElementById("changelog")?.getElementsByClassName("markdown").item(0); + if (changelog) changelog.innerHTML = parseColorTags(changelog.innerHTML); + }} />