-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nit: Change "toText" to "nestedLiteral" for more explicit intention
- Loading branch information
1 parent
0eb5c3d
commit e66bb22
Showing
2 changed files
with
22 additions
and
15 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
20 changes: 20 additions & 0 deletions
20
...xtensions/markdown/src/main/kotlin/com/varabyte/kobwebx/gradle/markdown/util/NodeUtils.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 com.varabyte.kobwebx.gradle.markdown.util | ||
|
||
import com.varabyte.kobwebx.gradle.markdown.children | ||
import org.commonmark.node.Code | ||
import org.commonmark.node.Node | ||
import org.commonmark.node.Text | ||
|
||
/** | ||
* Convert a [Node] to any literal value it contains. | ||
* | ||
* This is useful if you are pretty sure that a node contains some text but it might be deep down in its children. For | ||
* example, if a node represents a link, then the text value is contained as a child node. | ||
*/ | ||
internal val Node.nestedLiteral: String get() { | ||
return when (this) { | ||
is Text -> this.literal | ||
is Code -> this.literal | ||
else -> this.children().joinToString { it.nestedLiteral } | ||
} | ||
} |