Remember descriptionAnnotator across composition
Closes mihonapp/mihon#2510 Co-authored-by: Cuong-Tran <16017808+cuong-tran@users.noreply.github.com> (cherry picked from commit 906d6f3cdbd6f7168d9cdea0c3eb8f9c663a09c2)
This commit is contained in:
parent
c525ce49af
commit
e3186b3db4
1 changed files with 34 additions and 31 deletions
|
|
@ -871,44 +871,47 @@ private fun ColumnScope.MangaContentInfo(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun descriptionAnnotator(loadImages: Boolean, linkStyle: SpanStyle) = markdownAnnotator(
|
@Composable
|
||||||
annotate = { content, child ->
|
private fun descriptionAnnotator(loadImages: Boolean, linkStyle: SpanStyle) = remember(loadImages, linkStyle) {
|
||||||
if (!loadImages && child.type == MarkdownElementTypes.IMAGE) {
|
markdownAnnotator(
|
||||||
val inlineLink = child.findChildOfType(MarkdownElementTypes.INLINE_LINK)
|
annotate = { content, child ->
|
||||||
|
if (!loadImages && child.type == MarkdownElementTypes.IMAGE) {
|
||||||
|
val inlineLink = child.findChildOfType(MarkdownElementTypes.INLINE_LINK)
|
||||||
|
|
||||||
val url = inlineLink?.findChildOfType(MarkdownElementTypes.LINK_DESTINATION)
|
val url = inlineLink?.findChildOfType(MarkdownElementTypes.LINK_DESTINATION)
|
||||||
?.getUnescapedTextInNode(content)
|
|
||||||
?: inlineLink?.findChildOfType(MarkdownElementTypes.AUTOLINK)
|
|
||||||
?.findChildOfType(MarkdownTokenTypes.AUTOLINK)
|
|
||||||
?.getUnescapedTextInNode(content)
|
?.getUnescapedTextInNode(content)
|
||||||
?: return@markdownAnnotator false
|
?: inlineLink?.findChildOfType(MarkdownElementTypes.AUTOLINK)
|
||||||
|
?.findChildOfType(MarkdownTokenTypes.AUTOLINK)
|
||||||
|
?.getUnescapedTextInNode(content)
|
||||||
|
?: return@markdownAnnotator false
|
||||||
|
|
||||||
val textNode = inlineLink?.findChildOfType(MarkdownElementTypes.LINK_TITLE)
|
val textNode = inlineLink?.findChildOfType(MarkdownElementTypes.LINK_TITLE)
|
||||||
?: inlineLink?.findChildOfType(MarkdownElementTypes.LINK_TEXT)
|
?: inlineLink?.findChildOfType(MarkdownElementTypes.LINK_TEXT)
|
||||||
val altText = textNode?.findChildOfType(MarkdownTokenTypes.TEXT)
|
val altText = textNode?.findChildOfType(MarkdownTokenTypes.TEXT)
|
||||||
?.getUnescapedTextInNode(content).orEmpty()
|
?.getUnescapedTextInNode(content).orEmpty()
|
||||||
|
|
||||||
withLink(LinkAnnotation.Url(url = url)) {
|
withLink(LinkAnnotation.Url(url = url)) {
|
||||||
pushStyle(linkStyle)
|
pushStyle(linkStyle)
|
||||||
appendInlineContent(MARKDOWN_INLINE_IMAGE_TAG)
|
appendInlineContent(MARKDOWN_INLINE_IMAGE_TAG)
|
||||||
append(altText)
|
append(altText)
|
||||||
pop()
|
pop()
|
||||||
|
}
|
||||||
|
|
||||||
|
return@markdownAnnotator true
|
||||||
}
|
}
|
||||||
|
|
||||||
return@markdownAnnotator true
|
if (child.type in DISALLOWED_MARKDOWN_TYPES) {
|
||||||
}
|
append(content.substring(child.startOffset, child.endOffset))
|
||||||
|
return@markdownAnnotator true
|
||||||
|
}
|
||||||
|
|
||||||
if (child.type in DISALLOWED_MARKDOWN_TYPES) {
|
false
|
||||||
append(content.substring(child.startOffset, child.endOffset))
|
},
|
||||||
return@markdownAnnotator true
|
config = markdownAnnotatorConfig(
|
||||||
}
|
eolAsNewLine = true,
|
||||||
|
),
|
||||||
false
|
)
|
||||||
},
|
}
|
||||||
config = markdownAnnotatorConfig(
|
|
||||||
eolAsNewLine = true,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun MangaSummary(
|
private fun MangaSummary(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue