Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior with blank line in itemize or enumerate environment #158

Closed
atsuyaw opened this issue May 15, 2021 · 9 comments · Fixed by #183
Closed

Behavior with blank line in itemize or enumerate environment #158

atsuyaw opened this issue May 15, 2021 · 9 comments · Fixed by #183
Assignees
Labels
bug Something isn't working

Comments

@atsuyaw
Copy link

atsuyaw commented May 15, 2021

When there is a blank line just before/after comment line in itemize or enumerate environment, textlint shows error:

[Error - 16:15:59] Unexpected node is given. Is the syntax correct?
Error: Unexpected node is given. Is the syntax correct?

I encountered this issue with the tex file such as the below:

\begin{enumerate}
	\item aaaaa

	% \vspace{8zh}
	\item bbbb
\end{enumerate}

In case without comment line or/and blank line, the error is not shown.

I am sorry but I'm not acquainted with programming, so I can't provide any idea for solute this issue.

@pddg
Copy link
Member

pddg commented May 16, 2021

@atsuyaw
Thank you for reporting the issue.
I reproduced this issue and will work for fixing this.

@pddg pddg added the bug Something isn't working label May 16, 2021
@pddg
Copy link
Member

pddg commented May 16, 2021

$ cat << EOF > sample.tex
\begin{enumerate}
  \item aaaaa

  % \vspace{8zh}
  \item bbbb
\end{enumerate}
EOF 
npx luparse -lc sample.tex
$ npx luparse -lc sample.tex
{
  "kind": "ast.root",
  "content": [
    {
      "kind": "env",
      "name": "enumerate",
      "args": [],
      "content": [
        {
          "kind": "command",
          "name": "item",
          "args": [],
          "location": {
            "start": {
              "offset": 19,
              "line": 2,
              "column": 2
            },
            "end": {
              "offset": 24,
              "line": 2,
              "column": 7
            }
          }
        },
        {
          "kind": "text.string",
          "content": "aaaaa",
          "location": {
            "start": {
              "offset": 25,
              "line": 2,
              "column": 8
            },
            "end": {
              "offset": 30,
              "line": 2,
              "column": 13
            }
          }
        },
        {
          "kind": "parbreak",
          "location": {
            "start": {
              "offset": 30,
              "line": 2,
              "column": 13
            },
            "end": {
              "offset": 49,
              "line": 5,
              "column": 2
            }
          }
        },
        {
          "kind": "command",
          "name": "item",
          "args": [],
          "location": {
            "start": {
              "offset": 49,
              "line": 5,
              "column": 2
            },
            "end": {
              "offset": 54,
              "line": 5,
              "column": 7
            }
          }
        },
        {
          "kind": "text.string",
          "content": "bbbb",
          "location": {
            "start": {
              "offset": 55,
              "line": 5,
              "column": 8
            },
            "end": {
              "offset": 59,
              "line": 5,
              "column": 12
            }
          }
        }
      ],
      "location": {
        "start": {
          "offset": 0,
          "line": 1,
          "column": 1
        },
        "end": {
          "offset": 75,
          "line": 6,
          "column": 16
        }
      }
    }
  ],
  "comment": [
    {
      "kind": "comment",
      "content": " \\vspace{8zh}",
      "location": {
        "start": {
          "offset": 33,
          "line": 4,
          "column": 2
        },
        "end": {
          "offset": 48,
          "line": 5,
          "column": 1
        }
      }
    }
  ]
}

The location of parbreak (next line of aaaa) is:

          "location": {
            "start": {
              "offset": 30,
              "line": 2,
              "column": 13
            },
            "end": {
              "offset": 49,
              "line": 5,
              "column": 2
            }
          }

The location of comment is:

      "location": {
        "start": {
          "offset": 33,
          "line": 4,
          "column": 2
        },
        "end": {
          "offset": 48,
          "line": 5,
          "column": 1
        }
      }

