Skip to content

Commit da538a0

Browse files
authored
Merge pull request #449 from mikepenz/copilot/fix-439
Feat: Add top bar with language label and copy button for code blocks
2 parents 01f0696 + 7d98324 commit da538a0

File tree

11 files changed

+123
-21
lines changed

11 files changed

+123
-21
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,16 @@ Markdown(
444444
MarkdownHighlightedCodeBlock(
445445
content = it.content,
446446
node = it.node,
447-
highlightsBuilder = highlightsBuilder
447+
highlightsBuilder = highlightsBuilder,
448+
showHeader = true, // optional enable header with code language + copy button
448449
)
449450
},
450451
codeFence = {
451452
MarkdownHighlightedCodeFence(
452453
content = it.content,
453454
node = it.node,
454-
highlightsBuilder = highlightsBuilder
455+
highlightsBuilder = highlightsBuilder,
456+
showHeader = true, // optional enable header with code language + copy button
455457
)
456458
},
457459
)

multiplatform-markdown-renderer-code/api/android/multiplatform-markdown-renderer-code.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public final class com/mikepenz/markdown/compose/elements/ComposableSingletons$M
66
}
77

88
public final class com/mikepenz/markdown/compose/elements/MarkdownHighlightedCodeKt {
9-
public static final fun MarkdownHighlightedCode (Ljava/lang/String;Ljava/lang/String;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;Landroidx/compose/runtime/Composer;II)V
10-
public static final fun MarkdownHighlightedCodeBlock (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;Landroidx/compose/runtime/Composer;II)V
11-
public static final fun MarkdownHighlightedCodeFence (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;Landroidx/compose/runtime/Composer;II)V
9+
public static final fun MarkdownHighlightedCode (Ljava/lang/String;Ljava/lang/String;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;ZLandroidx/compose/runtime/Composer;II)V
10+
public static final fun MarkdownHighlightedCodeBlock (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;ZLandroidx/compose/runtime/Composer;II)V
11+
public static final fun MarkdownHighlightedCodeFence (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;ZLandroidx/compose/runtime/Composer;II)V
1212
public static final fun getHighlightedCodeBlock ()Lkotlin/jvm/functions/Function3;
1313
public static final fun getHighlightedCodeFence ()Lkotlin/jvm/functions/Function3;
1414
}

multiplatform-markdown-renderer-code/api/jvm/multiplatform-markdown-renderer-code.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public final class com/mikepenz/markdown/compose/elements/ComposableSingletons$M
66
}
77

88
public final class com/mikepenz/markdown/compose/elements/MarkdownHighlightedCodeKt {
9-
public static final fun MarkdownHighlightedCode (Ljava/lang/String;Ljava/lang/String;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;Landroidx/compose/runtime/Composer;II)V
10-
public static final fun MarkdownHighlightedCodeBlock (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;Landroidx/compose/runtime/Composer;II)V
11-
public static final fun MarkdownHighlightedCodeFence (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;Landroidx/compose/runtime/Composer;II)V
9+
public static final fun MarkdownHighlightedCode (Ljava/lang/String;Ljava/lang/String;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;ZLandroidx/compose/runtime/Composer;II)V
10+
public static final fun MarkdownHighlightedCodeBlock (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;ZLandroidx/compose/runtime/Composer;II)V
11+
public static final fun MarkdownHighlightedCodeFence (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Ldev/snipme/highlights/Highlights$Builder;ZLandroidx/compose/runtime/Composer;II)V
1212
public static final fun getHighlightedCodeBlock ()Lkotlin/jvm/functions/Function3;
1313
public static final fun getHighlightedCodeFence ()Lkotlin/jvm/functions/Function3;
1414
}

multiplatform-markdown-renderer-code/api/multiplatform-markdown-renderer-code.klib.api

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ final val com.mikepenz.markdown.compose.elements/highlightedCodeBlock // com.mik
1111
final val com.mikepenz.markdown.compose.elements/highlightedCodeFence // com.mikepenz.markdown.compose.elements/highlightedCodeFence|{}highlightedCodeFence[0]
1212
final fun <get-highlightedCodeFence>(): kotlin/Function3<com.mikepenz.markdown.compose.components/MarkdownComponentModel, androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit> // com.mikepenz.markdown.compose.elements/highlightedCodeFence.<get-highlightedCodeFence>|<get-highlightedCodeFence>(){}[0]
1313

