diff --git a/android-sample/src/main/java/com/zachklipp/richtext/sample/LazyMarkdownSample.kt b/android-sample/src/main/java/com/zachklipp/richtext/sample/LazyMarkdownSample.kt index 463ffdfe..19be2b88 100644 --- a/android-sample/src/main/java/com/zachklipp/richtext/sample/LazyMarkdownSample.kt +++ b/android-sample/src/main/java/com/zachklipp/richtext/sample/LazyMarkdownSample.kt @@ -61,9 +61,10 @@ import com.halilibo.richtext.ui.resolveDefaults ) } LaunchedEffect(isAutolinkEnabled) { - markdownParseOptions = markdownParseOptions.copy( - autolink = isAutolinkEnabled - ) + markdownParseOptions = if (isAutolinkEnabled) + MarkdownParseOptions.MarkdownWithLinks + else + MarkdownParseOptions.MarkdownOnly } val colors = if (isDarkModeEnabled) darkColorScheme() else lightColorScheme() diff --git a/android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt b/android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt index fa3fb03d..6a08c235 100644 --- a/android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt +++ b/android-sample/src/main/java/com/zachklipp/richtext/sample/MarkdownSample.kt @@ -61,9 +61,10 @@ import com.halilibo.richtext.ui.resolveDefaults ) } LaunchedEffect(isAutolinkEnabled) { - markdownParseOptions = markdownParseOptions.copy( - autolink = isAutolinkEnabled - ) + markdownParseOptions = if (isAutolinkEnabled) + MarkdownParseOptions.MarkdownWithLinks + else + MarkdownParseOptions.MarkdownOnly } val colors = if (isDarkModeEnabled) darkColorScheme() else lightColorScheme() diff --git a/docs/richtext-commonmark.md b/docs/richtext-commonmark.md index fa149aae..8dc0451b 100644 --- a/docs/richtext-commonmark.md +++ b/docs/richtext-commonmark.md @@ -97,7 +97,11 @@ Passing `MarkdownParseOptions` into either `Markdown` composable or `CommonmarkA ```kotlin val markdownParseOptions = MarkdownParseOptions( - autolink = false + listOfNotNull( + TablesExtension.create(), + StrikethroughExtension.create(), + AutolinkExtension.create() + ) ) Markdown( diff --git a/richtext-commonmark/src/commonJvmAndroid/kotlin/com/halilibo/richtext/commonmark/AstNodeConvert.kt b/richtext-commonmark/src/commonJvmAndroid/kotlin/com/halilibo/richtext/commonmark/AstNodeConvert.kt index 7877270b..0208771d 100644 --- a/richtext-commonmark/src/commonJvmAndroid/kotlin/com/halilibo/richtext/commonmark/AstNodeConvert.kt +++ b/richtext-commonmark/src/commonJvmAndroid/kotlin/com/halilibo/richtext/commonmark/AstNodeConvert.kt @@ -187,13 +187,7 @@ public actual class CommonmarkAstNodeParser actual constructor( ) { private val parser = Parser.builder() - .extensions( - listOfNotNull( - TablesExtension.create(), - StrikethroughExtension.create(), - if (options.autolink) AutolinkExtension.create() else null - ) - ) + .extensions(options.extensions) .build() public actual fun parse(text: String): AstNode { diff --git a/richtext-commonmark/src/commonMain/kotlin/com/halilibo/richtext/commonmark/MarkdownParseOptions.kt b/richtext-commonmark/src/commonMain/kotlin/com/halilibo/richtext/commonmark/MarkdownParseOptions.kt index 30756823..ee5e6825 100644 --- a/richtext-commonmark/src/commonMain/kotlin/com/halilibo/richtext/commonmark/MarkdownParseOptions.kt +++ b/richtext-commonmark/src/commonMain/kotlin/com/halilibo/richtext/commonmark/MarkdownParseOptions.kt @@ -1,16 +1,32 @@ package com.halilibo.richtext.commonmark +import org.commonmark.Extension +import org.commonmark.ext.autolink.AutolinkExtension +import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension +import org.commonmark.ext.gfm.tables.TablesExtension + /** * Allows configuration of the Markdown parser * * @param autolink Detect plain text links and turn them into Markdown links. */ -public data class MarkdownParseOptions( - val autolink: Boolean -) { +public data class MarkdownParseOptions(val extensions: List) { public companion object { - public val Default: MarkdownParseOptions = MarkdownParseOptions( - autolink = true + public val MarkdownWithLinks: MarkdownParseOptions = MarkdownParseOptions( + listOfNotNull( + TablesExtension.create(), + StrikethroughExtension.create(), + AutolinkExtension.create() + ) + ) + + public val MarkdownOnly: MarkdownParseOptions = MarkdownParseOptions( + listOfNotNull( + TablesExtension.create(), + StrikethroughExtension.create() + ) ) + + public val Default: MarkdownParseOptions = MarkdownWithLinks } -} +} \ No newline at end of file