The parbreak seems including the comment node, but it cannot have child nodes actually. So it will become an error.
This might be a issue of latex-utensils. It can be reproduced using the latest version of latex-utensils.

(However, now we use [email protected]. Even if this is resolved by latex-utensils, we may have to resolve #79 (comment) first.)

@pddg
Copy link
Member

pddg commented May 16, 2021

$ cat << EOF > sample.tex
\begin{document}

% \vspace{8zh}

\end{document}
EOF
npx luparse -lc sample.tex
{
  "kind": "ast.root",
  "content": [
    {
      "kind": "env",
      "name": "document",
      "args": [],
      "content": [
        {
          "kind": "parbreak",
          "location": {
            "start": {
              "offset": 16,
              "line": 1,
              "column": 17
            },
            "end": {
              "offset": 34,
              "line": 5,
              "column": 1
            }
          }
        }
      ],
      "location": {
        "start": {
          "offset": 0,
          "line": 1,
          "column": 1
        },
        "end": {
          "offset": 48,
          "line": 5,
          "column": 15
        }
      }
    },
    {
      "kind": "parbreak",
      "location": {
        "start": {
          "offset": 48,
          "line": 5,
          "column": 15
        },
        "end": {
          "offset": 50,
          "line": 7,
          "column": 1
        }
      }
    }
  ],
  "comment": [
    {
      "kind": "comment",
      "content": " \\vspace{8zh}",
      "location": {
        "start": {
          "offset": 18,
          "line": 3,
          "column": 1
        },
        "end": {
          "offset": 33,
          "line": 4,
          "column": 1
        }
      }
    }
  ]
}

The location of parbreak is:

          "location": {
            "start": {
              "offset": 16,
              "line": 1,
              "column": 17
            },
            "end": {
              "offset": 34,
              "line": 5,
              "column": 1
            }
          }

The location of the comment is:

      "location": {
        "start": {
          "offset": 18,
          "line": 3,
          "column": 1
        },
        "end": {
          "offset": 33,
          "line": 4,
          "column": 1
        }
      }

In the same way, the parbreak node appears to contain the comment node. However, this can be parsed by tex2tast.

{
  "type": "Document",
  "range": [
    0,
    50
  ],
  "loc": {
    "start": {
      "line": 1,
      "column": 0
    },
    "end": {
      "line": 6,
      "column": 0
    }
  },
  "children": [
    {
      "loc": {
        "start": {
          "line": 3,
          "column": 0
        },
        "end": {
          "line": 4,
          "column": 0
        }
      },
      "range": [
        18,
        33
      ],
      "value": " \\vspace{8zh}",
      "type": "Comment"
    }
  ]
}

@tani
Do you have any ideas as to why a comment just after a blank line in an enumerate environment would be an error?
Is it possible that the following function is affecting this in some way?

const transformListItems =

@tani
Copy link
Member

tani commented May 16, 2021

Hmm, the code you mentioned is very clear and looks it has no problem. We should also check the code inserting comment nodes. @atsuyaw, Could you give one week to us because the behavior of code is curious.

@tani tani assigned tani and pddg May 16, 2021
@tani
Copy link
Member

tani commented May 16, 2021

We should also report this but to upstream because of the bug @pddg mentioned.

@atsuyaw
Copy link
Author

atsuyaw commented May 16, 2021

@tani
sure
I can avoid temporarily this issue by comment outing the blank line.
I just use the blank line for visibility with long \item line, so this issue is not serious for me.

@pddg @tani
Thankyou for your early corresponding.

@pddg
Copy link
Member

pddg commented Jun 6, 2021

@tani
We should consider that the parbreak node will overlaps the location of comment...
tamuratak/latex-utensils#25 (comment)

@tani
Copy link
Member

tani commented Jun 6, 2021

I see. Hmm...

@pddg
Copy link
Member

pddg commented Jun 12, 2021

I found a solution.
Ignore parbreak as well as follows.

if (
(node.kind === "command" && node.name === "item") ||
node.kind === "math.character"
) {
return [];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants