Skip to content

Commit edfe0ef

Browse files
committed
Fix issue
1 parent b548d9a commit edfe0ef

4 files changed

Lines changed: 23 additions & 27 deletions

File tree

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: build
3333
run: ./gradlew build
3434
- name: capture build artifacts
35-
uses: actions/upload-artifact@v2
35+
uses: actions/upload-artifact@v4
3636
with:
3737
name: Artifacts
3838
path: build/libs/

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
MODRINTH: ${{ secrets.MODRINTH }}
3939
CHANGELOG: ${{ github.event.release.body }}
4040
- name: Upload GitHub release
41-
uses: AButler/upload-release-assets@v2.0
41+
uses: AButler/upload-release-assets@v3.0
4242
with:
4343
files: 'build/libs/*.jar;!build/libs/*-sources.jar;!build/libs/*-dev.jar'
4444
repo-token: ${{ secrets.GITHUB_TOKEN }}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1G
1111
fabric_version=0.89.0+1.20.2
1212

1313
# Mod Properties
14-
mod_version = 2.2.0+1.20.2
14+
mod_version = 2.2.1+1.20.2
1515
maven_group = eu.pb4
1616
archives_base_name = placeholder-api
1717

src/main/java/eu/pb4/placeholders/api/parsers/MarkdownLiteParserV1.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public TextNode[] parseNodes(TextNode input) {
7878
if (input instanceof LiteralNode literalNode) {
7979
var list = new ArrayList<SubNode<?>>();
8080
parseLiteral(literalNode, list::add);
81-
return parseSubNodes(list.listIterator(), null, -1, false);
81+
return parseSubNodes(list.listIterator(), null, -1);
8282
} else if (input instanceof TranslatedNode translatedNode) {
8383
var list = new ArrayList<>();
8484
for (var arg : translatedNode.args()) {
@@ -98,7 +98,7 @@ public TextNode[] parseNodes(TextNode input) {
9898
list.add(new SubNode<>(SubNodeType.TEXT_NODE, TextNode.asSingle(parseNodes(children))));
9999
}
100100
}
101-
return new TextNode[]{parentTextNode.copyWith(parseSubNodes(list.listIterator(), null, -1, false), this)};
101+
return new TextNode[]{parentTextNode.copyWith(parseSubNodes(list.listIterator(), null, -1), this)};
102102
} else {
103103
return new TextNode[]{input};
104104
}
@@ -112,9 +112,7 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
112112
var i = reader.read();
113113
if (i == '\\' && reader.canRead()) {
114114
var next = reader.read();
115-
//if (next != '~' && next != '`' && next != '_' && next != '*' && next != '|') {
116115
builder.append(i);
117-
//}
118116
builder.append(next);
119117
continue;
120118
}
@@ -140,7 +138,14 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
140138
type = switch (i) {
141139
case '`' -> SubNodeType.BACK_TICK;
142140
case '*' -> SubNodeType.STAR;
143-
case '_' -> SubNodeType.FLOOR;
141+
case '_' -> {
142+
if (reader.getCursor() == 1 || !reader.canRead()
143+
|| Character.isWhitespace(reader.peek(-2))
144+
|| Character.isWhitespace(reader.peek())) {
145+
yield SubNodeType.FLOOR;
146+
}
147+
yield null;
148+
}
144149
case '(' -> SubNodeType.BRACKET_OPEN;
145150
case ')' -> SubNodeType.BRACKET_CLOSE;
146151
case '[' -> SubNodeType.SQR_BRACKET_OPEN;
@@ -166,7 +171,7 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
166171
}
167172
}
168173