14-
final fun com.mikepenz.markdown.compose.elements/MarkdownHighlightedCode(kotlin/String, kotlin/String?, androidx.compose.ui.text/TextStyle?, dev.snipme.highlights/Highlights.Builder?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownHighlightedCode|MarkdownHighlightedCode(kotlin.String;kotlin.String?;androidx.compose.ui.text.TextStyle?;dev.snipme.highlights.Highlights.Builder?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
15-
final fun com.mikepenz.markdown.compose.elements/MarkdownHighlightedCodeBlock(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle?, dev.snipme.highlights/Highlights.Builder?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownHighlightedCodeBlock|MarkdownHighlightedCodeBlock(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle?;dev.snipme.highlights.Highlights.Builder?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
16-
final fun com.mikepenz.markdown.compose.elements/MarkdownHighlightedCodeFence(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle?, dev.snipme.highlights/Highlights.Builder?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownHighlightedCodeFence|MarkdownHighlightedCodeFence(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle?;dev.snipme.highlights.Highlights.Builder?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
14+
final fun com.mikepenz.markdown.compose.elements/MarkdownHighlightedCode(kotlin/String, kotlin/String?, androidx.compose.ui.text/TextStyle?, dev.snipme.highlights/Highlights.Builder?, kotlin/Boolean, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownHighlightedCode|MarkdownHighlightedCode(kotlin.String;kotlin.String?;androidx.compose.ui.text.TextStyle?;dev.snipme.highlights.Highlights.Builder?;kotlin.Boolean;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
15+
final fun com.mikepenz.markdown.compose.elements/MarkdownHighlightedCodeBlock(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle?, dev.snipme.highlights/Highlights.Builder?, kotlin/Boolean, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownHighlightedCodeBlock|MarkdownHighlightedCodeBlock(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle?;dev.snipme.highlights.Highlights.Builder?;kotlin.Boolean;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
16+
final fun com.mikepenz.markdown.compose.elements/MarkdownHighlightedCodeFence(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle?, dev.snipme.highlights/Highlights.Builder?, kotlin/Boolean, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownHighlightedCodeFence|MarkdownHighlightedCodeFence(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle?;dev.snipme.highlights.Highlights.Builder?;kotlin.Boolean;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]

multiplatform-markdown-renderer-code/src/commonMain/kotlin/com/mikepenz/markdown/compose/elements/MarkdownHighlightedCode.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ fun MarkdownHighlightedCodeFence(
5050
node: ASTNode,
5151
style: TextStyle = LocalMarkdownTypography.current.code,
5252
highlightsBuilder: Highlights.Builder = rememberHighlightsBuilder(),
53+
showHeader: Boolean = false,
5354
) {
5455
MarkdownCodeFence(content, node, style) { code, language, style ->
5556
MarkdownHighlightedCode(
5657
code = code,
5758
language = language,
5859
style = style,
5960
highlightsBuilder = highlightsBuilder,
61+
showHeader = showHeader,
6062
)
6163
}
6264
}
@@ -67,13 +69,15 @@ fun MarkdownHighlightedCodeBlock(
6769
node: ASTNode,
6870
style: TextStyle = LocalMarkdownTypography.current.code,
6971
highlightsBuilder: Highlights.Builder = rememberHighlightsBuilder(),
72+
showHeader: Boolean = false,
7073
) {
7174
MarkdownCodeBlock(content, node, style) { code, language, style ->
7275
MarkdownHighlightedCode(
7376
code = code,
7477
language = language,
7578
style = style,
7679
highlightsBuilder = highlightsBuilder,
80+
showHeader = showHeader,
7781
)
7882
}
7983
}
@@ -84,6 +88,7 @@ fun MarkdownHighlightedCode(
8488
language: String?,
8589
style: TextStyle = LocalMarkdownTypography.current.code,
8690
highlightsBuilder: Highlights.Builder = rememberHighlightsBuilder(),
91+
showHeader: Boolean = false,
8792
) {
8893
val backgroundCodeColor = LocalMarkdownColors.current.codeBackground
8994
val codeBackgroundCornerSize = LocalMarkdownDimens.current.codeBackgroundCornerSize
@@ -97,7 +102,10 @@ fun MarkdownHighlightedCode(
97102
MarkdownCodeBackground(
98103
color = backgroundCodeColor,
99104
shape = RoundedCornerShape(codeBackgroundCornerSize),
100-
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp)
105+
modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp),
106+
showHeader = showHeader,
107+
language = language,
108+
code = code
101109
) {
102110
@Suppress("DEPRECATION")
103111
MarkdownBasicText(

multiplatform-markdown-renderer/api/android/multiplatform-markdown-renderer.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public final class com/mikepenz/markdown/compose/elements/MarkdownCheckBoxKt {
188188
}
189189

190190
public final class com/mikepenz/markdown/compose/elements/MarkdownCodeKt {
191-
public static final fun MarkdownCodeBackground-xzXfpvY (JLandroidx/compose/ui/Modifier;Landroidx/compose/ui/graphics/Shape;Landroidx/compose/foundation/BorderStroke;FLkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
191+
public static final fun MarkdownCodeBackground-ymN66Js (JLandroidx/compose/ui/Modifier;Landroidx/compose/ui/graphics/Shape;Landroidx/compose/foundation/BorderStroke;FZLjava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
192192
public static final fun MarkdownCodeBlock (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V
193193
public static final fun MarkdownCodeFence (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V
194194
}

multiplatform-markdown-renderer/api/jvm/multiplatform-markdown-renderer.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public final class com/mikepenz/markdown/compose/elements/MarkdownCheckBoxKt {
188188
}
189189

190190
public final class com/mikepenz/markdown/compose/elements/MarkdownCodeKt {
191-
public static final fun MarkdownCodeBackground-xzXfpvY (JLandroidx/compose/ui/Modifier;Landroidx/compose/ui/graphics/Shape;Landroidx/compose/foundation/BorderStroke;FLkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
191+
public static final fun MarkdownCodeBackground-ymN66Js (JLandroidx/compose/ui/Modifier;Landroidx/compose/ui/graphics/Shape;Landroidx/compose/foundation/BorderStroke;FZLjava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Landroidx/compose/runtime/Composer;II)V
192192
public static final fun MarkdownCodeBlock (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V
193193
public static final fun MarkdownCodeFence (Ljava/lang/String;Lorg/intellij/markdown/ast/ASTNode;Landroidx/compose/ui/text/TextStyle;Lkotlin/jvm/functions/Function5;Landroidx/compose/runtime/Composer;II)V
194194
}

multiplatform-markdown-renderer/api/multiplatform-markdown-renderer.klib.api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ final fun com.mikepenz.markdown.compose.elements.material/MarkdownBasicText(andr
753753
final fun com.mikepenz.markdown.compose.elements/MarkdownBlockQuote(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownBlockQuote|MarkdownBlockQuote(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
754754
final fun com.mikepenz.markdown.compose.elements/MarkdownBulletList(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle?, kotlin/Int, kotlin/Function1<androidx.compose.foundation.layout/RowScope, androidx.compose.ui/Modifier>?, kotlin/Function1<androidx.compose.foundation.layout/RowScope, androidx.compose.ui/Modifier>?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownBulletList|MarkdownBulletList(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle?;kotlin.Int;kotlin.Function1<androidx.compose.foundation.layout.RowScope,androidx.compose.ui.Modifier>?;kotlin.Function1<androidx.compose.foundation.layout.RowScope,androidx.compose.ui.Modifier>?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
755755
final fun com.mikepenz.markdown.compose.elements/MarkdownCheckBox(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle, kotlin/Function4<kotlin/Boolean, androidx.compose.ui/Modifier, androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownCheckBox|MarkdownCheckBox(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle;kotlin.Function4<kotlin.Boolean,androidx.compose.ui.Modifier,androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
756-
final fun com.mikepenz.markdown.compose.elements/MarkdownCodeBackground(androidx.compose.ui.graphics/Color, androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Shape?, androidx.compose.foundation/BorderStroke?, androidx.compose.ui.unit/Dp, kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownCodeBackground|MarkdownCodeBackground(androidx.compose.ui.graphics.Color;androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Shape?;androidx.compose.foundation.BorderStroke?;androidx.compose.ui.unit.Dp;kotlin.Function2<androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
756+
final fun com.mikepenz.markdown.compose.elements/MarkdownCodeBackground(androidx.compose.ui.graphics/Color, androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Shape?, androidx.compose.foundation/BorderStroke?, androidx.compose.ui.unit/Dp, kotlin/Boolean, kotlin/String?, kotlin/String?, kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownCodeBackground|MarkdownCodeBackground(androidx.compose.ui.graphics.Color;androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Shape?;androidx.compose.foundation.BorderStroke?;androidx.compose.ui.unit.Dp;kotlin.Boolean;kotlin.String?;kotlin.String?;kotlin.Function2<androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
757757
final fun com.mikepenz.markdown.compose.elements/MarkdownCodeBlock(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle?, kotlin/Function5<kotlin/String, kotlin/String?, androidx.compose.ui.text/TextStyle, androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownCodeBlock|MarkdownCodeBlock(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle?;kotlin.Function5<kotlin.String,kotlin.String?,androidx.compose.ui.text.TextStyle,androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
758758
final fun com.mikepenz.markdown.compose.elements/MarkdownCodeFence(kotlin/String, org.intellij.markdown.ast/ASTNode, androidx.compose.ui.text/TextStyle?, kotlin/Function5<kotlin/String, kotlin/String?, androidx.compose.ui.text/TextStyle, androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownCodeFence|MarkdownCodeFence(kotlin.String;org.intellij.markdown.ast.ASTNode;androidx.compose.ui.text.TextStyle?;kotlin.Function5<kotlin.String,kotlin.String?,androidx.compose.ui.text.TextStyle,androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
759759
final fun com.mikepenz.markdown.compose.elements/MarkdownDivider(androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Color, androidx.compose.ui.unit/Dp, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mikepenz.markdown.compose.elements/MarkdownDivider|MarkdownDivider(androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Color;androidx.compose.ui.unit.Dp;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]

0 commit comments

Comments
 (0)