-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
276 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
public final class org/jetbrains/jewel/markdown/extensions/tables/GitHubTableBlockRenderer : org/jetbrains/jewel/markdown/extensions/MarkdownBlockRendererExtension { | ||
public static final field $stable I | ||
public fun <init> (Lorg/jetbrains/jewel/markdown/extensions/tables/TableStyling;Lorg/jetbrains/jewel/markdown/rendering/MarkdownStyling;)V | ||
public fun canRender (Lorg/jetbrains/jewel/markdown/MarkdownBlock$CustomBlock;)Z | ||
public fun render (Lorg/jetbrains/jewel/markdown/MarkdownBlock$CustomBlock;Lorg/jetbrains/jewel/markdown/rendering/MarkdownBlockRenderer;Lorg/jetbrains/jewel/markdown/rendering/InlineMarkdownRenderer;Landroidx/compose/runtime/Composer;I)V | ||
} | ||
|
||
public final class org/jetbrains/jewel/markdown/extensions/tables/GitHubTableProcessorExtension : org/jetbrains/jewel/markdown/extensions/MarkdownProcessorExtension { | ||
public static final field $stable I | ||
public static final field INSTANCE Lorg/jetbrains/jewel/markdown/extensions/tables/GitHubTableProcessorExtension; | ||
public fun getParserExtension ()Lorg/commonmark/parser/Parser$ParserExtension; | ||
public fun getProcessorExtension ()Lorg/jetbrains/jewel/markdown/extensions/MarkdownBlockProcessorExtension; | ||
public fun getTextRendererExtension ()Lorg/commonmark/renderer/text/TextContentRenderer$TextContentRendererExtension; | ||
} | ||
|
||
public final class org/jetbrains/jewel/markdown/extensions/tables/GitHubTableRendererExtension : org/jetbrains/jewel/markdown/extensions/MarkdownRendererExtension { | ||
public static final field $stable I | ||
public fun <init> (Lorg/jetbrains/jewel/markdown/extensions/tables/TableStyling;Lorg/jetbrains/jewel/markdown/rendering/MarkdownStyling;)V | ||
public fun getBlockRenderer ()Lorg/jetbrains/jewel/markdown/extensions/MarkdownBlockRendererExtension; | ||
} | ||
|
||
public final class org/jetbrains/jewel/markdown/extensions/tables/TableStyling { | ||
public static final field $stable I | ||
public static final field Companion Lorg/jetbrains/jewel/markdown/extensions/tables/TableStyling$Companion; | ||
public synthetic fun <init> (JJLkotlin/jvm/internal/DefaultConstructorMarker;)V | ||
public fun equals (Ljava/lang/Object;)Z | ||
public final fun getBorderColor-0d7_KjU ()J | ||
public final fun getHeadColor-0d7_KjU ()J | ||
public fun hashCode ()I | ||
public fun toString ()Ljava/lang/String; | ||
} | ||
|
||
public final class org/jetbrains/jewel/markdown/extensions/tables/TableStyling$Companion { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
plugins { | ||
jewel | ||
`jewel-publish` | ||
`jewel-check-public-api` | ||
alias(libs.plugins.composeDesktop) | ||
} | ||
|
||
dependencies { | ||
implementation(projects.markdown.core) | ||
implementation(libs.commonmark.ext.gfm.tables) | ||
|
||
testImplementation(compose.desktop.uiTestJUnit4) | ||
} | ||
|
||
publicApiValidation { | ||
// TODO Oleg remove this once migrated to value classes | ||
excludedClassRegexes = setOf("org.jetbrains.jewel.markdown.extensions.github.alerts.*") | ||
} | ||
|
||
publishing.publications.named<MavenPublication>("main") { | ||
val ijpTarget = project.property("ijp.target") as String | ||
artifactId = "jewel-markdown-extension-${project.name}-$ijpTarget" | ||
} |
97 changes: 97 additions & 0 deletions
97
...rc/main/kotlin/org/jetbrains/jewel/markdown/extensions/tables/GitHubTableBlockRenderer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.jetbrains.jewel.markdown.extensions.tables | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import org.commonmark.ext.gfm.tables.TableBlock | ||
import org.commonmark.ext.gfm.tables.TableBody | ||
import org.commonmark.ext.gfm.tables.TableHead | ||
import org.commonmark.node.Node | ||
import org.jetbrains.jewel.markdown.InlineMarkdown | ||
import org.jetbrains.jewel.markdown.MarkdownBlock.CustomBlock | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownBlockRendererExtension | ||
import org.jetbrains.jewel.markdown.rendering.InlineMarkdownRenderer | ||
import org.jetbrains.jewel.markdown.rendering.MarkdownBlockRenderer | ||
import org.jetbrains.jewel.markdown.rendering.MarkdownStyling | ||
import org.jetbrains.jewel.markdown.toInlineNode | ||
import org.jetbrains.jewel.ui.component.Text | ||
|
||
public class GitHubTableBlockRenderer( | ||
private val styling: TableStyling, | ||
private val rootStyling: MarkdownStyling, | ||
) : MarkdownBlockRendererExtension { | ||
|
||
override fun canRender(block: CustomBlock): Boolean = | ||
block is CustomBlock.DefaultCustomBlock && block.nativeBlock is TableBlock | ||
|
||
@Composable | ||
private fun RowScope.TableCell( | ||
text: List<InlineMarkdown>, | ||
inlineRenderer: InlineMarkdownRenderer, | ||
) { | ||
Text( | ||
text = inlineRenderer.renderAsAnnotatedString(text, rootStyling.paragraph.inlinesStyling), | ||
Modifier | ||
.border(1.dp, styling.borderColor) | ||
.weight(1.0f) | ||
.padding(8.dp), | ||
) | ||
} | ||
|
||
@Composable | ||
override fun render( | ||
block: CustomBlock, | ||
blockRenderer: MarkdownBlockRenderer, | ||
inlineRenderer: InlineMarkdownRenderer, | ||
) { | ||
if (block !is CustomBlock.DefaultCustomBlock) return | ||
|
||
val head = block.nativeBlock.firstChild as TableHead | ||
val body = block.nativeBlock.lastChild as TableBody | ||
|
||
Column(Modifier.fillMaxSize().padding(16.dp)) { | ||
head.forEachChild { row -> | ||
Row(Modifier.background(styling.headColor)) { | ||
row.forEachChild { cell -> | ||
TableCell(text = cell.children().map { it.toInlineNode() }, inlineRenderer) | ||
} | ||
} | ||
} | ||
body.forEachChild { row -> | ||
Row(Modifier.fillMaxWidth()) { | ||
row.forEachChild { cell -> | ||
TableCell(text = cell.children().map { it.toInlineNode() }, inlineRenderer) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun Node.children(): List<Node> = buildList { | ||
var child = firstChild | ||
|
||
while (child != null) { | ||
add(child) | ||
child = child.next | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun Node.forEachChild(action: @Composable (Node) -> Unit) { | ||
var child = firstChild | ||
|
||
while (child != null) { | ||
action(child) | ||
child = child.next | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/kotlin/org/jetbrains/jewel/markdown/extensions/tables/GitHubTableProcessorExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.jetbrains.jewel.markdown.extensions.tables | ||
|
||
import org.commonmark.ext.gfm.tables.TablesExtension | ||
import org.commonmark.parser.Parser.ParserExtension | ||
import org.commonmark.renderer.text.TextContentRenderer.TextContentRendererExtension | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownProcessorExtension | ||
|
||
public object GitHubTableProcessorExtension : MarkdownProcessorExtension { | ||
|
||
override val parserExtension: ParserExtension = TablesExtension.create() as ParserExtension | ||
override val textRendererExtension: TextContentRendererExtension = TablesExtension.create() as TextContentRendererExtension | ||
} |
14 changes: 14 additions & 0 deletions
14
...ain/kotlin/org/jetbrains/jewel/markdown/extensions/tables/GitHubTableRendererExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.jetbrains.jewel.markdown.extensions.tables | ||
|
||
import org.jetbrains.jewel.markdown.extensions.MarkdownBlockRendererExtension | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownRendererExtension | ||
import org.jetbrains.jewel.markdown.rendering.MarkdownStyling | ||
|
||
public class GitHubTableRendererExtension( | ||
alertStyling: TableStyling, | ||
rootStyling: MarkdownStyling, | ||
) : MarkdownRendererExtension { | ||
|
||
override val blockRenderer: MarkdownBlockRendererExtension = | ||
GitHubTableBlockRenderer(alertStyling, rootStyling) | ||
} |
13 changes: 13 additions & 0 deletions
13
...gfm-tables/src/main/kotlin/org/jetbrains/jewel/markdown/extensions/tables/TableStyling.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jetbrains.jewel.markdown.extensions.tables | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import org.jetbrains.jewel.foundation.GenerateDataFunctions | ||
|
||
@GenerateDataFunctions | ||
public class TableStyling( | ||
public val headColor: Color, | ||
public val borderColor: Color, | ||
) { | ||
|
||
public companion object | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...tbrains/jewel/intui/markdown/styling/extension/github/alerts/GitHubTableDefaultStyling.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.jetbrains.jewel.intui.markdown.styling.extension.github.alerts | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import org.jetbrains.jewel.markdown.extensions.tables.TableStyling | ||
|
||
public fun TableStyling.Companion.dark( | ||
headColor: Color = Color.DarkGray, | ||
borderColor: Color = Color.Gray, | ||
): TableStyling = TableStyling( | ||
headColor, | ||
borderColor, | ||
) | ||
|
||
public fun TableStyling.Companion.light( | ||
headColor: Color = Color.LightGray, | ||
borderColor: Color = Color.Gray, | ||
): TableStyling = TableStyling( | ||
headColor, | ||
borderColor, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.