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

Fix to not strip whitespace in th, td #45

Merged
merged 2 commits into from
Jan 18, 2023

Conversation

chitoku-k
Copy link
Contributor

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

Since #29 rehype-react removes any whitespaces in table elements but th and td should not be its target when filtering because whitespaces are valid to appear inside them and of course React does not warn about them. This PR removes th and td from the list of target table elements and adds tests to verify they remain the same. Thanks.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jan 15, 2023
@chitoku-k
Copy link
Contributor Author

Hi, thanks for your prompt response. I think I understood what exactly is happening.

I've made a small reproduction here:
https://github.com/chitoku-k/rehype-react-table-whitespace-test

At first check what happens with the current release:

npm install
npm start

Then apply changes in node_modules/rehype-react/lib/index.js, remove cache, and restart to see how it fixes the problem:

rm -rf node_modules/.cache
npm start

@wooorm
Copy link
Member

wooorm commented Jan 18, 2023

Investigating this some more, most of why this is annoying is due to #32.

What makes it hard to investigate, is that React often does not show warnings. So it’s hard to check. But I did check, with this tree. Every commented out text is whitespace that React (including 18.2) warns about:

  const tree = h("div", [
    h("p", [" ", h("span", "a"), "\n", h("span", "b."), "\t"]),
    h("table", {}, [
      // " ",
      h("thead", [
        // " ",
        h("tr", [
          // " ",
          h("th", [" ", h("span", "c"), "\n", h("span", "d."), "\t"]),
          // "\n",
          h("th", "e.")
          // "\t"
        ]),
        // "\n",
        h("tr", [])
        // "\t"
      ]),
      // "\n",
      h("tbody", [
        // " ",
        h("tr", [
          // " ",
          h("td", [" ", h("span", "f"), "\n", h("span", "g."), "\t"]),
          // "\n",
          h("td", "h.")
          // "\t"
        ]),
        // "\n",
        h("tr", [])
        // "\t"
      ]),
      // "\t",
      h("tfoot", [
        // " ",
        h("tr", [
          // " ",
          h("td", [" ", h("span", "i"), "\n", h("span", "j."), "\t"]),
          // "\n",
          h("td", "k.")
          // "\t"
        ]),
        // "\n",
        h("tr", [])
        // "\t"
      ])
    ])
  ]);

@wooorm wooorm changed the title Fix transformation not to remove whitespaces in th and td Fix to not strip whitespace in th, td Jan 18, 2023
@wooorm wooorm merged commit 33e3489 into rehypejs:main Jan 18, 2023
@wooorm wooorm added 🐛 type/bug This is a problem 💪 phase/solved Post is done labels Jan 18, 2023
@github-actions

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Jan 18, 2023
@wooorm
Copy link
Member

wooorm commented Jan 18, 2023

Thanks, released in 7.1.2!

@chitoku-k
Copy link
Contributor Author

Thanks for your detailed explanation and the release too!

@chitoku-k chitoku-k deleted the fix-table-with-whitespace branch January 18, 2023 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done 🐛 type/bug This is a problem
Development

Successfully merging this pull request may close these issues.

None yet

2 participants