Skip to content

Commit

Permalink
Fix handling of multiple nodes in list item
Browse files Browse the repository at this point in the history
  • Loading branch information
JojOatXGME committed Apr 22, 2023
1 parent 6c9239e commit 8847823
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/main/kotlin/org/jetbrains/changelog/Changelog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ data class Changelog(
HTML,
}

private fun ASTNode?.textAsIs(customContent: String? = null) = this
?.getTextInNode(customContent ?: content)
?.let {
when (type) {
EOL -> lineSeparator
else -> it
}
}
?.toString()
.orEmpty()

private fun ASTNode?.text(customContent: String? = null) = this
?.getTextInNode(customContent ?: content)
?.let {
Expand Down Expand Up @@ -431,7 +442,11 @@ data class Changelog(
.flatMap { list ->
list.children
.filter { it.type == org.intellij.markdown.MarkdownElementTypes.LIST_ITEM }
.map { it.children.last().text(content) }
.map { listItem ->
listItem.children
.drop(1) // MarkdownTokenTypes.LIST_BULLET or LIST_NUMBER
.joinToString("") { it.textAsIs(content) }
}
.toSet()
}
.toSet()
Expand All @@ -445,7 +460,11 @@ data class Changelog(
.associate { (left, right) ->
left.text(content) to right.children
.filter { it.type == org.intellij.markdown.MarkdownElementTypes.LIST_ITEM }
.map { it.children.last().text(content) }
.map { listItem ->
listItem.children
.drop(1) // MarkdownTokenTypes.LIST_BULLET or LIST_NUMBER
.joinToString("") { it.textAsIs(content) }
}
.toSet()
}

Expand Down

0 comments on commit 8847823

Please sign in to comment.