diff --git a/library/src/commonMain/kotlin/dev/usbharu/markdown/Parser.kt b/library/src/commonMain/kotlin/dev/usbharu/markdown/Parser.kt index aec00b8..24f6162 100644 --- a/library/src/commonMain/kotlin/dev/usbharu/markdown/Parser.kt +++ b/library/src/commonMain/kotlin/dev/usbharu/markdown/Parser.kt @@ -78,12 +78,14 @@ class Parser { } val peekOrNull = iterator.peekOrNull() if (peekOrNull is Token.List) { - iterator.skip() + if (peekOrNull.type != list.type) { if (item.isNotEmpty()) { listItems.add(ListItemNode(item)) } break + } else { + iterator.skip() } } diff --git a/library/src/commonTest/kotlin/dev/usbharu/markdown/ParserTest.kt b/library/src/commonTest/kotlin/dev/usbharu/markdown/ParserTest.kt index 3cb69b1..0f5c347 100644 --- a/library/src/commonTest/kotlin/dev/usbharu/markdown/ParserTest.kt +++ b/library/src/commonTest/kotlin/dev/usbharu/markdown/ParserTest.kt @@ -670,4 +670,43 @@ class ParserTest { ), actual ) } + + @Test + fun 異種list() { + val parser = Parser() + + val actual = parser.parse( + listOf( + DiscList, + Text("aiueo"), + LineBreak(1), + DiscList, + Text("abcd"), + LineBreak(1), + DecimalList('1'), + Text("efgh"), + LineBreak(1), + DecimalList('1'), + Text("hoge") + ) + ) + + println(actual) + println(actual.print()) + + assertEquals( + RootNode( + BodyNode( + DiscListNode( + ListItemNode(PlainText("aiueo")), + ListItemNode(PlainText("abcd")) + ), + DecimalListNode( + ListItemNode(PlainText("efgh")), + ListItemNode(PlainText("hoge")) + ) + ) + ), actual + ) + } } \ No newline at end of file