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 CHTML Output Processor #43

Merged
merged 9 commits into from
Apr 24, 2020
Merged

Add CHTML Output Processor #43

merged 9 commits into from
Apr 24, 2020

Conversation

tani
Copy link
Contributor

@tani tani commented Apr 21, 2020

Closes GH-42

I add two plugins rehypeMathJaxCHTML and rehypeMathJaxSVG instead of rehypeMathJax.
Users can choose the output processor of MathJax by this change.

API

const rehypeMathJaxCHTML = require('rehype-mathjax/chtml') // Import CommonHTML ouput processor
// const rehypeMathJaxSVG = require('rehype-mathjax/svg') // Import SVG output processor
// const {rehypeMathJaxCHTML, rehypeMathJaxSVG}  = require('rehype-mathjax') // Import both processors
unified().use(rehypeMathJaxCHMTL, options)

Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 🎊

  • I’d prefer casing acronyms as normal words: CHTMLRenderer -> ChtmlRenderer, fontURL -> fontUrl, rehypeMathJaxSVG -> rehypeMathJaxSvg; what do you think?
  • I think it makes more sense to default to one from index.js instead of exporting both. Exporting both is probably not what you want. We should pick the one that makes the most sense and export that from index.js.

@tani
Copy link
Contributor Author

tani commented Apr 23, 2020

I updated symbol names, however, we should not change the symbol fontURL because this is not defined in our code. This symbol named by upstream, MathJax.

@tani
Copy link
Contributor Author

tani commented Apr 23, 2020

According to the documet of MathJax,

Currently, MathJax can render math in three ways:

Using HTML and CSS to lay out the mathematics,
Using Scalable Vector Graphics (SVG) to lay out the mathematics, or
As a serialized MathML string.
The first two are implemented by the CommonHTML and SVG output processors. The third is a consequence of the fact that MathJax uses MathML as its internal format. While MathJax version 2 included a NativeMML output processor that produced MathML notation for those browsers that support it, this has been dropped from version 3. See the MathML Support section for more information on how to get MathML output.
Currently, MathJax can render math in three ways:

Using HTML and CSS to lay out the mathematics,
Using Scalable Vector Graphics (SVG) to lay out the mathematics, or
As a serialized MathML string.
The first two are implemented by the CommonHTML and SVG output processors. The third is a consequence of the fact that MathJax uses MathML as its internal format. While MathJax version 2 included a NativeMML output processor that produced MathML notation for those browsers that support it, this has been dropped from version 3. See the MathML Support section for more information on how to get MathML output.

If you are using one of the combined component files, then this will select one of these output processors for you. If the component file ends in -chtml, then it is the CommonHTML output processor, while if it ends in -svg then the SVG output processor will be used.
If you are using one of the combined component files, then this will select one of these output processors for you. If the component file ends in -chtml, then it is the CommonHTML output processor, while if it ends in -svg then the SVG output processor will be used.

There is no recommendation of output format, every output format treated equally in document.
As SVG output format has no external dependency, I prefer to set it default.
While we have to set fontURL when we use CHTML output format, this is better to reduce the bundled size. I'd like to avoid the external dependency even if the bundle size is reduced. How about you?

@wooorm
Copy link
Member

wooorm commented Apr 23, 2020

Yeah, seems like SVG is a good default, as it works without options!

@wooorm wooorm merged commit c5ab344 into remarkjs:master Apr 24, 2020
@wooorm wooorm added 🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🦋 type/enhancement This is great to have 🧒 semver/minor This is backwards-compatible change labels Apr 24, 2020
@wooorm wooorm added the 💪 phase/solved Post is done label Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

rehype-mathjax: mathjax is 500kb+ minzipped
2 participants