Skip to content

Commit

Permalink
Fix bug in AST traversal of tables
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotto committed Aug 6, 2023
1 parent be3599f commit 259a369
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ This version upgrades to the latest Pandoc version 3.0 with API version 1.23.

- Remove obsolete `Panpipe.AST.Null` AST node struct

### Fixed

- bug in AST traversal of tables


[Compare v0.2.0...HEAD](https://github.com/marcelotto/panpipe/compare/v0.2.0...HEAD)

Expand Down
2 changes: 1 addition & 1 deletion lib/panpipe/ast/nodes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ defmodule Panpipe.AST.Table do
table.caption.blocks ++
Panpipe.AST.TableHead.children(table.table_head) ++
Enum.flat_map(table.table_bodies, &Panpipe.AST.TableBody.children/1) ++
Panpipe.AST.TableHead.children(table.table_foot)
Panpipe.AST.TableFoot.children(table.table_foot)
end

def transform(%__MODULE__{} = table, fun) do
Expand Down
20 changes: 20 additions & 0 deletions test/panpipe/ast_node_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ defmodule Panpipe.AST.NodeTest do
]
end

test "traverse over multiline table" do
assert {:ok, ast} = """
---
# Foo
Bar
---
# Baz
...
"""
|> Panpipe.ast(from: {:markdown, [:multiline_tables]})

for %{parent: %Panpipe.Document{}} = element <- ast do
%{element | parent: nil}
end

end

describe "transform/2" do
test "replace a node with another node" do
assert {:ok, document} = Panpipe.ast "<http://example.com/foo>"
Expand Down

0 comments on commit 259a369

Please sign in to comment.