pandoc-ast icon indicating copy to clipboard operation
pandoc-ast copied to clipboard

Crashes when parsing AST of table with caption.

Open xfbs opened this issue 3 years ago • 3 comments

Hey,

really awesome work here! I noticed a crash when parsing the AST of this table tho:

| First Header | Second Header |
|:-------------|:--------------|
| Content Cell | Content Cell  |

: Table example {#tbl:table1}

thread '' panicked at 'json is not in the pandoc format: Error("invalid type: map, expected a tuple of size 2", line: 283, column: 5)

Here is the raw JSON:

{
  "blocks": [
    {
      "t": "Table",
      "c": [
        [
          "",
          [],
          []
        ],
        {
          "t": "Caption",
          "c": [
            null,
            [
              {
                "t": "Plain",
                "c": [
                  {
                    "t": "Str",
                    "c": "Table"
                  },
                  {
                    "t": "Space"
                  },
                  {
                    "t": "Str",
                    "c": "example"
                  },
                  {
                    "t": "Space"
                  },
                  {
                    "t": "Str",
                    "c": "{#tbl:table1}"
                  }
                ]
              }
            ]
          ]
        },
        [
          [
            {
              "t": "AlignLeft"
            },
            {
              "t": "ColWidthDefault"
            }
          ],
          [
            {
              "t": "AlignLeft"
            },
            {
              "t": "ColWidthDefault"
            }
          ]
        ],
        {
          "t": "TableHead",
          "c": [
            [
              "",
              [],
              []
            ],
            [
              {
                "t": "Row",
                "c": [
                  [
                    "",
                    [],
                    []
                  ],
                  [
                    {
                      "t": "Cell",
                      "c": [
                        [
                          "",
                          [],
                          []
                        ],
                        {
                          "t": "AlignDefault"
                        },
                        {
                          "t": "RowSpan",
                          "c": 1
                        },
                        {
                          "t": "ColSpan",
                          "c": 1
                        },
                        [
                          {
                            "t": "Plain",
                            "c": [
                              {
                                "t": "Str",
                                "c": "First"
                              },
                              {
                                "t": "Space"
                              },
                              {
                                "t": "Str",
                                "c": "Header"
                              }
                            ]
                          }
                        ]
                      ]
                    },
                    {
                      "t": "Cell",
                      "c": [
                        [
                          "",
                          [],
                          []
                        ],
                        {
                          "t": "AlignDefault"
                        },
                        {
                          "t": "RowSpan",
                          "c": 1
                        },
                        {
                          "t": "ColSpan",
                          "c": 1
                        },
                        [
                          {
                            "t": "Plain",
                            "c": [
                              {
                                "t": "Str",
                                "c": "Second"
                              },
                              {
                                "t": "Space"
                              },
                              {
                                "t": "Str",
                                "c": "Header"
                              }
                            ]
                          }
                        ]
                      ]
                    }
                  ]
                ]
              }
            ]
          ]
        },
        [
          {
            "t": "TableBody",
            "c": [
              [
                "",
                [],
                []
              ],
              {
                "t": "RowHeadColumns",
                "c": 0
              },
              [],
              [
                {
                  "t": "Row",
                  "c": [
                    [
                      "",
                      [],
                      []
                    ],
                    [
                      {
                        "t": "Cell",
                        "c": [
                          [
                            "",
                            [],
                            []
                          ],
                          {
                            "t": "AlignDefault"
                          },
                          {
                            "t": "RowSpan",
                            "c": 1
                          },
                          {
                            "t": "ColSpan",
                            "c": 1
                          },
                          [
                            {
                              "t": "Plain",
                              "c": [
                                {
                                  "t": "Str",
                                  "c": "Content"
                                },
                                {
                                  "t": "Space"
                                },
                                {
                                  "t": "Str",
                                  "c": "Cell"
                                }
                              ]
                            }
                          ]
                        ]
                      },
                      {
                        "t": "Cell",
                        "c": [
                          [
                            "",
                            [],
                            []
                          ],
                          {
                            "t": "AlignDefault"
                          },
                          {
                            "t": "RowSpan",
                            "c": 1
                          },
                          {
                            "t": "ColSpan",
                            "c": 1
                          },
                          [
                            {
                              "t": "Plain",
                              "c": [
                                {
                                  "t": "Str",
                                  "c": "Content"
                                },
                                {
                                  "t": "Space"
                                },
                                {
                                  "t": "Str",
                                  "c": "Cell"
                                }
                              ]
                            }
                          ]
                        ]
                      }
                    ]
                  ]
                }
              ]
            ]
          }
        ],
        {
          "t": "TableFoot",
          "c": [
            [
              "",
              [],
              []
            ],
            []
          ]
        }
      ]
    }
  ],
  "pandoc-api-version": [
    1,
    21
  ],
  "meta": {}
}

I hope that is enough information to reproduce this issue. I'm using pandoc version 2.10.1, pandoc crate 0.8.2 and pandoc-ast 0.8.0.

xfbs avatar Jan 03 '21 15:01 xfbs