From e2e803f5f2c1784e8f34c659ced19246ef438b1b Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Sat, 14 Sep 2024 22:12:11 +0400 Subject: [PATCH 1/3] add test --- djot_parser/examples/issue_9.djot | 3 +++ djot_parser/examples/issue_9.html | 8 ++++++++ 2 files changed, 11 insertions(+) create mode 100644 djot_parser/examples/issue_9.djot create mode 100644 djot_parser/examples/issue_9.html diff --git a/djot_parser/examples/issue_9.djot b/djot_parser/examples/issue_9.djot new file mode 100644 index 0000000..247b696 --- /dev/null +++ b/djot_parser/examples/issue_9.djot @@ -0,0 +1,3 @@ +# Test + +- List item \ No newline at end of file diff --git a/djot_parser/examples/issue_9.html b/djot_parser/examples/issue_9.html new file mode 100644 index 0000000..53ecde0 --- /dev/null +++ b/djot_parser/examples/issue_9.html @@ -0,0 +1,8 @@ +
+

Test

+ +
From 688f689002a799b549cd0c15c0e7fade22d241ad Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Sat, 14 Sep 2024 22:16:45 +0400 Subject: [PATCH 2/3] fix condition of group reset in case of lists --- djot_parser/djot_ast.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/djot_parser/djot_ast.go b/djot_parser/djot_ast.go index ee61ff1..00d9bf0 100644 --- a/djot_parser/djot_ast.go +++ b/djot_parser/djot_ast.go @@ -444,11 +444,12 @@ func buildDjotAst( footnotes := make([]TreeNode[DjotNode], 0) groupElementsPop := make(map[int]int) + groupElementsInsert := make(map[int]*TreeNode[DjotNode]) assignedTableProps := make(map[int]TableProps) { groupElements := make([]*TreeNode[DjotNode], 0) - activeList, activeListNode, activeListLastItemSparse := ListProps{}, &TreeNode[DjotNode]{}, false + activeList, activeListNode, activeListLastItemSparse := ListProps{}, (*TreeNode[DjotNode])(nil), false activeTableProps := TableProps{} i, previous := 0, -1 for i < len(list) { @@ -523,7 +524,8 @@ func buildDjotAst( groupElements = append(groupElements, §ionNode) case djot_tokenizer.ListItemBlock: currentList, currentStart := detectListProps(document, openToken) - if len(groupElements) > 0 && (groupElements[len(groupElements)-1].Type != currentList.Type || activeList != currentList) { + // reset group only if last active group is the List of another type (markers, style, etc.) + if len(groupElements) > 0 && activeListNode != nil && activeList != currentList { groupElementsPop[i] = 1 groupElements = groupElements[:len(groupElements)-1] } @@ -553,7 +555,7 @@ func buildDjotAst( } } if openToken.Type != djot_tokenizer.ListItemBlock { - activeList, activeListNode, activeListLastItemSparse = ListProps{}, &TreeNode[DjotNode]{}, false + activeList, activeListNode, activeListLastItemSparse = ListProps{}, (*TreeNode[DjotNode])(nil), false } if openToken.Type != djot_tokenizer.PipeTableBlock { activeTableProps = TableProps{} From dadba49b7c4dc49c157dfaff6af3e74d2d122d71 Mon Sep 17 00:00:00 2001 From: Nikita Sivukhin Date: Sat, 14 Sep 2024 22:21:43 +0400 Subject: [PATCH 3/3] add one more test --- djot_parser/examples/issue_9_1.djot | 8 ++++++++ djot_parser/examples/issue_9_1.html | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 djot_parser/examples/issue_9_1.djot create mode 100644 djot_parser/examples/issue_9_1.html diff --git a/djot_parser/examples/issue_9_1.djot b/djot_parser/examples/issue_9_1.djot new file mode 100644 index 0000000..3f174ae --- /dev/null +++ b/djot_parser/examples/issue_9_1.djot @@ -0,0 +1,8 @@ +# Test + +- 1 item +* 2 item +1) 3 item +2) 4 item +A) 5 item +B) 6 item \ No newline at end of file diff --git a/djot_parser/examples/issue_9_1.html b/djot_parser/examples/issue_9_1.html new file mode 100644 index 0000000..4ede45a --- /dev/null +++ b/djot_parser/examples/issue_9_1.html @@ -0,0 +1,29 @@ +
+

Test

+
    +
  • +1 item +
  • +
+
    +
  • +2 item +
  • +
+
    +
  1. +3 item +
  2. +
  3. +4 item +
  4. +
+
    +
  1. +5 item +
  2. +
  3. +6 item +
  4. +
+