Handle spoiler tags

This commit is contained in:
Nassim Jahnke 2022-12-24 18:37:08 +01:00
parent be3ce10f4b
commit dc7641a17d
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B

View File

@ -30,8 +30,12 @@ public class BBCodeConverter {
REPLACERS.put("user", (tag, tagArg, content) -> content);
REPLACERS.put("list", (tag, tagArg, content) -> content);
REPLACERS.put("spoiler", (tag, tagArg, content) -> content); // disable till we figure out if we want to allow html, markdown doesnt support spoilers
REPLACERS.put("spoiler", (tag, tagArg, content) -> {
return "<details>\n" +
" <summary>" + removeQuotes(tagArg) + "</summary>\n" +
" " + content + "\n" +
"</details>\n";
});
REPLACERS.put("b", (tag, tagArg, content) -> "**" + content + "**");
REPLACERS.put("i", (tag, tagArg, content) -> "*" + content + "*");
REPLACERS.put("s", (tag, tagArg, content) -> "~~" + content + "~~");
@ -71,8 +75,8 @@ public class BBCodeConverter {
}
return "```" + lang + "\n"
+ content
+ "\n```";
+ content
+ "\n```";
}
@Override
@ -300,4 +304,14 @@ public class BBCodeConverter {
return false;
}
}
private static String removeQuotes(final String s) {
if (s.length() > 2) {
final char c = s.charAt(0);
if ((c == '\'' || c == '"') && c == s.charAt(s.length() - 1)) {
return s.substring(0, s.length() - 1);
}
}
return s;
}
}