@@ -75,7 +75,7 @@ public TextNode[] parseNodes(TextNode input) {
7575 if (input instanceof LiteralNode literalNode ) {
7676 var list = new ArrayList <SubNode <?>>();
7777 parseLiteral (literalNode , list ::add );
78- return parseSubNodes (list .listIterator (), null , -1 , false );
78+ return parseSubNodes (list .listIterator (), null , -1 );
7979 } else if (input instanceof TranslatedNode translatedNode ) {
8080 return new TextNode []{ translatedNode .transform (this ) };
8181 } else if (input instanceof ParentTextNode parentTextNode ) {
@@ -87,7 +87,7 @@ public TextNode[] parseNodes(TextNode input) {
8787 list .add (new SubNode <>(SubNodeType .TEXT_NODE , TextNode .asSingle (parseNodes (children ))));
8888 }
8989 }
90- return new TextNode []{parentTextNode .copyWith (parseSubNodes (list .listIterator (), null , -1 , false ), this )};
90+ return new TextNode []{parentTextNode .copyWith (parseSubNodes (list .listIterator (), null , -1 ), this )};
9191 } else {
9292 return new TextNode []{input };
9393 }
@@ -101,9 +101,7 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
101101 var i = reader .read ();
102102 if (i == '\\' && reader .canRead ()) {
103103 var next = reader .read ();
104- //if (next != '~' && next != '`' && next != '_' && next != '*' && next != '|') {
105104 builder .append (i );
106- //}
107105 builder .append (next );
108106 continue ;
109107 }
@@ -129,7 +127,14 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
129127 type = switch (i ) {
130128 case '`' -> SubNodeType .BACK_TICK ;
131129 case '*' -> SubNodeType .STAR ;
132- case '_' -> SubNodeType .FLOOR ;
130+ case '_' -> {
131+ if (reader .getCursor () == 1 || !reader .canRead ()
132+ || Character .isWhitespace (reader .peek (-2 ))
133+ || Character .isWhitespace (reader .peek ())) {
134+ yield SubNodeType .FLOOR ;
135+ }
136+ yield null ;
137+ }
133138 case '(' -> SubNodeType .BRACKET_OPEN ;
134139 case ')' -> SubNodeType .BRACKET_CLOSE ;
135140 case '[' -> SubNodeType .SQR_BRACKET_OPEN ;
@@ -155,7 +160,7 @@ private void parseLiteral(LiteralNode literalNode, Consumer<SubNode<?>> consumer
155160 }
156161 }
157162
158- private TextNode [] parseSubNodes (ListIterator <SubNode <?>> nodes , @ Nullable SubNodeType endAt , int count , boolean requireEmpty ) {
163+ private TextNode [] parseSubNodes (ListIterator <SubNode <?>> nodes , @ Nullable SubNodeType endAt , int count ) {
159164 var out = new ArrayList <TextNode >();
160165 int startIndex = nodes .nextIndex ();
161166 var builder = new StringBuilder ();
@@ -165,16 +170,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
165170 if (next .type == endAt ) {
166171 int foundCount = 1 ;
167172
168- boolean endingOrSpace ;
169- if (requireEmpty && nodes .hasNext ()) {
170- var prev = nodes .next ();
171- endingOrSpace = prev .type != SubNodeType .STRING || ((String ) prev .value ).startsWith (" " );
172- nodes .previous ();
173- } else {
174- endingOrSpace = true ;
175- }
176-
177- if (foundCount == count && endingOrSpace ) {
173+ if (foundCount == count ) {
178174 if (!builder .isEmpty ()) {
179175 out .add (new LiteralNode (builder .toString ()));
180176 }
@@ -186,7 +182,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
186182 while (nodes .hasNext ()) {
187183 if (nodes .next ().type == endAt ) {
188184 if ((++foundCount ) == count ) {
189- if (requireEmpty && nodes .hasNext ()) {
185+ if (nodes .hasNext ()) {
190186 var prev = nodes .next ();
191187 nodes .previous ();
192188 if (prev .type == SubNodeType .STRING && !((String ) prev .value ).startsWith (" " )) {
@@ -220,7 +216,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
220216 builder .append ((String ) next .value );
221217 continue ;
222218 } else if (next .type == SubNodeType .BACK_TICK && this .allowedFormatting .contains (MarkdownFormat .QUOTE )) {
223- var value = parseSubNodes (nodes , next .type , 1 , false );
219+ var value = parseSubNodes (nodes , next .type , 1 );
224220
225221 if (value != null ) {
226222 if (!builder .isEmpty ()) {
@@ -231,7 +227,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
231227 continue ;
232228 }
233229 } else if (next .type == SubNodeType .SPOILER_LINE && this .allowedFormatting .contains (MarkdownFormat .SPOILER )) {
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 .DOUBLE_WAVY_LINE && this .allowedFormatting .contains (MarkdownFormat .STRIKETHROUGH )) {
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 ()) {
@@ -262,7 +258,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
262258 if (nexter .type == next .type ) {
263259 two = true ;
264260 var i = nodes .nextIndex ();
265- var value = parseSubNodes (nodes , next .type , 2 , false );
261+ var value = parseSubNodes (nodes , next .type , 2 );
266262
267263 if (value != null ) {
268264 if (!builder .isEmpty ()) {
@@ -288,7 +284,7 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
288284 }
289285
290286 if (startingOrSpace ) {
291- var value = parseSubNodes (nodes , next .type , 1 , next . type == SubNodeType . FLOOR );
287+ var value = parseSubNodes (nodes , next .type , 1 );
292288
293289 if (value != null ) {
294290 if (!builder .isEmpty ()) {
@@ -302,14 +298,14 @@ private TextNode[] parseSubNodes(ListIterator<SubNode<?>> nodes, @Nullable SubNo
302298 }
303299 } else if (next .type == SubNodeType .SQR_BRACKET_OPEN && this .allowedFormatting .contains (MarkdownFormat .URL ) && nodes .hasNext ()) {
304300 var start = nodes .nextIndex ();
305- var value = parseSubNodes (nodes , SubNodeType .SQR_BRACKET_CLOSE , 1 , false );
301+ var value = parseSubNodes (nodes , SubNodeType .SQR_BRACKET_CLOSE , 1 );
306302
307303 if (value != null ) {
308304 if (nodes .hasNext ()) {
309305 var check = nodes .next ().type == SubNodeType .BRACKET_OPEN ;
310306
311307 if (check ) {
312- var url = parseSubNodes (nodes , SubNodeType .BRACKET_CLOSE , 1 , false );
308+ var url = parseSubNodes (nodes , SubNodeType .BRACKET_CLOSE , 1 );
313309 if (url != null ) {
314310 if (!builder .isEmpty ()) {
315311 out .add (new LiteralNode (builder .toString ()));
0 commit comments