@Test public void createInline() { assertNoInline(createCursor("``one`")); assertNoInline(createCursor("two")); assertNoInline(createCursor("``")); assertNoInline(createCursor("`one``")); assertCode(14, "this is code", "`this is code`"); assertCode(12, "one\ntwo\n", "``one\ntwo\n``"); assertCode(14, "one *two", "```one *two```"); assertCode(14, "one *two` ", "``one *two` ``"); }
@Override public Optional<? extends Inline> createInline(Cursor cursor) { char c = cursor.getChar(); if (c == '`' && (!cursor.hasPrevious() || cursor.getPrevious() != '`')) { Matcher matcher = cursor.matcher(pattern); if (matcher.matches()) { String openingBackticks = matcher.group(1); int backtickCount = openingBackticks.length(); Pattern closingPattern = Pattern.compile("(?<!`)(" + Strings.repeat("`", backtickCount) + ")([^`]|$)", Pattern.DOTALL | Pattern.MULTILINE); cursor.advance(backtickCount); String textAtOffset = cursor.getTextAtOffset(); cursor.rewind(backtickCount); Matcher closingMatcher = closingPattern.matcher(textAtOffset); if (closingMatcher.find()) { String codeText = textAtOffset.substring(0, closingMatcher.start()); return Optional.of(new Code(cursor.getLineAtOffset(), cursor.getOffset(), backtickCount, codeText)); } } } return Optional.empty(); }
CodeSpan extends SourceSpan { @Override public Optional<? extends Inline> createInline(Cursor cursor) { char c = cursor.getChar(); if (c == '`' && (!cursor.hasPrevious() || cursor.getPrevious() != '`')) { Matcher matcher = cursor.matcher(pattern); if (matcher.matches()) { String openingBackticks = matcher.group(1); int backtickCount = openingBackticks.length(); Pattern closingPattern = Pattern.compile("(?<!`)(" + Strings.repeat("`", backtickCount) + ")([^`]|$)", Pattern.DOTALL | Pattern.MULTILINE); cursor.advance(backtickCount); String textAtOffset = cursor.getTextAtOffset(); cursor.rewind(backtickCount); Matcher closingMatcher = closingPattern.matcher(textAtOffset); if (closingMatcher.find()) { String codeText = textAtOffset.substring(0, closingMatcher.start()); return Optional.of(new Code(cursor.getLineAtOffset(), cursor.getOffset(), backtickCount, codeText)); } } } return Optional.empty(); } }
CodeSpan extends SourceSpan { @Override public Optional<? extends Inline> createInline(Cursor cursor) { char c = cursor.getChar(); if (c == '`' && (!cursor.hasPrevious() || cursor.getPrevious() != '`')) { Matcher matcher = cursor.matcher(pattern); if (matcher.matches()) { String openingBackticks = matcher.group(1); int backtickCount = openingBackticks.length(); Pattern closingPattern = Pattern.compile("(?<!`)(" + Strings.repeat("`", backtickCount) + ")([^`]|$)", Pattern.DOTALL | Pattern.MULTILINE); cursor.advance(backtickCount); String textAtOffset = cursor.getTextAtOffset(); cursor.rewind(backtickCount); Matcher closingMatcher = closingPattern.matcher(textAtOffset); if (closingMatcher.find()) { String codeText = textAtOffset.substring(0, closingMatcher.start()); return Optional.of(new Code(cursor.getLineAtOffset(), cursor.getOffset(), backtickCount, codeText)); } } } return Optional.empty(); }  }
CodeSpan extends SourceSpan { @Override public Optional<? extends Inline> createInline(Cursor cursor) { char c = cursor.getChar(); if (c == '`' && (!cursor.hasPrevious() || cursor.getPrevious() != '`')) { Matcher matcher = cursor.matcher(pattern); if (matcher.matches()) { String openingBackticks = matcher.group(1); int backtickCount = openingBackticks.length(); Pattern closingPattern = Pattern.compile("(?<!`)(" + Strings.repeat("`", backtickCount) + ")([^`]|$)", Pattern.DOTALL | Pattern.MULTILINE); cursor.advance(backtickCount); String textAtOffset = cursor.getTextAtOffset(); cursor.rewind(backtickCount); Matcher closingMatcher = closingPattern.matcher(textAtOffset); if (closingMatcher.find()) { String codeText = textAtOffset.substring(0, closingMatcher.start()); return Optional.of(new Code(cursor.getLineAtOffset(), cursor.getOffset(), backtickCount, codeText)); } } } return Optional.empty(); }  @Override Optional<? extends Inline> createInline(Cursor cursor); }
CodeSpan extends SourceSpan { @Override public Optional<? extends Inline> createInline(Cursor cursor) { char c = cursor.getChar(); if (c == '`' && (!cursor.hasPrevious() || cursor.getPrevious() != '`')) { Matcher matcher = cursor.matcher(pattern); if (matcher.matches()) { String openingBackticks = matcher.group(1); int backtickCount = openingBackticks.length(); Pattern closingPattern = Pattern.compile("(?<!`)(" + Strings.repeat("`", backtickCount) + ")([^`]|$)", Pattern.DOTALL | Pattern.MULTILINE); cursor.advance(backtickCount); String textAtOffset = cursor.getTextAtOffset(); cursor.rewind(backtickCount); Matcher closingMatcher = closingPattern.matcher(textAtOffset); if (closingMatcher.find()) { String codeText = textAtOffset.substring(0, closingMatcher.start()); return Optional.of(new Code(cursor.getLineAtOffset(), cursor.getOffset(), backtickCount, codeText)); } } } return Optional.empty(); }  @Override Optional<? extends Inline> createInline(Cursor cursor);  }