Skip to content

Commit a409919

Browse files
committed
- add setting to consider EOL as a new line (by default false)
1 parent 468768a commit a409919

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatedStringKtx.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ fun AnnotatedString.Builder.buildMarkdownAnnotatedString(
205205
annotatorSettings: AnnotatorSettings,
206206
) {
207207
val annotate = annotatorSettings.annotator?.annotate
208+
val eolAsNewLine = annotatorSettings.eolAsNewLine
208209
var skipIfNext: Any? = null
209210
children.forEach { child ->
210211
if (skipIfNext == null || skipIfNext != child.type) {
@@ -273,7 +274,7 @@ fun AnnotatedString.Builder.buildMarkdownAnnotatedString(
273274
}
274275

275276
MarkdownTokenTypes.EMPH -> if (parentType != MarkdownElementTypes.EMPH && parentType != MarkdownElementTypes.STRONG) append('*')
276-
MarkdownTokenTypes.EOL -> append(' ')
277+
MarkdownTokenTypes.EOL -> if (eolAsNewLine) append('\n') else append(' ')
277278
MarkdownTokenTypes.WHITE_SPACE -> if (length > 0) append(' ')
278279
MarkdownTokenTypes.BLOCK_QUOTE -> {
279280
skipIfNext = MarkdownTokenTypes.WHITE_SPACE

multiplatform-markdown-renderer/src/commonMain/kotlin/com/mikepenz/markdown/annotator/AnnotatorSettings.kt

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.compose.ui.text.LinkAnnotation
99
import androidx.compose.ui.text.LinkInteractionListener
1010
import androidx.compose.ui.text.SpanStyle
1111
import androidx.compose.ui.text.TextLinkStyles
12-
import androidx.compose.ui.text.TextStyle
1312
import com.mikepenz.markdown.compose.LocalMarkdownAnnotator
1413
import com.mikepenz.markdown.compose.LocalMarkdownTypography
1514
import com.mikepenz.markdown.compose.LocalReferenceLinkHandler
@@ -33,6 +32,9 @@ interface AnnotatorSettings {
3332

3433
/** Represents the [LinkInteractionListener] used for links in this annotated string */
3534
val linkInteractionListener: LinkInteractionListener?
35+
36+
/** Defines if a EOL should be treated as a new line */
37+
val eolAsNewLine: Boolean
3638
}
3739

3840
@Immutable
@@ -42,16 +44,8 @@ class DefaultAnnotatorSettings(
4244
override val annotator: MarkdownAnnotator? = null,
4345
override val referenceLinkHandler: ReferenceLinkHandler? = null,
4446
override val linkInteractionListener: LinkInteractionListener? = null,
45-
) : AnnotatorSettings {
46-
constructor(
47-
style: TextStyle,
48-
linkTextSpanStyle: TextLinkStyles = TextLinkStyles(style = style.toSpanStyle()),
49-
codeSpanStyle: SpanStyle = style.toSpanStyle(),
50-
annotator: MarkdownAnnotator? = null,
51-
referenceLinkHandler: ReferenceLinkHandler? = null,
52-
linkInteractionListener: LinkInteractionListener? = null,
53-
) : this(linkTextSpanStyle, codeSpanStyle, annotator, referenceLinkHandler, linkInteractionListener)
54-
}
47+
override val eolAsNewLine: Boolean = false,
48+
) : AnnotatorSettings
5549

5650
@Composable
5751
fun annotatorSettings(
@@ -72,10 +66,12 @@ fun annotatorSettings(
7266
}
7367
}
7468
},
69+
eolAsNewLine: Boolean = false,
7570
): AnnotatorSettings = DefaultAnnotatorSettings(
7671
linkTextSpanStyle = linkTextSpanStyle,
7772
codeSpanStyle = codeSpanStyle,
7873
annotator = annotator,
7974
referenceLinkHandler = referenceLinkHandler,
8075
linkInteractionListener = linkInteractionListener,
76+
eolAsNewLine = eolAsNewLine,
8177
)

0 commit comments

Comments
 (0)