diff --git a/MIGRATION.md b/MIGRATION.md index 3db54f3d..697372c7 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -3,7 +3,10 @@ #### Version 0.39.0 - **Note**: The `highlights` library in v1.1.0 seems to be compiled with Java 21 -- **Note**: Some dependencies start to require minSDK: 23 (compared to the minSDK of 21 from before) +- **Breaking Change**: Some underlying APIs start to require API 23 instead of 21. + - `org.jetbrains.compose.components.resources` +- **Dependency Upgrade**: Kotlin 2.3.0 +- **Dependency Upgrade**: Compose 1.10.x #### Version 0.38.0 diff --git a/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt b/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt index 19cad76b..f54f0f6b 100644 --- a/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt +++ b/multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt @@ -24,6 +24,7 @@ import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes import org.intellij.markdown.ast.ASTNode import org.intellij.markdown.ast.findChildOfType +import org.intellij.markdown.ast.getTextInNode import org.intellij.markdown.flavours.MarkdownFlavourDescriptor import org.intellij.markdown.flavours.gfm.GFMElementTypes import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor @@ -295,6 +296,7 @@ fun AnnotatedString.Builder.buildMarkdownAnnotatedString( GFMTokenTypes.GFM_AUTOLINK -> if (child.parent == MarkdownElementTypes.LINK_TEXT) { append(child.getUnescapedTextInNode(content)) } else appendAutoLink(content, child, annotatorSettings) + GFMTokenTypes.DOLLAR -> append('$') MarkdownTokenTypes.SINGLE_QUOTE -> append('\'') @@ -313,12 +315,24 @@ fun AnnotatedString.Builder.buildMarkdownAnnotatedString( skipIfNext = MarkdownTokenTypes.EOL } - MarkdownTokenTypes.EMPH -> if (parentType != MarkdownElementTypes.EMPH && parentType != MarkdownElementTypes.STRONG) append('*') + MarkdownTokenTypes.EMPH -> { + if (parentType != MarkdownElementTypes.EMPH && parentType != MarkdownElementTypes.STRONG) { + append(child.getTextInNode(content)) + } + } + MarkdownTokenTypes.EOL -> if (eolAsNewLine) append('\n') else append(' ') MarkdownTokenTypes.WHITE_SPACE -> if (length > 0) append(' ') MarkdownTokenTypes.BLOCK_QUOTE -> { skipIfNext = MarkdownTokenTypes.WHITE_SPACE } + + else -> { + // `~` is not a specific `MarkdownTokenTypes` + if (child.type.name == "~" && parentType != GFMElementTypes.STRIKETHROUGH) { + append(child.getTextInNode(content)) + } + } } } } else { diff --git a/sample/android/src/screenshotTest/kotlin/com/mikepenz/markdown/ui/m2/SnapshotTests.kt b/sample/android/src/screenshotTest/kotlin/com/mikepenz/markdown/ui/m2/SnapshotTests.kt index 0946a35e..d932e738 100644 --- a/sample/android/src/screenshotTest/kotlin/com/mikepenz/markdown/ui/m2/SnapshotTests.kt +++ b/sample/android/src/screenshotTest/kotlin/com/mikepenz/markdown/ui/m2/SnapshotTests.kt @@ -31,6 +31,11 @@ class SnapshotTests { @Preview(showBackground = true, backgroundColor = Color.BLACK.toLong(), heightDp = 1500, uiMode = Configuration.UI_MODE_NIGHT_YES) @Composable fun TableTest() = TestMarkdown(MARKDOWN_TABLE) + + @Preview(showBackground = true, backgroundColor = Color.WHITE.toLong(), heightDp = 1500) + @Preview(showBackground = true, backgroundColor = Color.BLACK.toLong(), heightDp = 1500, uiMode = Configuration.UI_MODE_NIGHT_YES) + @Composable + fun InlineCodeTest() = TestMarkdown(MARKDOWN_INLINE_CODE) } @@ -228,4 +233,15 @@ private val MARKDOWN_LIST = """ * 7 * 8 * **Bold**: 9 +""".trimIndent() + +private val MARKDOWN_INLINE_CODE = """ +* Emphasis (`*`, `_`) +* It will be displayed as: Emphasis ( * , * ) + +* Strong emphasis (`**`, `__`) + +It will be displayed as: Strong emphasis ( ** , ** ) + +* Strike-through (`~~`) """.trimIndent() \ No newline at end of file diff --git a/sample/android/src/screenshotTest/kotlin/com/mikepenz/markdown/ui/m3/SnapshotTests.kt b/sample/android/src/screenshotTest/kotlin/com/mikepenz/markdown/ui/m3/SnapshotTests.kt index 8a0624ee..3d4d5539 100644 --- a/sample/android/src/screenshotTest/kotlin/com/mikepenz/markdown/ui/m3/SnapshotTests.kt +++ b/sample/android/src/screenshotTest/kotlin/com/mikepenz/markdown/ui/m3/SnapshotTests.kt @@ -31,6 +31,11 @@ class SnapshotTests { @Preview(showBackground = true, backgroundColor = Color.BLACK.toLong(), heightDp = 1500, uiMode = Configuration.UI_MODE_NIGHT_YES) @Composable fun TableTest() = TestMarkdown(MARKDOWN_TABLE) + + @Preview(showBackground = true, backgroundColor = Color.WHITE.toLong(), heightDp = 1500) + @Preview(showBackground = true, backgroundColor = Color.BLACK.toLong(), heightDp = 1500, uiMode = Configuration.UI_MODE_NIGHT_YES) + @Composable + fun InlineCodeTest() = TestMarkdown(MARKDOWN_INLINE_CODE) } @@ -228,4 +233,15 @@ private val MARKDOWN_LIST = """ * 7 * 8 * **Bold**: 9 +""".trimIndent() + +private val MARKDOWN_INLINE_CODE = """ +* Emphasis (`*`, `_`) +* It will be displayed as: Emphasis ( * , * ) + +* Strong emphasis (`**`, `__`) + +It will be displayed as: Strong emphasis ( ** , ** ) + +* Strike-through (`~~`) """.trimIndent() \ No newline at end of file