-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define delimited inlines extension API, implement strikethrough
This includes a bunch of changes to the Markdown inline APIs to better align with CommonMark and our actual needs; a clean-up of the previous half-hearted attempt at supporting custom inline nodes (it did not and could never have worked in the way it was implemented), and some misc tweaks and cleanup.
- Loading branch information
Showing
43 changed files
with
995 additions
and
290 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
2 changes: 2 additions & 0 deletions
2
...rm/jewel/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/WithInlineMarkdown.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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package org.jetbrains.jewel.markdown | ||
|
||
/** An inline Markdown node that contains other [InlineMarkdown] nodes. */ | ||
public interface WithInlineMarkdown { | ||
/** Child inline Markdown nodes. */ | ||
public val inlineContent: List<InlineMarkdown> | ||
} |
2 changes: 2 additions & 0 deletions
2
platform/jewel/markdown/core/src/main/kotlin/org/jetbrains/jewel/markdown/WithTextContent.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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package org.jetbrains.jewel.markdown | ||
|
||
/** An inline Markdown node that has a plain text content, or can be rendered as plain text. */ | ||
public interface WithTextContent { | ||
/** The plain text content or representation of this node. */ | ||
public val content: String | ||
} |
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
23 changes: 23 additions & 0 deletions
23
...tlin/org/jetbrains/jewel/markdown/extensions/MarkdownDelimitedInlineProcessorExtension.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,23 @@ | ||
package org.jetbrains.jewel.markdown.extensions | ||
|
||
import org.commonmark.node.Delimited | ||
import org.jetbrains.jewel.markdown.InlineMarkdown | ||
import org.jetbrains.jewel.markdown.processing.MarkdownProcessor | ||
|
||
/** An extension for parsing [org.commonmark.node.Delimited] inline nodes. */ | ||
public interface MarkdownDelimitedInlineProcessorExtension { | ||
/** Checks whether the [delimited] can be processed by this instance. */ | ||
public fun canProcess(delimited: Delimited): Boolean | ||
|
||
/** | ||
* Processes a [delimited] for which [canProcess] returned `true` into a [InlineMarkdown.CustomDelimitedNode]. | ||
* | ||
* @param delimited A [Delimited] produced by a [MarkdownProcessor]. | ||
* @param markdownProcessor The [MarkdownProcessor] to use to parse this [Delimited]. | ||
* @return The [InlineMarkdown.CustomDelimitedNode] obtained from [delimited]. | ||
*/ | ||
public fun processDelimitedInline( | ||
delimited: Delimited, | ||
markdownProcessor: MarkdownProcessor, | ||
): InlineMarkdown.CustomDelimitedNode | ||
} |
41 changes: 41 additions & 0 deletions
41
...otlin/org/jetbrains/jewel/markdown/extensions/MarkdownDelimitedInlineRendererExtension.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,41 @@ | ||
package org.jetbrains.jewel.markdown.extensions | ||
|
||
import androidx.compose.ui.text.AnnotatedString | ||
import org.jetbrains.jewel.markdown.InlineMarkdown | ||
import org.jetbrains.jewel.markdown.InlineMarkdown.CustomDelimitedNode | ||
import org.jetbrains.jewel.markdown.rendering.InlineMarkdownRenderer | ||
import org.jetbrains.jewel.markdown.rendering.InlinesStyling | ||
|
||
/** | ||
* An extension for [InlineMarkdownRenderer] that can render [InlineMarkdown.CustomDelimitedNode]s backed by a | ||
* [org.commonmark.node.Delimited] node. | ||
* | ||
* Only `Delimited` nodes that can be rendered as an [AnnotatedString] are supported; other kinds of inline node aren't. | ||
*/ | ||
public interface MarkdownDelimitedInlineRendererExtension { | ||
/** | ||
* Check whether the provided [node] node can be rendered by this extension. | ||
* | ||
* @param node The [CustomDelimitedNode] to check. | ||
* @return True if this instance can render [node], false otherwise. | ||
*/ | ||
public fun canRender(node: CustomDelimitedNode): Boolean | ||
|
||
/** | ||
* Render a [CustomDelimitedNode] into an [AnnotatedString.Builder]. Note that if [canRender] returns `false` for | ||
* [node], the implementation might throw. | ||
* | ||
* @param node The [CustomDelimitedNode] to render. | ||
* @param inlineRenderer The [InlineMarkdownRenderer] to use to render the node and its content. | ||
* @param inlinesStyling The styling to use to render the node and its content. | ||
* @param enabled When false, the node will be rendered with a disabled appearance (e.g., grayed out). | ||
* @param onUrlClicked Lambda that will be invoked when URLs inside this node are clicked. | ||
*/ | ||
public fun render( | ||
node: CustomDelimitedNode, | ||
inlineRenderer: InlineMarkdownRenderer, | ||
inlinesStyling: InlinesStyling, | ||
enabled: Boolean, | ||
onUrlClicked: ((String) -> Unit)?, | ||
): AnnotatedString | ||
} |
Oops, something went wrong.