From bea6d6aeecdb1b55474aeb2497ec06babe4480c0 Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Fri, 26 Jun 2020 17:56:42 +0300 Subject: [PATCH] MakwonReducer filter out LinkReferenceDefinition --- CHANGELOG.md | 1 + .../java/io/noties/markwon/app/readme/ReadMeActivity.kt | 2 -- .../src/main/java/io/noties/markwon/MarkwonReducer.java | 7 ++++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be426a6e..b9a246ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * `inline-parser` - `BangInlineProcessor` properly returns `null` if no image node is found (possible to define other inline parsers that use `!` as special character) * `image` - `AsyncDrawable` won't trigger loading if it has result (aim: `RecyclerView` due to multiple attach/detach events of a View) * `image` - `AsyncDrawable` will resume result if it is `Animatable` and was playing before detach event (aim: `RecyclerView`) ([#241]) +* `core` - `MarkwonReducer` filter out `LinkReferenceDefinition` nodes #### Fixed * `image-glide` cache `RequestManager` in `GlideImagesPlugin#create(Context)` factory method ([#259]) diff --git a/app-sample/src/main/java/io/noties/markwon/app/readme/ReadMeActivity.kt b/app-sample/src/main/java/io/noties/markwon/app/readme/ReadMeActivity.kt index 3a5231f8..45143557 100644 --- a/app-sample/src/main/java/io/noties/markwon/app/readme/ReadMeActivity.kt +++ b/app-sample/src/main/java/io/noties/markwon/app/readme/ReadMeActivity.kt @@ -29,7 +29,6 @@ import io.noties.markwon.recycler.table.TableEntry import io.noties.markwon.recycler.table.TableEntryPlugin import io.noties.markwon.syntax.Prism4jThemeDefault import io.noties.markwon.syntax.SyntaxHighlightPlugin -import io.noties.markwon.utils.DumpNodes import io.noties.prism4j.Prism4j import io.noties.prism4j.annotations.PrismBundle import okhttp3.Call @@ -128,7 +127,6 @@ class ReadMeActivity : Activity() { is Result.Success -> { val markwon = markwon val node = markwon.parse(result.markdown) - Debug.i(DumpNodes.dump(node)) if (window != null) { recyclerView.post { adapter.setParsedMarkdown(markwon, node) diff --git a/markwon-core/src/main/java/io/noties/markwon/MarkwonReducer.java b/markwon-core/src/main/java/io/noties/markwon/MarkwonReducer.java index c54f8c2d..146b20e3 100644 --- a/markwon-core/src/main/java/io/noties/markwon/MarkwonReducer.java +++ b/markwon-core/src/main/java/io/noties/markwon/MarkwonReducer.java @@ -2,6 +2,7 @@ package io.noties.markwon; import androidx.annotation.NonNull; +import org.commonmark.node.LinkReferenceDefinition; import org.commonmark.node.Node; import java.util.ArrayList; @@ -48,7 +49,11 @@ public abstract class MarkwonReducer { Node temp; while (node != null) { - list.add(node); + // @since $nap; do not include LinkReferenceDefinition node (would result + // in empty textView if rendered in recycler-view) + if (!(node instanceof LinkReferenceDefinition)) { + list.add(node); + } temp = node.getNext(); node.unlink(); node = temp;