-
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.
Add an autolink extension for Markdown (#341)
Exposes the autolink extension offered by the commonmark java library, to markdown rendering in Compose. Since links are already supported for processing and rendering, we only need to hookup the parserExtension to get this to work.
- Loading branch information
Showing
10 changed files
with
85 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public final class org/jetbrains/jewel/markdown/extension/autolink/AutolinkProcessorExtension : org/jetbrains/jewel/markdown/extensions/MarkdownProcessorExtension { | ||
public static final field $stable I | ||
public static final field INSTANCE Lorg/jetbrains/jewel/markdown/extension/autolink/AutolinkProcessorExtension; | ||
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; | ||
} | ||
|
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.autolink) | ||
testImplementation(compose.desktop.uiTestJUnit4) | ||
} | ||
|
||
publishing.publications.named<MavenPublication>("main") { | ||
val ijpTarget = project.property("ijp.target") as String | ||
artifactId = "jewel-markdown-extension-${project.name}-$ijpTarget" | ||
} |
20 changes: 20 additions & 0 deletions
20
...main/kotlin/org/jetbrains/jewel/markdown/extension/autolink/AutolinkProcessorExtension.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.commonmark.ext.autolink.AutolinkExtension | ||
import org.commonmark.parser.Parser.ParserExtension | ||
import org.commonmark.renderer.text.TextContentRenderer | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownBlockProcessorExtension | ||
import org.jetbrains.jewel.markdown.extensions.MarkdownProcessorExtension | ||
|
||
public object AutolinkProcessorExtension : MarkdownProcessorExtension { | ||
override val parserExtension: ParserExtension | ||
get() = AutolinkExtension.create() as ParserExtension | ||
|
||
/** | ||
* Rendering and processing is already handled by [org.jetbrains.jewel.markdown.rendering.DefaultInlineMarkdownRenderer] | ||
*/ | ||
override val textRendererExtension: TextContentRenderer.TextContentRendererExtension? | ||
get() = null | ||
override val processorExtension: MarkdownBlockProcessorExtension? | ||
get() = null | ||
} |
20 changes: 20 additions & 0 deletions
20
.../kotlin/org/jetbrains/jewel/markdown/extension/autolink/AutolinkProcessorExtensionTest.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.InlineMarkdown | ||
import org.jetbrains.jewel.markdown.MarkdownBlock | ||
import org.jetbrains.jewel.markdown.processing.MarkdownProcessor | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
class AutolinkProcessorExtensionTest { | ||
// testing a simple case to assure wiring up our AutolinkProcessorExtension works correctly | ||
@Test | ||
fun `https text gets processed into a link`() { | ||
val processor = MarkdownProcessor(listOf(AutolinkProcessorExtension)) | ||
val rawMarkDown = "https://commonmark.org" | ||
val processed = processor.processMarkdownDocument(rawMarkDown) | ||
val paragraph = processed[0] as MarkdownBlock.Paragraph | ||
|
||
assertTrue(paragraph.inlineContent[0] is InlineMarkdown.Link) | ||
} | ||
} |
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