├── .github └── workflows │ └── deploy.yml ├── .gitignore ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src └── main ├── kotlin ├── main.kt └── net │ └── kyori │ └── adventure │ └── text │ └── minimessage │ ├── Context.kt │ ├── MiniMessage.kt │ ├── MiniMessageImpl.kt │ ├── MiniMessageParser.kt │ ├── Template.kt │ ├── Tokens.kt │ ├── helper │ ├── ClickEvent.kt │ ├── Component.kt │ ├── HoverEvent.kt │ ├── Key.kt │ ├── NamedTextColor.kt │ ├── Style.kt │ ├── TextColor.kt │ ├── TextComponent.kt │ └── TextDecoration.kt │ ├── markdown │ ├── DiscordFlavor.kt │ ├── GithubFlavor.kt │ ├── LegacyFlavor.kt │ ├── MarkdownFlavor.kt │ ├── MiniMarkdownParser.kt │ └── package-info.kt │ ├── package-info.kt │ ├── parser │ ├── ParsingException.kt │ ├── Token.kt │ ├── TokenParser.kt │ ├── TokenType.kt │ ├── node │ │ ├── ElementNode.kt │ │ ├── RootNode.kt │ │ ├── TagNode.kt │ │ ├── TagPart.kt │ │ ├── TemplateNode.kt │ │ ├── TextNode.kt │ │ ├── ValueNode.kt │ │ └── package-info.kt │ └── package-info.kt │ └── transformation │ ├── Inserting.kt │ ├── Modifying.kt │ ├── Transformation.kt │ ├── TransformationParser.kt │ ├── TransformationRegistry.kt │ ├── TransformationRegistryImpl.kt │ ├── TransformationType.kt │ ├── inbuild │ ├── ClickTransformation.kt │ ├── ColorTransformation.kt │ ├── DecorationTransformation.kt │ ├── FontTransformation.kt │ ├── GradientTransformation.kt │ ├── HoverTransformation.kt │ ├── InsertionTransformation.kt │ ├── KeybindTransformation.kt │ ├── RainbowTransformation.kt │ ├── TemplateTransformation.kt │ ├── TranslatableTransformation.kt │ └── package-info.kt │ └── package-info.kt └── resources ├── font ├── 1_Minecraft-Regular.woff ├── 2_Minecraft-Italic.woff ├── 3_Minecraft-Bold.woff └── 4_Minecraft-BoldItalic.woff ├── img ├── desert.png ├── grass.png ├── stone.png └── water.png ├── index.html └── style.css /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy 2 | on: 3 | push: 4 | branches: [ main ] 5 | jobs: 6 | build-and-deploy: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout 🛎️ 10 | uses: actions/checkout@v2.3.1 11 | 12 | - name: Install and Build 🔧 13 | run: ./gradlew build 14 | 15 | - name: Deploy 🚀 16 | uses: JamesIves/github-pages-deploy-action@4.1.4 17 | with: 18 | branch: gh-pages 19 | folder: build/distributions 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MiniMessage Viewer 2 | 3 | > It's cursed 4 | 5 | **in fact, its so cursed that its dead now, a much better version can be found [here](https://github.com/KyoriPowered/adventure-webui).** 6 | 7 | A hacked together web based editor/viewer for MiniMessage. 8 | 9 | --> **[Access it here](https://minidigger.github.io/MiniMessageViewer/)** <-- 10 | 11 | This was created by copy-pasting all code from MiniMessage's new parser into this project, telling IntelliJ to convert it to Kotlin, 12 | ripping out Adventure and replacing it with DOM calls, hacking till it compiles (**I don't know kotlin nor do I like it**) and throwing it on GitHub. 13 | 14 | ## Status 15 | 16 | I will most likely not spend much time on this project. You can see a list of stuff I should do here: https://github.com/MiniDigger/MiniMessageViewer/issues/1 17 | No gurantee that I will actually do that tho. 18 | Contributions are welcome tho! 19 | 20 | ## Dev Setup 21 | 22 | `` 23 | gradlew browserDevelopmentRun --continuous 24 | `` 25 | 26 | then you can just edit the kotlin code and it will auto rebuild and reload 27 | 28 | ## Licence 29 | 30 | no. this code is cursed, don't look at it, don't use it, just use the website. 31 | 32 | ## Credits 33 | 34 | Font is from here: https://fonts2u.com/minecraft-regular.font 35 | You can find the real MiniMessage project here: https://github.com/KyoriPowered/adventure-text-minimessage 36 | Blame Noxite for the idea: https://i.imgur.com/pmyoW0D.png 37 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("js") version "1.5.20" 3 | } 4 | 5 | group = "org.example" 6 | version = "1.0-SNAPSHOT" 7 | 8 | repositories { 9 | mavenCentral() 10 | } 11 | 12 | dependencies { 13 | implementation(kotlin("stdlib-js")) 14 | implementation("org.jetbrains.kotlin-wrappers:kotlin-extensions:1.0.1-pre.214-kotlin-1.5.20") 15 | 16 | } 17 | 18 | kotlin { 19 | js { 20 | browser { 21 | webpackTask { 22 | cssSupport.enabled = true 23 | } 24 | 25 | runTask { 26 | cssSupport.enabled = true 27 | } 28 | } 29 | binaries.executable() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MiniDigger/MiniMessageViewer/0e734e1a21cc9a09103da3526b8d19dfdd559673/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | 86 | # Determine the Java command to use to start the JVM. 87 | if [ -n "$JAVA_HOME" ] ; then 88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 89 | # IBM's JDK on AIX uses strange locations for the executables 90 | JAVACMD="$JAVA_HOME/jre/sh/java" 91 | else 92 | JAVACMD="$JAVA_HOME/bin/java" 93 | fi 94 | if [ ! -x "$JAVACMD" ] ; then 95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 96 | 97 | Please set the JAVA_HOME variable in your environment to match the 98 | location of your Java installation." 99 | fi 100 | else 101 | JAVACMD="java" 102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 103 | 104 | Please set the JAVA_HOME variable in your environment to match the 105 | location of your Java installation." 106 | fi 107 | 108 | # Increase the maximum file descriptors if we can. 109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 110 | MAX_FD_LIMIT=`ulimit -H -n` 111 | if [ $? -eq 0 ] ; then 112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 113 | MAX_FD="$MAX_FD_LIMIT" 114 | fi 115 | ulimit -n $MAX_FD 116 | if [ $? -ne 0 ] ; then 117 | warn "Could not set maximum file descriptor limit: $MAX_FD" 118 | fi 119 | else 120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 121 | fi 122 | fi 123 | 124 | # For Darwin, add options to specify how the application appears in the dock 125 | if $darwin; then 126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 127 | fi 128 | 129 | # For Cygwin or MSYS, switch paths to Windows format before running java 130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 133 | 134 | JAVACMD=`cygpath --unix "$JAVACMD"` 135 | 136 | # We build the pattern for arguments to be converted via cygpath 137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 138 | SEP="" 139 | for dir in $ROOTDIRSRAW ; do 140 | ROOTDIRS="$ROOTDIRS$SEP$dir" 141 | SEP="|" 142 | done 143 | OURCYGPATTERN="(^($ROOTDIRS))" 144 | # Add a user-defined pattern to the cygpath arguments 145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 147 | fi 148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 149 | i=0 150 | for arg in "$@" ; do 151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 153 | 154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 156 | else 157 | eval `echo args$i`="\"$arg\"" 158 | fi 159 | i=`expr $i + 1` 160 | done 161 | case $i in 162 | 0) set -- ;; 163 | 1) set -- "$args0" ;; 164 | 2) set -- "$args0" "$args1" ;; 165 | 3) set -- "$args0" "$args1" "$args2" ;; 166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 172 | esac 173 | fi 174 | 175 | # Escape application args 176 | save () { 177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 178 | echo " " 179 | } 180 | APP_ARGS=`save "$@"` 181 | 182 | # Collect all arguments for the java command, following the shell quoting and substitution rules 183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 184 | 185 | exec "$JAVACMD" "$@" 186 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "MiniMessageViewer" 2 | 3 | -------------------------------------------------------------------------------- /src/main/kotlin/main.kt: -------------------------------------------------------------------------------- 1 | 2 | import kotlinext.js.asJsObject 3 | import kotlinx.browser.document 4 | import kotlinx.browser.window 5 | import kotlinx.dom.hasClass 6 | import net.kyori.adventure.text.minimessage.MiniMessage 7 | import org.w3c.dom.Element 8 | import org.w3c.dom.HTMLAnchorElement 9 | import org.w3c.dom.HTMLDivElement 10 | import org.w3c.dom.HTMLElement 11 | import org.w3c.dom.HTMLPreElement 12 | import org.w3c.dom.HTMLSelectElement 13 | import org.w3c.dom.HTMLTextAreaElement 14 | import org.w3c.dom.asList 15 | import org.w3c.dom.get 16 | import org.w3c.dom.url.URLSearchParams 17 | 18 | enum class Mode { 19 | CHAT_OPEN, CHAT_CLOSED, LORE, HOLOGRAM, BOOK; 20 | 21 | val className = "mode-${name.lowercase().replace('_', '-')}" 22 | val paramName = name.lowercase() 23 | 24 | companion object { 25 | val default = CHAT_CLOSED 26 | val modes = values().asList() 27 | val index = modes.associateBy { it.name } 28 | 29 | /** Gets a mode from [string], returning [CHAT_CLOSED] as a default. */ 30 | fun fromString(string: String?): Mode = index[string?.uppercase()] ?: default 31 | } 32 | } 33 | 34 | val homeUrl by lazy { window.location.href.split('?')[0] } 35 | lateinit var currentMode: Mode 36 | 37 | // thanks kotlin you rock 38 | external fun decodeURIComponent(encodedURI: String): String 39 | external fun encodeURIComponent(string: String): String 40 | 41 | const val PARAM_INPUT = "input" 42 | const val PARAM_MODE = "mode" 43 | 44 | fun main() { 45 | document.addEventListener("DOMContentLoaded", { 46 | // CORRECT HOME LINK 47 | document.getElementById("home-link")!!.asJsObject().unsafeCast().href = homeUrl 48 | 49 | // SHARING 50 | val inputBox = document.getElementById("input")!!.asJsObject().unsafeCast() 51 | val urlParams = URLSearchParams(window.location.search) 52 | val outputPre = document.getElementById("output-pre")!!.asJsObject().unsafeCast() 53 | val outputPane = document.getElementById("output-pane")!!.asJsObject().unsafeCast() 54 | 55 | currentMode = Mode.fromString(urlParams.get(PARAM_MODE)) 56 | outputPre.classList.add(currentMode.className) 57 | outputPane.classList.add(currentMode.className) 58 | 59 | urlParams.get(PARAM_INPUT)?.also { inputString -> 60 | val text = decodeURIComponent(inputString) 61 | inputBox.innerText = text 62 | println("SHARED: $text") 63 | parse(text) 64 | } 65 | 66 | // INPUT 67 | val input = document.getElementById("input")!!.asJsObject().unsafeCast() 68 | input.addEventListener("keyup", { 69 | parse(input.value) 70 | }) 71 | input.addEventListener("change", { 72 | parse(input.value) 73 | }) 74 | 75 | // OBFUSCATION 76 | window.setInterval( { obfuscateAll() }, 10) 77 | 78 | // CARET 79 | val chatBox = document.getElementById("chat-entry-box")!!.asJsObject().unsafeCast() 80 | window.setInterval({ 81 | chatBox.innerHTML = if (chatBox.innerHTML == "_") " " else "_" 82 | }, 380) 83 | 84 | // BUTTONS 85 | val settingsBox = document.getElementById("settings-box") 86 | document.getElementsByClassName("settings-button").asList().forEach { element -> 87 | element.addEventListener("click", { 88 | settingsBox!!.classList.toggle("is-active") 89 | }) 90 | } 91 | 92 | val modeButtons = document.getElementsByClassName("mc-mode").asList().unsafeCast>() 93 | modeButtons.forEach { element -> 94 | // set is-active on the current mode first 95 | val mode = Mode.valueOf(element.dataset["mode"]!!) 96 | if (currentMode == mode) { 97 | element.classList.add("is-active") 98 | } 99 | 100 | // then add event listeners for the rest 101 | element.addEventListener("click", { event -> 102 | // remove active 103 | modeButtons.forEach { button -> 104 | button.classList.remove("is-active") 105 | } 106 | 107 | // now add it again lmao 10/10 code 108 | val button = event.target!!.asJsObject().unsafeCast() 109 | button.classList.add("is-active") 110 | currentMode = mode 111 | 112 | // swap the class for the pane 113 | Mode.modes.forEach { mode -> 114 | if (currentMode == mode) { 115 | outputPre.classList.add(mode.className) 116 | outputPane.classList.add(mode.className) 117 | } else { 118 | outputPre.classList.remove(mode.className) 119 | outputPane.classList.remove(mode.className) 120 | } 121 | } 122 | }) 123 | } 124 | 125 | // CLIPBOARD 126 | val shareButton = document.getElementById("share-button")!!.asJsObject().unsafeCast() 127 | val shareBox = document.getElementById("share-box")!!.asJsObject().unsafeCast() 128 | shareButton.addEventListener("click", { 129 | window.navigator.clipboard.writeText("$homeUrl?$PARAM_MODE=${currentMode.paramName}&$PARAM_INPUT=${encodeURIComponent(input.value)}").then { 130 | shareBox.classList.add("is-active") 131 | } 132 | }) 133 | document.getElementsByClassName("close-share-box").asList().unsafeCast>().forEach { element -> 134 | element.addEventListener("click", { 135 | shareBox.classList.remove("is-active") 136 | }) 137 | } 138 | 139 | // BURGER MENU 140 | val burgerMenu = document.getElementById("burger-menu")!! 141 | val navbarMenu = document.getElementById("navbar-menu")!! 142 | burgerMenu.addEventListener("click", { 143 | burgerMenu.classList.toggle("is-active") 144 | navbarMenu.classList.toggle("is-active") 145 | }) 146 | 147 | // SETTINGS 148 | val settingBackground = document.getElementById("setting-background")!!.asJsObject().unsafeCast() 149 | settingBackground.addEventListener("change", { 150 | outputPane.style.backgroundImage = "url(\"img/${settingBackground.value}.png\")" 151 | }) 152 | }) 153 | } 154 | 155 | fun obfuscateAll() { 156 | document.getElementsByClassName("obfuscated").asList().forEach { 157 | obfuscate(it) 158 | } 159 | } 160 | 161 | fun obfuscate(input: Element) { 162 | if (input.hasClass("hover")) return 163 | if (input.childElementCount > 0) { 164 | input.children.asList().forEach { 165 | obfuscate(it) 166 | } 167 | } else if (input.textContent != null){ 168 | input.textContent = obfuscate(input.textContent!!) 169 | } 170 | } 171 | 172 | fun CharArray.map(transform: (Char) -> Char): CharArray { 173 | for (i in this.indices) { 174 | this[i] = transform(this[i]) 175 | } 176 | return this 177 | } 178 | 179 | fun obfuscate(input: String): String { 180 | val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9') 181 | 182 | return input.toCharArray() 183 | .map { if (it != ' ') allowedChars.random() else it } 184 | .concatToString() 185 | } 186 | 187 | fun parse(input: String) { 188 | val output = document.getElementById("output-pre")!! 189 | output.textContent = "" 190 | val miniMessage = MiniMessage.builder().debug(object : Appendable { 191 | override fun append(value: Char): Appendable { 192 | print(value) 193 | return this 194 | } 195 | 196 | override fun append(value: CharSequence?): Appendable { 197 | print(value) 198 | return this 199 | } 200 | 201 | override fun append(value: CharSequence?, startIndex: Int, endIndex: Int): Appendable { 202 | TODO("Not yet implemented") 203 | } 204 | 205 | }).parsingErrorMessageConsumer { }.build() 206 | val lines = input.split("\n") 207 | 208 | lines.map { line -> 209 | // we don't want to lose empty lines, so replace them with zero-width space 210 | if (line == "") "\u200B" else line 211 | }.forEach { line -> 212 | println("BEGING PARSING \"$line\"") 213 | val div = document.createElement("div") 214 | div.append(miniMessage.parse(line).buildOutChildren()) 215 | output.append(div) 216 | println("DONE") 217 | } 218 | 219 | // reset scroll to bottom (like how chat works) 220 | if (currentMode == Mode.CHAT_OPEN || currentMode == Mode.CHAT_CLOSED) { 221 | output.scrollTop = output.scrollHeight.toDouble() 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /src/main/kotlin/net/kyori/adventure/text/minimessage/Context.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of adventure-text-minimessage, licensed under the MIT License. 3 | * 4 | * Copyright (c) 2018-2021 KyoriPowered 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package net.kyori.adventure.text.minimessage 25 | 26 | import net.kyori.adventure.text.minimessage.helper.Component 27 | import net.kyori.adventure.text.minimessage.parser.node.ElementNode 28 | 29 | /** 30 | * Carries needed context for minimessage around, ranging from debug info to the configured minimessage instance. 31 | * 32 | * @since 4.1.0 33 | */ 34 | class Context internal constructor(private val strict: Boolean, private val debugOutput: Appendable?, root: ElementNode?, ogMessage: String, replacedMessage: String?, miniMessage: MiniMessageImpl, templates: Array) { 35 | private var root: ElementNode? 36 | private val ogMessage: String 37 | private var replacedMessage: String? 38 | private val miniMessage: MiniMessageImpl 39 | 40 | private val templates: Array 41 | 42 | /** 43 | * Sets the root element. 44 | * 45 | * @param root the root element. 46 | * @since 4.1.0 47 | */ 48 | fun root(root: ElementNode?) { 49 | this.root = root 50 | } 51 | 52 | /** 53 | * sets the replaced message. 54 | * 55 | * @param replacedMessage the replaced message 56 | * @since 4.1.0 57 | */ 58 | fun replacedMessage(replacedMessage: String?) { 59 | this.replacedMessage = replacedMessage 60 | } 61 | 62 | /** 63 | * Returns strict mode. 64 | * 65 | * @return if strict mode is enabled 66 | * @since 4.1.0 67 | */ 68 | fun strict(): Boolean { 69 | return strict 70 | } 71 | 72 | /** 73 | * Returns the appendable to print debug output to. 74 | * 75 | * @return the debug output to print to 76 | * @since 4.2.0 77 | */ 78 | fun debugOutput(): Appendable? { 79 | return debugOutput 80 | } 81 | 82 | /** 83 | * Returns the root element. 84 | * 85 | * @return root 86 | * @since 4.1.0 87 | */ 88 | fun tokens(): ElementNode? { 89 | return root 90 | } 91 | 92 | /** 93 | * Returns og message. 94 | * 95 | * @return ogMessage 96 | * @since 4.1.0 97 | */ 98 | fun ogMessage(): String { 99 | return ogMessage 100 | } 101 | 102 | /** 103 | * Returns replaced message. 104 | * 105 | * @return replacedMessage 106 | * @since 4.1.0 107 | */ 108 | fun replacedMessage(): String? { 109 | return replacedMessage 110 | } 111 | 112 | /** 113 | * Returns minimessage. 114 | * 115 | * @return minimessage 116 | * @since 4.1.0 117 | */ 118 | fun miniMessage(): MiniMessageImpl { 119 | return miniMessage 120 | } 121 | 122 | /** 123 | * Parses a MiniMessage using all the settings of this context, including templates. 124 | * 125 | * @param message the message to parse 126 | * @return the parsed message 127 | * @since 4.1.0 128 | */ 129 | fun parse(message: String): Component { 130 | return if(templates != null && templates.isNotEmpty()) { 131 | miniMessage.parse(message, templates) 132 | } else { 133 | miniMessage.parse(message) 134 | } 135 | } 136 | 137 | companion object { 138 | /** 139 | * Init. 140 | * 141 | * @param strict if strict mode is enabled 142 | * @param input the input message 143 | * @param miniMessage the minimessage instance 144 | * @return the debug context 145 | * @since 4.1.0 146 | */ 147 | fun of(strict: Boolean, input: String, miniMessage: MiniMessageImpl): Context { 148 | return Context(strict, null, null, input, null, miniMessage, arrayOf()) 149 | } 150 | 151 | /** 152 | * Init. 153 | * 154 | * @param strict if strict mode is enabled 155 | * @param debugOutput where to print debug output 156 | * @param input the input message 157 | * @param miniMessage the minimessage instance 158 | * @return the debug context 159 | * @since 4.1.0 160 | */ 161 | fun of(strict: Boolean, debugOutput: Appendable?, input: String, miniMessage: MiniMessageImpl): Context { 162 | return Context(strict, debugOutput, null, input, null, miniMessage, arrayOf()) 163 | } 164 | 165 | /** 166 | * Init. 167 | * 168 | * @param strict if strict mode is enabled 169 | * @param input the input message 170 | * @param miniMessage the minimessage instance 171 | * @param templates the templates passed to minimessage 172 | * @return the debug context 173 | * @since 4.1.0 174 | */ 175 | fun of(strict: Boolean, input: String, miniMessage: MiniMessageImpl, templates: Array): Context { 176 | return Context(strict, null, null, input, null, miniMessage, templates) 177 | } 178 | 179 | /** 180 | * Init. 181 | * 182 | * @param strict if strict mode is enabled 183 | * @param debugOutput where to print debug output 184 | * @param input the input message 185 | * @param miniMessage the minimessage instance 186 | * @param templates the templates passed to minimessage 187 | * @return the debug context 188 | * @since 4.2.0 189 | */ 190 | fun of(strict: Boolean, debugOutput: Appendable?, input: String, miniMessage: MiniMessageImpl, templates: Array): Context { 191 | return Context(strict, debugOutput, null, input, null, miniMessage, templates) 192 | } 193 | } 194 | 195 | init { 196 | this.root = root 197 | this.ogMessage = ogMessage 198 | this.replacedMessage = replacedMessage 199 | this.miniMessage = miniMessage 200 | this.templates = templates 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /src/main/kotlin/net/kyori/adventure/text/minimessage/MiniMessage.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * This file is part of adventure-text-minimessage, licensed under the MIT License. 3 | * 4 | * Copyright (c) 2018-2021 KyoriPowered 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package net.kyori.adventure.text.minimessage 25 | 26 | import net.kyori.adventure.text.minimessage.helper.Component 27 | import net.kyori.adventure.text.minimessage.markdown.MarkdownFlavor 28 | import net.kyori.adventure.text.minimessage.transformation.TransformationRegistry 29 | 30 | 31 | /** 32 | * MiniMessage is a textual representation of components. 33 | * 34 | * 35 | * This class allows you to serialize and deserialize them, strip 36 | * or escape them, and even supports a markdown like format. 37 | * 38 | * @since 4.0.0 39 | */ 40 | interface MiniMessage { 41 | /** 42 | * Escapes all tokens in the input message, so that they are ignored in deserialization. 43 | * 44 | * 45 | * Useful for untrusted input. 46 | * 47 | * @param input the input message, with tokens 48 | * @return the output, with escaped tokens 49 | * @since 4.0.0 50 | */ 51 | fun escapeTokens(input: String): String 52 | 53 | /** 54 | * Removes all tokens in the input message. 55 | * 56 | * 57 | * Useful for untrusted input. 58 | * 59 | * @param input the input message, with tokens 60 | * @return the output, without tokens 61 | * @since 4.0.0 62 | */ 63 | fun stripTokens(input: String): String 64 | 65 | /** 66 | * Parses a string into an component. 67 | * 68 | * @param input the input string 69 | * @return the output component 70 | * @since 4.0.0 71 | */ 72 | fun parse(input: String): Component { 73 | return this.deserialize(input) 74 | } 75 | 76 | fun deserialize(input: String): Component 77 | 78 | /** 79 | * Parses a string into an component, allows passing placeholders in key value pairs. 80 | * 81 | * @param input the input string 82 | * @param placeholders the placeholders 83 | * @return the output component 84 | * @since 4.1.0 85 | */ 86 | fun parse(input: String, vararg placeholders: String): Component 87 | 88 | /** 89 | * Parses a string into an component, allows passing placeholders in key value pairs. 90 | * 91 | * @param input the input string 92 | * @param placeholders the placeholders 93 | * @return the output component 94 | * @since 4.1.0 95 | */ 96 | fun parse(input: String, placeholders: Map): Component 97 | 98 | /** 99 | * Parses a string into an component, allows passing placeholders using key component pairs. 100 | * 101 | * @param input the input string 102 | * @param placeholders the placeholders 103 | * @return the output component 104 | * @since 4.1.0 105 | */ 106 | fun parse(input: String, vararg placeholders: Any): Component 107 | 108 | /** 109 | * Parses a string into an component, allows passing placeholders using templates (which support components). 110 | * MiniMessage parses placeholders from following syntax: `` where placeholder_name is [Template.key] 111 | * 112 | * @param input the input string 113 | * @param placeholders the placeholders 114 | * @return the output component 115 | * @since 4.0.0 116 | */ 117 | fun parse(input: String, vararg placeholders: Template): Component 118 | 119 | /** 120 | * Parses a string into an component, allows passing placeholders using templates (which support components). 121 | * MiniMessage parses placeholders from following syntax: `` where placeholder_name is [Template.key] 122 | * 123 | * @param input the input string 124 | * @param placeholders the placeholders 125 | * @return the output component 126 | * @since 4.0.0 127 | */ 128 | fun parse(input: String, placeholders: List