169-
private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNodeType endAt, int count, boolean requireEmpty) {
174+
private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNodeType endAt, int count) {
170175
var out = new ArrayList<TextNode>();
171176
int startIndex = nodes.nextIndex();
172177
var builder = new StringBuilder();
@@ -176,16 +181,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
176181
if (next.type == endAt) {
177182
int foundCount = 1;
178183

179-
boolean endingOrSpace;
180-
if (requireEmpty && nodes.hasNext()) {
181-
var prev = nodes.next();
182-
endingOrSpace = prev.type != SubNodeType.STRING || ((String) prev.value).startsWith(" ");
183-
nodes.previous();
184-
} else {
185-
endingOrSpace = true;
186-
}
187-
188-
if (foundCount == count && endingOrSpace) {
184+
if (foundCount == count) {
189185
if (!builder.isEmpty()) {
190186
out.add(new LiteralNode(builder.toString()));
191187
}
@@ -197,7 +193,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
197193
while (nodes.hasNext()) {
198194
if (nodes.next().type == endAt) {
199195
if ((++foundCount) == count) {
200-
if (requireEmpty && nodes.hasNext()) {
196+
if (nodes.hasNext()) {
201197
var prev = nodes.next();
202198
nodes.previous();
203199
if (prev.type == SubNodeType.STRING && !((String) prev.value).startsWith(" ")) {
@@ -231,7 +227,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
231227
builder.append((String) next.value);
232228
continue;
233229
} else if (next.type == SubNodeType.BACK_TICK && this.allowedFormatting.contains(MarkdownFormat.QUOTE)) {
234-
var value = parseSubNodes(nodes, next.type, 1, false);
230+
var value = parseSubNodes(nodes, next.type, 1);
235231

236232
if (value != null) {
237233
if (!builder.isEmpty()) {
@@ -242,7 +238,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
242238
continue;
243239
}
244240
} else if (next.type == SubNodeType.SPOILER_LINE && this.allowedFormatting.contains(MarkdownFormat.SPOILER)) {
245-
var value = parseSubNodes(nodes, next.type, 1, false);
241+
var value = parseSubNodes(nodes, next.type, 1);
246242

247243
if (value != null) {
248244
if (!builder.isEmpty()) {
@@ -253,7 +249,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
253249
continue;
254250
}
255251
} else if (next.type == SubNodeType.DOUBLE_WAVY_LINE && this.allowedFormatting.contains(MarkdownFormat.STRIKETHROUGH)) {
256-
var value = parseSubNodes(nodes, next.type, 1, false);
252+
var value = parseSubNodes(nodes, next.type, 1);
257253

258254
if (value != null) {
259255
if (!builder.isEmpty()) {
@@ -273,7 +269,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
273269
if (nexter.type == next.type) {
274270
two = true;
275271
var i = nodes.nextIndex();
276-
var value = parseSubNodes(nodes, next.type, 2, false);
272+
var value = parseSubNodes(nodes, next.type, 2);
277273

278274
if (value != null) {
279275
if (!builder.isEmpty()) {
@@ -299,7 +295,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
299295
}
300296

301297
if (startingOrSpace) {
302-
var value = parseSubNodes(nodes, next.type, 1, next.type == SubNodeType.FLOOR);
298+
var value = parseSubNodes(nodes, next.type, 1);
303299

304300
if (value != null) {
305301
if (!builder.isEmpty()) {
@@ -313,14 +309,14 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
313309
}
314310
} else if (next.type == SubNodeType.SQR_BRACKET_OPEN && this.allowedFormatting.contains(MarkdownFormat.URL) && nodes.hasNext()) {
315311
var start = nodes.nextIndex();
316-
var value = parseSubNodes(nodes, SubNodeType.SQR_BRACKET_CLOSE, 1, false);
312+
var value = parseSubNodes(nodes, SubNodeType.SQR_BRACKET_CLOSE, 1);
317313

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

322318
if (check) {
323-
var url = parseSubNodes(nodes, SubNodeType.BRACKET_CLOSE, 1, false);
319+
var url = parseSubNodes(nodes, SubNodeType.BRACKET_CLOSE, 1);
324320
if (url != null) {
325321
if (!builder.isEmpty()) {
326322
out.add(new LiteralNode(builder.toString()));

0 commit comments

Comments
 (0)