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

V2 Alpha #464

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

V2 Alpha #464

wants to merge 12 commits into from

Conversation

pddg
Copy link
Member

@pddg pddg commented Feb 23, 2024

refs #463

Sorry for the huge PR.

Some large changes in this PR is:

  • Make this module as ESM
  • Use unified-latex instead of latex-utensils
  • Use vitest instead of jest and ts-jest
    • Vitest supports ESM natively and faster than jest
  • Upgrade textlint to v14
    • Our source codes will become type safe.
  • Omit support for Node.js v14.x and v16.x

@pddg pddg requested review from tani and kn1cht February 23, 2024 07:32
@pddg pddg self-assigned this Feb 23, 2024
@pddg pddg marked this pull request as draft February 23, 2024 07:34
@pddg
Copy link
Member Author

pddg commented Feb 23, 2024

Input:

% This is the beginning of the document
\documentclass{article}  % This is a comment

\begin{document}

This is a paragraph that contains inline math: $E=mc^2$.
This is a second line.

This is a link: \href{http://google.com}{google}.

% This is the beginning of the nested document
\begin{itemize}
    \item First item
    \begin{itemize}
        \item nested1
        \item nested2
    \end{itemize}
    \item Second item
\end{itemize}

\begin{description}
    \item[First] This is the first item
    \item[Second] This is the second item
\end{description}

\begin{table}
\begin{center}
\begin{tabular}{|c|c|c|}
    \hline
    Column 1 & Column 2 & Column 3 \\
    \hline
    Row 1 & Row 1 & Row 1 \\
    \hline
    Row 2 & Row 2 & Row 2 \\
    \hline
\end{tabular}
\end{center}
\end{table}

\begin{minted}{python}
def foo():
    print("This is a python code block")
\end{minted}

\end{document}

And the output is as follows:

npx tex2tast ./sample.tex -r
{
  "type": "Document",
  "raw": "% This is the beginning of the document\n\\documentclass{article}  % This is a comment\n\n\\begin{document}\n\nThis is a paragraph that contains inline math: $E=mc^2$.\nThis is a second line.\n\nThis is a link: \\href{http://google.com}{google}.\n\n% This is the beginning of the nested document\n\\begin{itemize}\n    \\item First item\n    \\begin{itemize}\n        \\item nested1\n        \\item nested2\n    \\end{itemize}\n    \\item Second item\n\\end{itemize}\n\n\\begin{description}\n    \\item[First] This is the first item\n    \\item[Second] This is the second item\n\\end{description}\n\n\\begin{table}\n\\begin{center}\n\\begin{tabular}{|c|c|c|}\n    \\hline\n    Column 1 & Column 2 & Column 3 \\\\\n    \\hline\n    Row 1 & Row 1 & Row 1 \\\\\n    \\hline\n    Row 2 & Row 2 & Row 2 \\\\\n    \\hline\n\\end{tabular}\n\\end{center}\n\\end{table}\n\n\\begin{minted}{python}\ndef foo():\n    print(\"This is a python code block\")\n\\end{minted}\n\n\\end{document}\n",
  "children": [
    {
      "type": "Comment",
      "raw": "% This is the beginning of the document\n",
      "value": " This is the beginning of the document"
    },
    {
      "type": "Html",
      "raw": "\\documentclass{article}",
      "value": "article"
    },
    {
      "type": "Comment",
      "raw": "  % This is a comment",
      "value": " This is a comment"
    },
    {
      "type": "Html",
      "raw": "\n\n",
      "value": ""
    },
    {
      "type": "Paragraph",
      "children": [
        {
          "type": "Str",
          "raw": "This is a paragraph that contains inline math: ",
          "value": "This is a paragraph that contains inline math: "
        },
        {
          "type": "Code",
          "raw": "$E=mc^2$",
          "value": "$E=mc^2$"
        },
        {
          "type": "Str",
          "raw": ".\nThis is a second line.",
          "value": ".\nThis is a second line."
        }
      ],
      "raw": "This is a paragraph that contains inline math: $E=mc^2$.\nThis is a second line."
    },
    {
      "type": "Paragraph",
      "children": [
        {
          "type": "Str",
          "raw": "This is a link: ",
          "value": "This is a link: "
        },
        {
          "type": "Link",
          "raw": "\\href{http://google.com}{google}",
          "children": [
            {
              "type": "Str",
              "raw": "google",
              "value": "google"
            }
          ],
          "url": "http://google.com"
        },
        {
          "type": "Str",
          "raw": ".",
          "value": "."
        }
      ],
      "raw": "This is a link: \\href{http://google.com}{google}."
    },
    {
      "type": "Paragraph",
      "children": [
        {
          "type": "Comment",
          "raw": "% This is the beginning of the nested document\n",
          "value": " This is the beginning of the nested document"
        }
      ],
      "raw": "% This is the beginning of the nested document\n"
    },
    {
      "type": "List",
      "children": [
        {
          "type": "ListItem",
          "raw": "\\item First item\n    \\begin{itemize}\n        \\item nested1\n        \\item nested2\n    \\end{itemize}",
          "children": [
            {
              "type": "Paragraph",
              "children": [
                {
                  "type": "Str",
                  "raw": "First item\n    ",
                  "value": "First item\n    "
                }
              ],
              "raw": "First item\n    "
            },
            {
              "type": "List",
              "children": [
                {
                  "type": "ListItem",
                  "raw": "\\item nested1",
                  "children": [
                    {
                      "type": "Paragraph",
                      "children": [
                        {
                          "type": "Str",
                          "raw": "nested1",
                          "value": "nested1"
                        }
                      ],
                      "raw": "nested1"
                    }
                  ]
                },
                {
                  "type": "ListItem",
                  "raw": "\\item nested2",
                  "children": [
                    {
                      "type": "Paragraph",
                      "children": [
                        {
                          "type": "Str",
                          "raw": "nested2",
                          "value": "nested2"
                        }
                      ],
                      "raw": "nested2"
                    }
                  ]
                }
              ],
              "raw": "\\begin{itemize}\n        \\item nested1\n        \\item nested2\n    \\end{itemize}"
            }
          ]
        },
        {
          "type": "ListItem",
          "raw": "\\item Second item",
          "children": [
            {
              "type": "Paragraph",
              "children": [
                {
                  "type": "Str",
                  "raw": "Second item",
                  "value": "Second item"
                }
              ],
              "raw": "Second item"
            }
          ]
        }
      ],
      "raw": "\\begin{itemize}\n    \\item First item\n    \\begin{itemize}\n        \\item nested1\n        \\item nested2\n    \\end{itemize}\n    \\item Second item\n\\end{itemize}"
    },
    {
      "type": "List",
      "children": [
        {
          "type": "ListItem",
          "raw": "\\item[First] This is the first item",
          "children": [
            {
              "type": "Paragraph",
              "children": [
                {
                  "type": "Str",
                  "raw": "First",
                  "value": "First"
                }
              ],
              "raw": "First"
            },
            {
              "type": "Paragraph",
              "children": [
                {
                  "type": "Str",
                  "raw": "This is the first item",
                  "value": "This is the first item"
                }
              ],
              "raw": "This is the first item"
            }
          ]
        },
        {
          "type": "ListItem",
          "raw": "\\item[Second] This is the second item",
          "children": [
            {
              "type": "Paragraph",
              "children": [
                {
                  "type": "Str",
                  "raw": "Second",
                  "value": "Second"
                }
              ],
              "raw": "Second"
            },
            {
              "type": "Paragraph",
              "children": [
                {
                  "type": "Str",
                  "raw": "This is the second item",
                  "value": "This is the second item"
                }
              ],
              "raw": "This is the second item"
            }
          ]
        }
      ],
      "raw": "\\begin{description}\n    \\item[First] This is the first item\n    \\item[Second] This is the second item\n\\end{description}"
    },
    {
      "type": "Table",
      "children": [
        {
          "type": "TableRow",
          "children": [
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Html",
                  "raw": "\\hline",
                  "value": ""
                },
                {
                  "type": "Str",
                  "raw": "\n    Column 1 ",
                  "value": "\n    Column 1 "
                }
              ],
              "raw": "\\hline\n    Column 1 "
            },
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": " Column 2 ",
                  "value": " Column 2 "
                }
              ],
              "raw": " Column 2 "
            },
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": " Column 3 ",
                  "value": " Column 3 "
                }
              ],
              "raw": " Column 3 "
            }
          ],
          "raw": "\\hline\n    Column 1 & Column 2 & Column 3 \\\\"
        },
        {
          "type": "TableRow",
          "children": [
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": "\n    ",
                  "value": "\n    "
                },
                {
                  "type": "Html",
                  "raw": "\\hline",
                  "value": ""
                },
                {
                  "type": "Str",
                  "raw": "\n    Row 1 ",
                  "value": "\n    Row 1 "
                }
              ],
              "raw": "\n    \\hline\n    Row 1 "
            },
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": " Row 1 ",
                  "value": " Row 1 "
                }
              ],
              "raw": " Row 1 "
            },
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": " Row 1 ",
                  "value": " Row 1 "
                }
              ],
              "raw": " Row 1 "
            }
          ],
          "raw": "\n    \\hline\n    Row 1 & Row 1 & Row 1 \\\\"
        },
        {
          "type": "TableRow",
          "children": [
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": "\n    ",
                  "value": "\n    "
                },
                {
                  "type": "Html",
                  "raw": "\\hline",
                  "value": ""
                },
                {
                  "type": "Str",
                  "raw": "\n    Row 2 ",
                  "value": "\n    Row 2 "
                }
              ],
              "raw": "\n    \\hline\n    Row 2 "
            },
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": " Row 2 ",
                  "value": " Row 2 "
                }
              ],
              "raw": " Row 2 "
            },
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": " Row 2 ",
                  "value": " Row 2 "
                }
              ],
              "raw": " Row 2 "
            }
          ],
          "raw": "\n    \\hline\n    Row 2 & Row 2 & Row 2 \\\\"
        },
        {
          "type": "TableRow",
          "children": [
            {
              "type": "TableCell",
              "children": [
                {
                  "type": "Str",
                  "raw": "\n    ",
                  "value": "\n    "
                },
                {
                  "type": "Html",
                  "raw": "\\hline",
                  "value": ""
                }
              ],
              "raw": "\n    \\hline"
            }
          ],
          "raw": "\n    \\hline"
        }
      ],
      "raw": "\\begin{tabular}{|c|c|c|}\n    \\hline\n    Column 1 & Column 2 & Column 3 \\\\\n    \\hline\n    Row 1 & Row 1 & Row 1 \\\\\n    \\hline\n    Row 2 & Row 2 & Row 2 \\\\\n    \\hline\n\\end{tabular}"
    },
    {
      "type": "CodeBlock",
      "raw": "\\begin{minted}{python}\ndef foo():\n    print(\"This is a python code block\")\n\\end{minted}",
      "value": "\ndef foo():\n    print(\"This is a python code block\")\n"
    }
  ]
}

@pddg pddg marked this pull request as ready for review March 15, 2024 01:40
@pddg
Copy link
Member Author

pddg commented Mar 15, 2024

@tani @kn1cht
Hi. I think it is now ready for review!
I think there is room for lots of improvement.

NOTE: We have to decide what version to release. I think it is better to release it as v2.0 alpha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant