Skip to content

Commit

Permalink
Fix lists reset logic (#10)
Browse files Browse the repository at this point in the history
There were strange group reset logic in case of lists.

We need to reset list only if previously there were another active list
of different type.

Fixes #9
  • Loading branch information
sivukhin authored Sep 14, 2024
2 parents 9170633 + dadba49 commit 975b00d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
8 changes: 5 additions & 3 deletions djot_parser/djot_ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -523,7 +524,8 @@ func buildDjotAst(
groupElements = append(groupElements, &sectionNode)
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]
}
Expand Down Expand Up @@ -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{}
Expand Down
3 changes: 3 additions & 0 deletions djot_parser/examples/issue_9.djot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Test

- List item
8 changes: 8 additions & 0 deletions djot_parser/examples/issue_9.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<section id="Test">
<h1>Test</h1>
<ul>
<li>
List item
</li>
</ul>
</section>
8 changes: 8 additions & 0 deletions djot_parser/examples/issue_9_1.djot
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Test

- 1 item
* 2 item
1) 3 item
2) 4 item
A) 5 item
B) 6 item
29 changes: 29 additions & 0 deletions djot_parser/examples/issue_9_1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<section id="Test">
<h1>Test</h1>
<ul>
<li>
1 item
</li>
</ul>
<ul>
<li>
2 item
</li>
</ul>
<ol>
<li>
3 item
</li>
<li>
4 item
</li>
</ol>
<ol type="A">
<li>
5 item
</li>
<li>
6 item
</li>
</ol>
</section>

0 comments on commit 975b00d

Please sign in to comment.