From 259a369e24e14103bed42bdbdf3be56ebf060da4 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Sun, 6 Aug 2023 21:26:59 +0200 Subject: [PATCH] Fix bug in AST traversal of tables --- CHANGELOG.md | 4 ++++ lib/panpipe/ast/nodes.ex | 2 +- test/panpipe/ast_node_test.exs | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a704b6..b146d3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/panpipe/ast/nodes.ex b/lib/panpipe/ast/nodes.ex index b070956..1b00ac5 100644 --- a/lib/panpipe/ast/nodes.ex +++ b/lib/panpipe/ast/nodes.ex @@ -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 diff --git a/test/panpipe/ast_node_test.exs b/test/panpipe/ast_node_test.exs index f4a52da..93ea008 100644 --- a/test/panpipe/ast_node_test.exs +++ b/test/panpipe/ast_node_test.exs @@ -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 ""