-
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
16 changed files
with
210 additions
and
13 deletions.
There are no files selected for viewing
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,29 @@ | ||
public final class org/jetbrains/jewel/markdown/extension/strikethrough/CustomStrikethroughNode : org/jetbrains/jewel/markdown/InlineMarkdown$CustomNode, org/jetbrains/jewel/markdown/WithInlineMarkdown { | ||
public static final field $stable I | ||
public fun <init> (Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)V | ||
public fun <init> (Lorg/commonmark/ext/gfm/strikethrough/Strikethrough;Lorg/jetbrains/jewel/markdown/processing/MarkdownProcessor;Ljava/util/List;)V | ||
public fun contentOrNull ()Ljava/lang/String; | ||
public fun equals (Ljava/lang/Object;)Z | ||
public final fun getClosingDelimiter ()Ljava/lang/String; | ||
public fun getInlineContent ()Ljava/util/List; | ||
public final fun getOpeningDelimiter ()Ljava/lang/String; | ||
public fun hashCode ()I | ||
public fun toString ()Ljava/lang/String; | ||
} | ||
|
||
public final class org/jetbrains/jewel/markdown/extension/strikethrough/StrikethroughProcessorExtension : org/jetbrains/jewel/markdown/extensions/MarkdownProcessorExtension { | ||
public static final field $stable I | ||
public static final field INSTANCE Lorg/jetbrains/jewel/markdown/extension/strikethrough/StrikethroughProcessorExtension; | ||
public fun getBlockProcessorExtension ()Lorg/jetbrains/jewel/markdown/extensions/MarkdownBlockProcessorExtension; | ||
public fun getInlineProcessorExtension ()Lorg/jetbrains/jewel/markdown/extensions/MarkdownInlineProcessorExtension; | ||
public fun getParserExtension ()Lorg/commonmark/parser/Parser$ParserExtension; | ||
public fun getTextRendererExtension ()Lorg/commonmark/renderer/text/TextContentRenderer$TextContentRendererExtension; | ||
} | ||
|
||
public final class org/jetbrains/jewel/markdown/extension/strikethrough/StrikethroughRendererExtension : org/jetbrains/jewel/markdown/extensions/MarkdownRendererExtension { | ||
public static final field $stable I | ||
public fun <init> (Lorg/jetbrains/jewel/markdown/rendering/InlinesStyling;)V | ||
public fun getBlockRenderer ()Lorg/jetbrains/jewel/markdown/extensions/MarkdownBlockRendererExtension; | ||
public fun getInlineRenderer ()Lorg/jetbrains/jewel/markdown/extensions/MarkdownInlineRendererExtension; | ||
} | ||
|
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,17 @@ | ||
plugins { | ||
jewel | ||
`jewel-publish` | ||
`jewel-check-public-api` | ||
alias(libs.plugins.composeDesktop) | ||
} | ||
|
||
dependencies { | ||
implementation(projects.markdown.core) | ||
implementation(libs.commonmark.ext.strikethrough) | ||
testImplementation(compose.desktop.uiTestJUnit4) | ||
} | ||
|
||
publishing.publications.named<MavenPublication>("main") { | ||
val ijpTarget = project.property("ijp.target") as String | ||
artifactId = "jewel-markdown-extension-${project.name}-$ijpTarget" | ||
} |
36 changes: 36 additions & 0 deletions
36
...in/kotlin/org/jetbrains/jewel/markdown/extension/strikethrough/CustomStrikethroughNode.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,36 @@ | ||
package org.jetbrains.jewel.markdown.extension.strikethrough | ||
|
||
import org.commonmark.ext.gfm.strikethrough.Strikethrough | ||
import org.commonmark.node.Node | ||
import org.jetbrains.jewel.foundation.GenerateDataFunctions | ||
import org.jetbrains.jewel.markdown.InlineMarkdown | ||
import org.jetbrains.jewel.markdown.WithInlineMarkdown | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownProcessorExtension | ||
import org.jetbrains.jewel.markdown.processing.MarkdownProcessor | ||
import org.jetbrains.jewel.markdown.processing.toInlineMarkdownOrNull | ||
|
||
@GenerateDataFunctions | ||
public class CustomStrikethroughNode( | ||
public val openingDelimiter: String, | ||
public val closingDelimiter: String, | ||
public override val inlineContent: List<InlineMarkdown>, | ||
) : InlineMarkdown.CustomNode, WithInlineMarkdown { | ||
public constructor( | ||
node: Strikethrough, | ||
markdownProcessor: MarkdownProcessor, | ||
extensions: List<MarkdownProcessorExtension>, | ||
) : this( | ||
node.openingDelimiter, | ||
node.closingDelimiter, | ||
node.children().mapNotNull { it.toInlineMarkdownOrNull(markdownProcessor, extensions) }, | ||
) | ||
} | ||
|
||
private fun Node.children() = | ||
buildList<Node> { | ||
var current = this@children.firstChild | ||
while (current != null) { | ||
this.add(current) | ||
current = current.next | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...n/org/jetbrains/jewel/markdown/extension/strikethrough/StrikethroughProcessorExtension.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,27 @@ | ||
package org.jetbrains.jewel.markdown.extension.strikethrough | ||
|
||
import org.commonmark.ext.gfm.strikethrough.Strikethrough | ||
import org.commonmark.ext.gfm.strikethrough.StrikethroughExtension | ||
import org.commonmark.node.CustomNode | ||
import org.commonmark.parser.Parser.ParserExtension | ||
import org.jetbrains.jewel.markdown.InlineMarkdown | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownInlineProcessorExtension | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownProcessorExtension | ||
import org.jetbrains.jewel.markdown.processing.MarkdownProcessor | ||
|
||
public object StrikethroughProcessorExtension : MarkdownProcessorExtension { | ||
override val parserExtension: ParserExtension = StrikethroughExtension.create() as ParserExtension | ||
|
||
override val inlineProcessorExtension: MarkdownInlineProcessorExtension | ||
get() = | ||
object : MarkdownInlineProcessorExtension { | ||
override fun canProcess(node: CustomNode): Boolean = node is Strikethrough | ||
|
||
override fun processInlineMarkdown( | ||
node: CustomNode, | ||
markdownProcessor: MarkdownProcessor, | ||
extensions: List<MarkdownProcessorExtension>, | ||
): InlineMarkdown.CustomNode = | ||
CustomStrikethroughNode(node as Strikethrough, markdownProcessor, extensions) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...in/org/jetbrains/jewel/markdown/extension/strikethrough/StrikethroughRendererExtension.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,36 @@ | ||
package org.jetbrains.jewel.markdown.extension.strikethrough | ||
|
||
import androidx.compose.ui.text.AnnotatedString.Builder | ||
import androidx.compose.ui.text.style.TextDecoration | ||
import androidx.compose.ui.text.withStyle | ||
import org.jetbrains.jewel.markdown.InlineMarkdown | ||
import org.jetbrains.jewel.markdown.WithInlineMarkdown | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownInlineRendererExtension | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownRendererExtension | ||
import org.jetbrains.jewel.markdown.rendering.InlineMarkdownRenderer | ||
import org.jetbrains.jewel.markdown.rendering.InlinesStyling | ||
|
||
public class StrikethroughRendererExtension(private val inlinesStyling: InlinesStyling) : MarkdownRendererExtension { | ||
override val inlineRenderer: MarkdownInlineRendererExtension | ||
get() = | ||
object : MarkdownInlineRendererExtension { | ||
override fun canRender(inline: InlineMarkdown.CustomNode): Boolean = inline is CustomStrikethroughNode | ||
|
||
override fun render( | ||
builder: Builder, | ||
inline: InlineMarkdown.CustomNode, | ||
inlineRenderer: InlineMarkdownRenderer, | ||
enabled: Boolean, | ||
) { | ||
val style = inlinesStyling.textStyle.copy(textDecoration = TextDecoration.LineThrough).toSpanStyle() | ||
builder.withStyle(style) { | ||
val inlineMarkdowns = (inline as? WithInlineMarkdown)?.inlineContent ?: emptyList() | ||
for (markdown in inlineMarkdowns) { | ||
append( | ||
inlineRenderer.renderAsAnnotatedString(listOf(markdown), inlinesStyling, enabled = true) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...in/org/jetbrains/jewel/markdown/extension/autolink/StrikethroughProcessorExtensionTest.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.markdown.extension.autolink | ||
|
||
import org.jetbrains.jewel.markdown.MarkdownBlock | ||
import org.jetbrains.jewel.markdown.extension.strikethrough.CustomStrikethroughNode | ||
import org.jetbrains.jewel.markdown.extension.strikethrough.StrikethroughProcessorExtension | ||
import org.jetbrains.jewel.markdown.processing.MarkdownProcessor | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class StrikethroughProcessorExtensionTest { | ||
// testing a simple case to assure wiring up our StrikethroughProcessorExtension works correctly | ||
@Test | ||
fun `~text~ processed into strikethrough`() { | ||
val processor = MarkdownProcessor(listOf(StrikethroughProcessorExtension)) | ||
val rawMarkDown = "~~text~~" | ||
val processed = processor.processMarkdownDocument(rawMarkDown) | ||
val paragraph = processed.first() as MarkdownBlock.Paragraph | ||
assertTrue(paragraph.inlineContent.first() is CustomStrikethroughNode) | ||
} | ||
} |
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