textlint-plugin-latex2e icon indicating copy to clipboard operation
textlint-plugin-latex2e copied to clipboard

tabular environment is treated as a paragraph in the textlint AST

Open kn1cht opened this issue 4 years ago • 4 comments

Problem

textlint-rule-ja-no-mixed-period points out "no period" errors in tabular environments.

image

Cause

\begin{table}[]
  \begin{tabular}{cc}
    This is & a table
  \end{tabular}
\end{table}

This LaTeX code is converted to an AST like below. Since textlint-rule-ja-no-mixed-period treats the last Str node of a Paragraph node as the end of a sentence, converting a tabular environment to these nodes causes an unexpected error.

{
  "type": "Document",
  "raw": "...",
  "range": [],
  "loc": {},
  "children": [
    {
      "loc": {},
      "range": [],
      "raw": "cc}\n        This is & a table",
      "type": "Paragraph",
      "children": [
        {
          "loc": {},
          "range": [],
          "raw": "cc",
          "type": "Str",
          "value": "cc"
        },
        {
          "loc": {},
          "range": [],
          "raw": "}\n        ",
          "type": "Html",
          "value": "}\n        "
        },
        {
          "loc": {},
          "range": [],
          "raw": "This",
          "type": "Str",
          "value": "This"
        },
        // ...
      ]
    }
  ]
}

Solution

textlint-plugin-review seems to treat each item in a table as a ListItem node. We can also wrap Str nodes into ListItem nodes.

https://github.com/orangain/textlint-plugin-review/pull/6

kn1cht avatar Jan 31 '21 03:01 kn1cht

Textlint AST provides Table node. Why not use it instead of ListItem? I note you that the third party parser latex-utensils has no node for table unfortunately.

tani avatar Jan 31 '21 03:01 tani

@tani Table nodes surely exists in markdown-to-ast but not in @textlint/ast-node-types. Thus I couldn't use node types like `ASTnodetypes.Table'.

https://github.com/textlint/textlint/blob/master/docs/txtnode.md#type

kn1cht avatar Jan 31 '21 03:01 kn1cht

OMG, should we send request to ast-node-types?

tani avatar Jan 31 '21 03:01 tani

Thanks for writing the issue. I will wait answers and decide which node to use for tabluar environments.

kn1cht avatar Jan 31 '21 04:01 kn1cht