diff --git a/app/src/main/kotlin/com/wire/android/ui/markdown/MarkdownHelper.kt b/app/src/main/kotlin/com/wire/android/ui/markdown/MarkdownHelper.kt index 895f44e367c..f45a04418cd 100644 --- a/app/src/main/kotlin/com/wire/android/ui/markdown/MarkdownHelper.kt +++ b/app/src/main/kotlin/com/wire/android/ui/markdown/MarkdownHelper.kt @@ -19,6 +19,7 @@ package com.wire.android.ui.markdown +import com.wire.android.appLogger import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toPersistentList import org.commonmark.ext.gfm.strikethrough.Strikethrough @@ -40,6 +41,7 @@ import org.commonmark.node.HtmlInline import org.commonmark.node.Image import org.commonmark.node.IndentedCodeBlock import org.commonmark.node.Link +import org.commonmark.node.LinkReferenceDefinition import org.commonmark.node.ListItem import org.commonmark.node.Node import org.commonmark.node.OrderedList @@ -89,7 +91,18 @@ fun T.toContent(isParentDocument: Boolean = false): MarkdownNode { is ThematicBreak -> MarkdownNode.Block.ThematicBreak(convertChildren(), isParentDocument) is Strikethrough -> MarkdownNode.Inline.Strikethrough(convertChildren()) is HardLineBreak, is SoftLineBreak -> MarkdownNode.Inline.Break(convertChildren()) - else -> throw IllegalArgumentException("Unsupported node type: ${this.javaClass.simpleName}") + is LinkReferenceDefinition -> MarkdownNode.Block.Paragraph( + listOf(MarkdownNode.Inline.Text("[$label]: $destination $title")), + isParentDocument + ) + + else -> { + appLogger.e( + "Unsupported markdown", + IllegalArgumentException("Unsupported node type: ${this.javaClass.simpleName}") + ) + MarkdownNode.Unsupported(isParentDocument = isParentDocument) + } } } @@ -167,6 +180,7 @@ fun MarkdownNode.filterNodesContainingQuery(query: String): MarkdownNode? { is MarkdownNode.Block.ThematicBreak -> null is MarkdownNode.Inline.Break -> this + is MarkdownNode.Unsupported -> null } } @@ -191,6 +205,7 @@ fun MarkdownNode.getFirstInlines(): MarkdownPreview? { is MarkdownNode.TableCell -> children.toPreview() is MarkdownNode.TableRow -> children.firstOrNull()?.children?.toPreview() + is MarkdownNode.Unsupported -> null } } @@ -307,6 +322,7 @@ private fun MarkdownNode.copy(children: List): MarkdownNode { // Custom nodes is MarkdownNode.TableRow -> this.copy(children = children.filterIsInstance()) is MarkdownNode.TableCell -> this.copy(children = children.filterIsInstance()) + is MarkdownNode.Unsupported -> this } } @@ -348,6 +364,7 @@ fun printMarkdownNodeTree(node: MarkdownNode?, indentLevel: Int = 0) { is MarkdownNode.Inline.Code -> "${indent}Code: '${node.literal}'" is MarkdownNode.Inline.Strikethrough -> "${indent}Strikethrough: [${node.children.size} children]" is MarkdownNode.Inline.Break -> "${indent}Break" + is MarkdownNode.Unsupported -> "${indent}Unsupported" } println(printLog) diff --git a/app/src/main/kotlin/com/wire/android/ui/markdown/MarkdownNode.kt b/app/src/main/kotlin/com/wire/android/ui/markdown/MarkdownNode.kt index 02453a8f0d0..d0d731214f1 100644 --- a/app/src/main/kotlin/com/wire/android/ui/markdown/MarkdownNode.kt +++ b/app/src/main/kotlin/com/wire/android/ui/markdown/MarkdownNode.kt @@ -143,6 +143,8 @@ sealed class MarkdownNode { override val children: List = listOf(), override val isParentDocument: Boolean = false ) : MarkdownNode() + + data class Unsupported(override val children: List = listOf(), override val isParentDocument: Boolean) : MarkdownNode() } data class MarkdownPreview(val children: PersistentList)