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

[add] add rehype-katex-notranslate plugin for docs #181

Merged
merged 4 commits into from
Oct 7, 2024

Conversation

PrinOrange
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

When a page contains a large number of katex formulas, if we want to use a tool to translate the webpage (such as the built-in translation tool of Google Chrome), the translation tool will often translate the symbols in the katex block, which will cause the formula to be destroyed.

So I wrote a rehype plugin rehype-katex-notranslate. This plugin add the attribute translate="no" to the katex formula generated by rehype-katex to prevent the formulas from being recognized and translated by webpage and browser translation tools.

@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 Oct 7, 2024
@ChristianMurphy
Copy link
Member

ChristianMurphy commented Oct 7, 2024

Thanks for sharing @PrinOrange! 🙇

General feedback on what gets included in the plugins list:

Some criteria to include packages in this list.

  • Some documentation with at least some instructions on how to use the package.
  • A CI job to run tests. (The tests are already there.)
  • A prepack script and CI job to build the types. (The JSDoc types are already there.)
  • The package should be published to npm.

source: syntax-tree/hast#24 (comment)

For your plugin I'm seeing:

  • Documentation
  • CI to run lint/tests
  • Job to generate types
  • Published to NPM

Some additional specific pointers.

@PrinOrange
Copy link
Contributor Author

PrinOrange commented Oct 7, 2024

Thank you for your review. I have done some changes and fixes issues you mentioned above.
I fixed the typescript module options and rewrite the process with visit. And I have add some test cases and make it auto-workflows

https://github.com/PrinOrange/rehype-katex-notranslate

@wooorm
Copy link
Member

wooorm commented Oct 7, 2024

Hi!

I would really recommend that you type the input of your top function: tree: Root (which comes from the @types/hast package). Then you don’t need node: Element.

You are using some formatter to rewrite the table of contents.
That is not our style.
We use formatters too.
You can use those formatters by running npm test.
That should make tests and CI pass.

@codecov-commenter
Copy link

codecov-commenter commented Oct 7, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (9bc5528) to head (b0e9a72).
Report is 18 commits behind head on main.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #181   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          154       154           
=========================================
  Hits           154       154           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@remcohaszing
Copy link
Member

I would really recommend that you type the input of your top function: tree: Root (which comes from the @types/hast package). Then you don’t need node: Element.

Even better: change the type annotation of the plugin from Plugin to Plugin<[], Root>. This is the type you want for your exports. The type of tree will be inferred.

Also replace the hast dependency with @types/hast.

@PrinOrange
Copy link
Contributor Author

Oh, sorry, I have re-format the documents and make it passed the CLI check.

I also have followed your advice and rewrites the typing of tree: Root and plugin Plugin<[], Root>.

Thank you all.
https://github.com/PrinOrange/rehype-katex-notranslate

@wooorm
Copy link
Member

wooorm commented Oct 7, 2024

@PrinOrange looks like the readme here still has an unwanted change? Can you revert that? Thanks!

@ChristianMurphy
Copy link
Member

ChristianMurphy commented Oct 7, 2024

Thanks @PrinOrange!
Looks good!


Some other tips.

doc/plugins.md Outdated Show resolved Hide resolved
@wooorm wooorm merged commit 5b1645b into rehypejs:main Oct 7, 2024
2 checks passed
@wooorm wooorm added 📚 area/docs This affects documentation 💪 phase/solved Post is done labels Oct 7, 2024

This comment has been minimized.

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 area/docs This affects documentation 💪 phase/solved Post is done
Development

Successfully merging this pull request may close these issues.

5 participants