@@ -28,6 +28,7 @@ import androidx.compose.ui.platform.LocalContext
2828import androidx.compose.ui.tooling.preview.Preview
2929import androidx.compose.ui.unit.dp
3030import com.halilibo.richtext.markdown.Markdown
31+ import com.halilibo.richtext.markdown.MarkdownParseOptions
3132import com.halilibo.richtext.ui.RichTextStyle
3233import com.halilibo.richtext.ui.material.MaterialRichText
3334import com.halilibo.richtext.ui.resolveDefaults
@@ -41,6 +42,8 @@ import com.halilibo.richtext.ui.resolveDefaults
4142 var richTextStyle by remember { mutableStateOf(RichTextStyle ().resolveDefaults()) }
4243 var isDarkModeEnabled by remember { mutableStateOf(false ) }
4344 var isWordWrapEnabled by remember { mutableStateOf(true ) }
45+ var markdownParseOptions by remember { mutableStateOf(MarkdownParseOptions .Default ) }
46+ var isAutolinkEnabled by remember { mutableStateOf(true ) }
4447
4548 LaunchedEffect (isWordWrapEnabled) {
4649 richTextStyle = richTextStyle.copy(
@@ -49,6 +52,11 @@ import com.halilibo.richtext.ui.resolveDefaults
4952 )
5053 )
5154 }
55+ LaunchedEffect (isAutolinkEnabled) {
56+ markdownParseOptions = markdownParseOptions.copy(
57+ autolink = isAutolinkEnabled
58+ )
59+ }
5260
5361 val colors = if (isDarkModeEnabled) darkColors() else lightColors()
5462 val context = LocalContext .current
@@ -75,6 +83,14 @@ import com.halilibo.richtext.ui.resolveDefaults
7583 label = " Word Wrap"
7684 )
7785
86+ CheckboxPreference (
87+ onClick = {
88+ isAutolinkEnabled = ! isAutolinkEnabled
89+ },
90+ checked = isAutolinkEnabled,
91+ label = " Autolink"
92+ )
93+
7894 RichTextStyleConfig (
7995 richTextStyle = richTextStyle,
8096 onChanged = { richTextStyle = it }
@@ -90,6 +106,7 @@ import com.halilibo.richtext.ui.resolveDefaults
90106 ) {
91107 Markdown (
92108 content = sampleMarkdown,
109+ markdownParseOptions = markdownParseOptions,
93110 onLinkClicked = {
94111 Toast .makeText(context, it, Toast .LENGTH_SHORT ).show()
95112 }
@@ -178,6 +195,8 @@ private val sampleMarkdown = """
178195 [You can use numbers for reference-style link definitions][1]
179196
180197 Or leave it empty and use the [link text itself].
198+
199+ Autolink option will detect text links like https://www.google.com and turn them into Markdown links automatically.
181200
182201 ---
183202
0 commit comments