inline-parser, revert parsing index when processor returns null
This commit is contained in:
parent
949962ee0b
commit
5162c13bf7
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#### Changed
|
#### Changed
|
||||||
* `image-glide`: update to `4.11.0` version
|
* `image-glide`: update to `4.11.0` version
|
||||||
|
* `inline-parser`: revert parsing index when `InlineProcessor` returns `null` as result
|
||||||
|
|
||||||
# 4.5.1
|
# 4.5.1
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import io.noties.markwon.Markwon;
|
|||||||
import io.noties.markwon.MarkwonVisitor;
|
import io.noties.markwon.MarkwonVisitor;
|
||||||
import io.noties.markwon.app.sample.Tags;
|
import io.noties.markwon.app.sample.Tags;
|
||||||
import io.noties.markwon.app.sample.ui.MarkwonTextViewSample;
|
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.InlineProcessor;
|
||||||
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
|
import io.noties.markwon.inlineparser.MarkwonInlineParserPlugin;
|
||||||
import io.noties.markwon.sample.annotations.MarkwonArtifact;
|
import io.noties.markwon.sample.annotations.MarkwonArtifact;
|
||||||
@ -56,7 +57,7 @@ public class InlineParsingTooltipSample extends MarkwonTextViewSample {
|
|||||||
"# Hello tooltip!\n\n" +
|
"# Hello tooltip!\n\n" +
|
||||||
"This is the !{tooltip label}(and actual content comes here)\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" +
|
"what if it is !{here}(The contents can be blocks, limited though) instead?\n\n" +
|
||||||
" anyway";
|
" anyway";
|
||||||
|
|
||||||
final Markwon markwon = Markwon.builder(context)
|
final Markwon markwon = Markwon.builder(context)
|
||||||
.usePlugin(MarkwonInlineParserPlugin.create(factoryBuilder ->
|
.usePlugin(MarkwonInlineParserPlugin.create(factoryBuilder ->
|
||||||
@ -71,6 +72,7 @@ public class InlineParsingTooltipSample extends MarkwonTextViewSample {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.usePlugin(ImagesPlugin.create())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
markwon.setMarkdown(textView, md);
|
markwon.setMarkdown(textView, md);
|
||||||
|
@ -29,10 +29,6 @@ public class BangInlineProcessor extends InlineProcessor {
|
|||||||
|
|
||||||
return node;
|
return node;
|
||||||
} else {
|
} 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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,11 +266,18 @@ public class MarkwonInlineParser implements InlineParser, MarkwonInlineParserCon
|
|||||||
final List<InlineProcessor> inlines = this.inlineProcessors.get(c);
|
final List<InlineProcessor> inlines = this.inlineProcessors.get(c);
|
||||||
|
|
||||||
if (inlines != null) {
|
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) {
|
for (InlineProcessor inline : inlines) {
|
||||||
node = inline.parse(this);
|
node = inline.parse(this);
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset after each iteration (happens only when node is null)
|
||||||
|
index = startIndex;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final DelimiterProcessor delimiterProcessor = delimiterProcessors.get(c);
|
final DelimiterProcessor delimiterProcessor = delimiterProcessors.get(c);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user