Showing with 21 additions and 25 deletions.
  1. +1 −1 gradle.properties
  2. +20 −24 src/main/java/eu/pb4/placeholders/api/parsers/MarkdownLiteParserV1.java
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1G
fabric_version=0.106.1+1.21.3

# Mod Properties
mod_version = 2.5.1+1.21.3
mod_version = 2.5.2+1.21.3
maven_group = eu.pb4
archives_base_name = placeholder-api

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public TextNode[] parseNodes(TextNode input) {
if (input instanceof LiteralNode literalNode) {
var list = new ArrayList<SubNode<?>>();
parseLiteral(literalNode, list::add);
return parseSubNodes(list.listIterator(), null, -1, false);
return parseSubNodes(list.listIterator(), null, -1);
} else if (input instanceof TranslatedNode translatedNode) {
return new TextNode[]{ translatedNode.transform(this) };
} else if (input instanceof ParentTextNode parentTextNode) {
Expand All @@ -87,7 +87,7 @@ public TextNode[] parseNodes(TextNode input) {
list.add(new SubNode<>(SubNodeType.TEXT_NODE, TextNode.asSingle(parseNodes(children))));
}
}
return new TextNode[]{parentTextNode.copyWith(parseSubNodes(list.listIterator(), null, -1, false), this)};
return new TextNode[]{parentTextNode.copyWith(parseSubNodes(list.listIterator(), null, -1), this)};
} else {
return new TextNode[]{input};
}
Expand All @@ -101,9 +101,7 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
var i = reader.read();
if (i == '\\' && reader.canRead()) {
var next = reader.read();
//if (next != '~' && next != '`' && next != '_' && next != '*' && next != '|') {
builder.append(i);
//}
builder.append(next);
continue;
}
Expand All @@ -129,7 +127,14 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
type = switch (i) {
case '`' -> SubNodeType.BACK_TICK;
case '*' -> SubNodeType.STAR;
case '_' -> SubNodeType.FLOOR;
case '_' -> {
if (reader.getCursor() == 1 || !reader.canRead()
|| Character.isWhitespace(reader.peek(-2))
|| Character.isWhitespace(reader.peek())) {
yield SubNodeType.FLOOR;
}
yield null;
}
case '(' -> SubNodeType.BRACKET_OPEN;
case ')' -> SubNodeType.BRACKET_CLOSE;
case '[' -> SubNodeType.SQR_BRACKET_OPEN;
Expand All @@ -155,7 +160,7 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
}
}

private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNodeType endAt, int count, boolean requireEmpty) {
private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNodeType endAt, int count) {
var out = new ArrayList<TextNode>();
int startIndex = nodes.nextIndex();
var builder = new StringBuilder();
Expand All @@ -165,16 +170,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
if (next.type == endAt) {
int foundCount = 1;

boolean endingOrSpace;
if (requireEmpty && nodes.hasNext()) {
var prev = nodes.next();
endingOrSpace = prev.type != SubNodeType.STRING || ((String) prev.value).startsWith(" ");
nodes.previous();
} else {
endingOrSpace = true;
}

if (foundCount == count && endingOrSpace) {
if (foundCount == count) {
if (!builder.isEmpty()) {
out.add(new LiteralNode(builder.toString()));
}
Expand All @@ -186,7 +182,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
while (nodes.hasNext()) {
if (nodes.next().type == endAt) {
if ((++foundCount) == count) {
if (requireEmpty && nodes.hasNext()) {
if (nodes.hasNext()) {
var prev = nodes.next();
nodes.previous();
if (prev.type == SubNodeType.STRING && !((String) prev.value).startsWith(" ")) {
Expand Down Expand Up @@ -220,7 +216,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
builder.append((String) next.value);
continue;
} else if (next.type == SubNodeType.BACK_TICK && this.allowedFormatting.contains(MarkdownFormat.QUOTE)) {
var value = parseSubNodes(nodes, next.type, 1, false);
var value = parseSubNodes(nodes, next.type, 1);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -231,7 +227,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
continue;
}
} else if (next.type == SubNodeType.SPOILER_LINE && this.allowedFormatting.contains(MarkdownFormat.SPOILER)) {
var value = parseSubNodes(nodes, next.type, 1, false);
var value = parseSubNodes(nodes, next.type, 1);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -242,7 +238,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
continue;
}
} else if (next.type == SubNodeType.DOUBLE_WAVY_LINE && this.allowedFormatting.contains(MarkdownFormat.STRIKETHROUGH)) {
var value = parseSubNodes(nodes, next.type, 1, false);
var value = parseSubNodes(nodes, next.type, 1);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -262,7 +258,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
if (nexter.type == next.type) {
two = true;
var i = nodes.nextIndex();
var value = parseSubNodes(nodes, next.type, 2, false);
var value = parseSubNodes(nodes, next.type, 2);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -288,7 +284,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
}

if (startingOrSpace) {
var value = parseSubNodes(nodes, next.type, 1, next.type == SubNodeType.FLOOR);
var value = parseSubNodes(nodes, next.type, 1);

if (value != null) {
if (!builder.isEmpty()) {
Expand All @@ -302,14 +298,14 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
}
} else if (next.type == SubNodeType.SQR_BRACKET_OPEN && this.allowedFormatting.contains(MarkdownFormat.URL) && nodes.hasNext()) {
var start = nodes.nextIndex();
var value = parseSubNodes(nodes, SubNodeType.SQR_BRACKET_CLOSE, 1, false);
var value = parseSubNodes(nodes, SubNodeType.SQR_BRACKET_CLOSE, 1);

if (value != null) {
if (nodes.hasNext()) {
var check = nodes.next().type == SubNodeType.BRACKET_OPEN;

if (check) {
var url = parseSubNodes(nodes, SubNodeType.BRACKET_CLOSE, 1, false);
var url = parseSubNodes(nodes, SubNodeType.BRACKET_CLOSE, 1);
if (url != null) {
if (!builder.isEmpty()) {
out.add(new LiteralNode(builder.toString()));
Expand Down