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 eb827c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Fixed
- No-longer discard all but the last paragraph in list items [#133](../../issues/133) [#147](../../issues/147)

## [2.0.0] - 2022-10-28

### Added
Expand Down
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 eb827c4

Please sign in to comment.