@@ -16,13 +16,14 @@ private Code() {
1616 }
1717
1818 /**
19- * {@code code} marked as code, fenced by more backticks than any run it holds, padded if it starts or ends with one
19+ * {@code code} marked as code, fenced by more backticks than any run it holds, and padded with a space on each side
20+ * if it holds a backtick or starts or ends with a space, so {@link #render} can tell the padding from the code
2021 */
2122 public static String of (String code ) {
2223 String fence = "`" ;
2324 while (code .contains (fence ))
2425 fence += "`" ;
25- String pad = code .startsWith ("`" ) || code .endsWith ("` " ) ? " " : "" ;
26+ String pad = code .contains ("`" ) || code .startsWith ( " " ) || code . endsWith (" " ) ? " " : "" ;
2627 return fence + pad + code + pad + fence ;
2728 }
2829
@@ -38,11 +39,9 @@ static String render(String message, boolean colour) {
3839 StringBuilder rendered = new StringBuilder ();
3940 while (span .find ()) {
4041 String code = span .group (2 );
41- // the padding of() adds around code that starts or ends with a backtick, not spaces of the code
42- String inner = code .length () > 2 && code .startsWith (" " ) && code .endsWith (" " )
43- ? code .substring (1 , code .length () - 1 ) : code ;
44- if (inner .startsWith ("`" ) || inner .endsWith ("`" ))
45- code = inner ;
42+ // the padding of() adds: code with a space at both ends is always padded
43+ if (code .length () >= 2 && code .startsWith (" " ) && code .endsWith (" " ))
44+ code = code .substring (1 , code .length () - 1 );
4645 span .appendReplacement (rendered , Matcher .quoteReplacement (Colors .BLUE + code + Colors .RESET ));
4746 }
4847 span .appendTail (rendered );
0 commit comments