diff --git a/core/src/main/java/com/seibel/lod/core/jar/installer/MarkdownFormatter.java b/core/src/main/java/com/seibel/lod/core/jar/installer/MarkdownFormatter.java new file mode 100644 index 000000000..ab07e0967 --- /dev/null +++ b/core/src/main/java/com/seibel/lod/core/jar/installer/MarkdownFormatter.java @@ -0,0 +1,67 @@ +package com.seibel.lod.core.jar.installer; + +import java.util.Arrays; +import java.util.List; +import java.util.regex.Pattern; + +/** + * Formats Markdown to other markup languages + * + * @author coolGi + */ +public class MarkdownFormatter { + public static abstract class GenericFormat { + /** Converts Markdown text to a different format */ + public String convertFrom(String original) { + System.out.println("Function \"convertFrom\" for \""+this.getClass().getSimpleName()+"\" not done yet"); + return null; + } + /** Converts formatted text back to Markdown */ + public String convertTo(String original) { + System.out.println("Function \"convertTo\" for \""+this.getClass().getSimpleName()+"\" not done yet"); + return null; + } + } + + + /** Split a string every n characters */ + public static List splitString(String text, int n) { + return Arrays.asList( + text.split("(?<=\\G.{"+ n +"})") + ); + } + private static String replaceRegex(String text, String regex, String start, String end) { + while (Pattern.compile(regex).matcher(text).find()) { + text = text.replaceFirst(regex, start).replaceFirst(regex, end); + } + return text; + } + + + + + public static class HTMLFormat extends GenericFormat { + @Override + public String convertTo(String original) { + original = original.replaceAll("\\\\\\n", "
") // Removes the "\" used in markdown to create new line + .replaceAll("\\n", "
"); // Fix the new line + + original = replaceRegex(original, "\\*\\*", "", ""); // Makes the text bold + original = replaceRegex(original, "~~", "", ""); // Striketrough +// original = replaceRegex(original, "_", "", ""); // Italic + + return original; + } + } + + public static class MinecraftFormat extends GenericFormat { + @Override + public String convertTo(String original) { + original = original.replaceAll("
", "\n"); // New lines + original = replaceRegex(original, "\\*\\*", "§l", "§r"); // Bold + original = replaceRegex(original, "~~", "§m", "§r"); // Striketrough +// original = replaceRegex(original, "_", "§n", "§r"); // Italic + return original; + } + } +} diff --git a/core/src/main/java/com/seibel/lod/core/jar/installer/ModrinthGetter.java b/core/src/main/java/com/seibel/lod/core/jar/installer/ModrinthGetter.java index 475dae491..7da9a8921 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/installer/ModrinthGetter.java +++ b/core/src/main/java/com/seibel/lod/core/jar/installer/ModrinthGetter.java @@ -76,6 +76,9 @@ public class ModrinthGetter { } } + public static String getLatestIDForVersion(String mcVer) { + return mcVerToReleaseID.get(mcVer).get(0); + } public static String getLatestNameForVersion(String mcVer) { return releaseNames.get(mcVerToReleaseID.get(mcVer).get(0)); } diff --git a/core/src/main/java/com/seibel/lod/core/jar/installer/WebDownloader.java b/core/src/main/java/com/seibel/lod/core/jar/installer/WebDownloader.java index 9d4be6af5..cf160b5e2 100644 --- a/core/src/main/java/com/seibel/lod/core/jar/installer/WebDownloader.java +++ b/core/src/main/java/com/seibel/lod/core/jar/installer/WebDownloader.java @@ -72,20 +72,8 @@ public class WebDownloader { } public static String formatMarkdownToHtml(String md, int width) { - String str = String.format("
%s
", width, md) - .replaceAll("\\\\\\n", "
") // Removes the "\" used in markdown to create new line - .replaceAll("\\n", "
"); // Fix the new line - - boolean counter = false; - while (str.contains("**")) { - if (counter) - str = str.replaceFirst("\\*\\*", ""); - else - str = str.replaceFirst("\\*\\*", ""); - counter = !counter; - } - - return str; + String str = String.format("
%s
", width, md); + return new MarkdownFormatter.HTMLFormat().convertTo(str); }