Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

import java.util.Collections;
import java.util.Set;
import java.util.regex.Pattern;
import org.commonmark.internal.util.Escaping;
import org.commonmark.node.HardLineBreak;
import org.commonmark.node.Text;
import org.commonmark.parser.beta.*;
import org.commonmark.text.AsciiMatcher;

/**
* Parse a backslash-escaped special character, adding either the escaped character, a hard line
Expand All @@ -15,7 +14,11 @@
*/
public class BackslashInlineParser implements InlineContentParser {

private static final Pattern ESCAPABLE = Pattern.compile('^' + Escaping.ESCAPABLE);
// The characters matched by Escaping.ESCAPABLE (ASCII punctuation)
private static final AsciiMatcher ESCAPABLE =
AsciiMatcher.builder()
.anyOf("!\"#$%&'()*+,./:;<=>?@[\\]^_`{|}~-")
.build();

@Override
public ParsedInline tryParse(InlineParserState inlineParserState) {
Expand All @@ -27,7 +30,7 @@ public ParsedInline tryParse(InlineParserState inlineParserState) {
if (next == '\n') {
scanner.next();
return ParsedInline.of(new HardLineBreak(), scanner.position());
} else if (ESCAPABLE.matcher(String.valueOf(next)).matches()) {
} else if (ESCAPABLE.matches(next)) {
scanner.next();
return ParsedInline.of(new Text(String.valueOf(next)), scanner.position());
} else {
Expand Down