From 81970ae1c26eb76056120eeb90e337f5b716d8d8 Mon Sep 17 00:00:00 2001 From: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com> Date: Sun, 31 Mar 2024 20:14:18 +0300 Subject: [PATCH] twy docs --- .../ch/njol/skript/doc/Documentation.java | 2 +- .../ch/njol/skript/doc/HTMLGenerator.java | 31 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/njol/skript/doc/Documentation.java b/src/main/java/ch/njol/skript/doc/Documentation.java index 9797e1b2188..aa138b9cb45 100644 --- a/src/main/java/ch/njol/skript/doc/Documentation.java +++ b/src/main/java/ch/njol/skript/doc/Documentation.java @@ -485,7 +485,7 @@ public static String escapeHTML(@Nullable String value) { assert false; return ""; } - return "" + value.replace("&", "&").replace("<", "<").replace(">", ">"); + return HTMLGenerator.introduceSkwipt("" + value.replace("&", "&").replace("<", "<").replace(">", ">")); } public static String[] escapeHTML(@Nullable String[] values) { diff --git a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java index e882057cebd..abf5e39bb0b 100644 --- a/src/main/java/ch/njol/skript/doc/HTMLGenerator.java +++ b/src/main/java/ch/njol/skript/doc/HTMLGenerator.java @@ -456,7 +456,7 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo info, @Nu desc = desc.replace("${element.since}", getDefaultIfNullOrEmpty((since != null ? since.value() : null), "Unknown")); Keywords keywords = c.getAnnotation(Keywords.class); - desc = desc.replace("${element.keywords}", keywords == null ? "" : Joiner.on(", ").join(keywords.value())); + desc = desc.replace("${element.keywords}", keywords == null ? "" : introduceSkwipt(Joiner.on(", ").join(keywords.value()))); // Description Description description = c.getAnnotation(Description.class); @@ -493,7 +493,7 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo info, @Nu } desc = desc.replace("${element.events}", Joiner.on(", ").join(eventLinks)); } - desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join((events != null ? events.value() : null))); + desc = desc.replace("${element.events-safe}", events == null ? "" : introduceSkwipt(Joiner.on(", ").join((events != null ? events.value() : null)))); // RequiredPlugins RequiredPlugins plugins = c.getAnnotation(RequiredPlugins.class); @@ -523,10 +523,10 @@ private String generateAnnotated(String descTemp, SyntaxElementInfo info, @Nu // TODO add type of entrydata like boolean/string/section etc. desc = handleIf(desc, "${if structure-optional-entrydata}", entryValidator != null); - desc = desc.replace("${element.structure-optional-entrydata}", entryValidator == null ? "" : Joiner.on(", ").join(entryDataList.stream().filter(EntryData::isOptional).map(EntryData::getKey).collect(Collectors.toList()))); + desc = desc.replace("${element.structure-optional-entrydata}", entryValidator == null ? "" : introduceSkwipt(Joiner.on(", ").join(entryDataList.stream().filter(EntryData::isOptional).map(EntryData::getKey).collect(Collectors.toList())))); desc = handleIf(desc, "${if structure-required-entrydata}", entryValidator != null); - desc = desc.replace("${element.structure-required-entrydata}", entryValidator == null ? "" : Joiner.on(", ").join(entryDataList.stream().filter(entryData -> !entryData.isOptional()).map(EntryData::getKey).collect(Collectors.toList()))); + desc = desc.replace("${element.structure-required-entrydata}", entryValidator == null ? "" : introduceSkwipt(Joiner.on(", ").join(entryDataList.stream().filter(entryData -> !entryData.isOptional()).map(EntryData::getKey).collect(Collectors.toList())))); } else { desc = handleIf(desc, "${if structure-optional-entrydata}", false); desc = handleIf(desc, "${if structure-required-entrydata}", false); @@ -601,7 +601,7 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable .replace("\\", "\\\\").replace("\"", "\\\"").replace("\t", " ")); String[] keywords = info.getKeywords(); - desc = desc.replace("${element.keywords}", keywords == null ? "" : Joiner.on(", ").join(keywords)); + desc = desc.replace("${element.keywords}", keywords == null ? "" : introduceSkwipt(Joiner.on(", ").join(keywords))); // Documentation ID String ID = info.getDocumentationID() != null ? info.getDocumentationID() : info.getId(); @@ -625,7 +625,7 @@ private String generateEvent(String descTemp, SkriptEventInfo info, @Nullable } desc = desc.replace("${element.events}", Joiner.on(", ").join(eventLinks)); } - desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join((events != null ? events.value() : null))); + desc = desc.replace("${element.events-safe}", events == null ? "" : introduceSkwipt(Joiner.on(", ").join((events != null ? events.value() : null)))); // Required Plugins String[] requiredPlugins = info.getRequiredPlugins(); @@ -707,7 +707,7 @@ private String generateClass(String descTemp, ClassInfo info, @Nullable Strin .replace("\\", "\\\\").replace("\"", "\\\"").replace("\t", " ")); Keywords keywords = c.getAnnotation(Keywords.class); - desc = desc.replace("${element.keywords}", keywords == null ? "" : Joiner.on(", ").join(keywords.value())); + desc = desc.replace("${element.keywords}", keywords == null ? "" : introduceSkwipt(Joiner.on(", ").join(keywords.value()))); // Documentation ID String ID = info.getDocumentationID() != null ? info.getDocumentationID() : info.getCodeName(); @@ -731,10 +731,10 @@ private String generateClass(String descTemp, ClassInfo info, @Nullable Strin } desc = desc.replace("${element.events}", Joiner.on(", ").join(eventLinks)); } - desc = desc.replace("${element.events-safe}", events == null ? "" : Joiner.on(", ").join((events != null ? events.value() : null))); + desc = desc.replace("${element.events-safe}", events == null ? "" : introduceSkwipt(Joiner.on(", ").join((events != null ? events.value() : null)))); // Required Plugins - String[] requiredPlugins = info.getRequiredPlugins(); + String[] requiredPlugins = introduceSkwipt(info.getRequiredPlugins()); desc = handleIf(desc, "${if required-plugins}", requiredPlugins != null); desc = desc.replace("${element.required-plugins}", Joiner.on(", ").join(requiredPlugins == null ? new String[0] : requiredPlugins)); @@ -912,7 +912,7 @@ public String getDefaultIfNullOrEmpty(@Nullable String string, String message) { } public String[] getDefaultIfNullOrEmpty(@Nullable String[] string, String message) { - return (string == null || string.length == 0 || string[0].equals("")) ? new String[]{ message } : string; // Null check first otherwise NullPointerException is thrown + return (string == null || string.length == 0 || "".equals(string[0]) ? new String[]{ introduceSkwipt(message) } : introduceSkwipt(string)); // Null check first otherwise NullPointerException is thrown } private String replaceReturnType(String desc, @Nullable ClassInfo returnType) { @@ -929,4 +929,15 @@ private String replaceReturnType(String desc, @Nullable ClassInfo returnType) return desc; } + public static String introduceSkwipt(String string) { + return string.replace('r', 'w').replace('l', 'w').replace("this", "dat"); + } + + public static String[] introduceSkwipt(String[] string) { + for (int i = 0; i < string.length; i++) { + string[i] = introduceSkwipt(string[i]); + } + return string; + } + }