grnet / docusaurus-terminology

Home of Docusaurus Terminology Plugin
BSD 2-Clause "Simplified" License
35 stars 5 forks source link

v.1.0.1 breaks on multi-line links #21

Closed Battleman closed 6 months ago

Battleman commented 11 months ago

After updating docusaurus-terminology to 1.0.1, our build fails, with error

TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))
[ERROR] Client bundle compiled with errors therefore further build is impossible.
error Command failed with exit code 1.

package.json dependencies look like so:

extract of package.json ```json { ... "dependencies": { "@docusaurus/core": "2.4.3", "@docusaurus/preset-classic": "2.4.3", "@docusaurus/theme-mermaid": "2.4.3", "@easyops-cn/docusaurus-search-local": "0.35.0", "@grafana/faro-web-sdk": "1.1.4", "@grnet/docusaurus-glossary-view": "1.0.1", "@grnet/docusaurus-term-preview": "1.0.1", "@grnet/docusaurus-terminology": "1.0.1", "@mdx-js/react": "1.6.22", "clsx": "1.2.1", "docusaurus-plugin-image-zoom": "0.1.2", "hast-util-is-element": "1.1.0", "prism-react-renderer": "1.3.5", "react": "17.0.2", "react-dom": "17.0.2", "rehype-katex": "5", "remark-math": "3" }, "devDependencies": { "@docusaurus/module-type-aliases": "2.4.0" }, ... } ```

Downgrading @grnet/docusaurus-terminology to 1.0.0 fixes the issue.

I'm no node guru, but am willing to provide additional information if necessary, or follow some debugging steps.

Battleman commented 11 months ago

Update: it appears we have a file that contains a link on multiple lines

[a link 
like this](https://example.org)

1.0.0 had support for multi-lines (flags gmi), while 1.0.1 has dropped flags mi. It's not a concerning issue for us, as it was probably introduced long ago by an auto-formatter. Putting back the link on one line fixes the issue, while not having any other side effect for us.

I guess now this issue is up to you: maybe it's worth adding some checks to prevent the obscure issue, or add back the m flag, or just document it somewhere.

As far as we're concerned, this issue is fixed.

tsironis commented 11 months ago

Thanks @Battleman. Glad to see the issue is fixed on your end, and also, for your suggestions. We'll keep this open and see if we can improve the development experience.

dimisus commented 11 months ago
TypeError: object null is not iterable (cannot read property Symbol(Symbol.iterator))

When filtering parsed URLs for one-liners only it builds without errors. Can confirm the issue relates to multi-line URLs as mentioned by @Battleman .


// in ../node_modules/@grnet/webpack-terms-replace-loader/index.js

module.exports = function(source) {
  const urlsRegex = /(?<!!)\[[^\]]+\]\([^)]+\)/g;

  const urlRegex = /\[(.*?)\]\((.*?)\)/;

  const urls = (source.match(urlsRegex) || []).filter(u => {
    regex = /^(\[{1})[\w`].*\]\(.*\)$/g;     // <=== here filtered for only one-liner urls

    return regex.test(u);
  })

Note: this is not a solution, it just throws out all multi line urls

osterman commented 7 months ago

Thank. you @dimisus!! I was tearing my hair out on this one, and this led me to the fix.

Here's my modification, that outputs the offending URLs. Only the ones with a newline needed to be fixed. Others with braces or other characters were redherrings.

const urlsRegex = /(?<!!)\[[^\]]+\]\([^)]+\)/g;

  const urlRegex = /\[(.*?)\]\((.*?)\)/;

  const urls = (source.match(urlsRegex) || []).filter(u => {
    regex = /^(\[{1})[\w`].*\]\(.*\)$/g;     // <=== here filtered for only one-liner urls
    if (!regex.test(u)) {
      console.log(u); // Log if it's not a one-liner URL
      return true; // Include this URL in the filtered results
    }

    return regex.test(u);
  })
tsironis commented 6 months ago

2.0.0-rc.1 was just released and it contains the fix for this bug. Please check it out and feel fee to reopen the issue if the bug still persists.