inline-parser, revert parsing index when processor returns null
This commit is contained in:
parent
949962ee0b
commit
5162c13bf7
CHANGELOG.md
app-sample/src/main/java/io/noties/markwon/app/samples/inlineparsing
markwon-inline-parser/src/main/java/io/noties/markwon/inlineparser
@ -4,6 +4,7 @@
|
||||
|
||||
#### Changed
|
||||
* `image-glide`: update to `4.11.0` version
|
||||
* `inline-parser`: revert parsing index when `InlineProcessor` returns `null` as result
|
||||
|
||||
# 4.5.1
|
||||
|
||||
|
4
app-sample/src/main/java/io/noties/markwon/app/samples/inlineparsing/InlineParsingTooltipSample.java
4
app-sample/src/main/java/io/noties/markwon/app/samples/inlineparsing/InlineParsingTooltipSample.java
@ -26,6 +26,7 @@ import io.noties.markwon.Markwon;
|
||||
import io.noties.markwon.MarkwonVisitor;
|
||||
import io.noties.markwon.app.sample.Tags;
|
||||
import io.noties.markwon.app.sample.ui.MarkwonTextViewSample;
|
||||
import io.noties.markwon.image.ImagesPlugin;
|
||||
import io.noties.markwon.inlineparser.InlineProcessor;
|
||||
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
|
||||
import io.noties.markwon.sample.annotations.MarkwonArtifact;
|
||||
@ -56,7 +57,7 @@ public class InlineParsingTooltipSample extends MarkwonTextViewSample {
|
||||
"# Hello tooltip!\n\n" +
|
||||
"This is the !{tooltip label}(and actual content comes here)\n\n" +
|
||||
"what if it is !{here}(The contents can be blocks, limited though) instead?\n\n" +
|
||||
" anyway";
|
||||
" anyway";
|
||||
|
||||
final Markwon markwon = Markwon.builder(context)
|
||||
.usePlugin(MarkwonInlineParserPlugin.create(factoryBuilder ->
|
||||
@ -71,6 +72,7 @@ public class InlineParsingTooltipSample extends MarkwonTextViewSample {
|
||||
});
|
||||
}
|
||||
})
|
||||
.usePlugin(ImagesPlugin.create())
|
||||
.build();
|
||||
|
||||
markwon.setMarkdown(textView, md);
|
||||
|
@ -29,10 +29,6 @@ public class BangInlineProcessor extends InlineProcessor {
|
||||
|
||||
return node;
|
||||
} else {
|
||||
// @since 4.5.0 return null in case no match (multiple inline
|
||||
// processors can define `!` as _special_ character, so let them handle it)
|
||||
// NB! do not forget to reset index
|
||||
index = startIndex;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -266,11 +266,18 @@ public class MarkwonInlineParser implements InlineParser, MarkwonInlineParserCon
|
||||
final List<InlineProcessor> inlines = this.inlineProcessors.get(c);
|
||||
|
||||
if (inlines != null) {
|
||||
// @since $SNAPSHOT; index must not be advanced if inline-processor returned null
|
||||
// so, further processors can be called at the _same_ position (and thus char)
|
||||
final int startIndex = index;
|
||||
|
||||
for (InlineProcessor inline : inlines) {
|
||||
node = inline.parse(this);
|
||||
if (node != null) {
|
||||
break;
|
||||
}
|
||||
|
||||
// reset after each iteration (happens only when node is null)
|
||||
index = startIndex;
|
||||
}
|
||||
} else {
|
||||
final DelimiterProcessor delimiterProcessor = delimiterProcessors.get(c);
|
||||
|
Loading…
x
Reference in New Issue
Block a user