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

Various bug fixs and enhancements on TeX math rendering #5

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

Conversation

sun123zxy
Copy link

@sun123zxy sun123zxy commented Feb 24, 2024

The followings are various bug fixs (2) and enhancement (1) on TeX math rendering. This is a part of work in an attempt to resolve niudai/VSCode-Zhihu#171. See each comment below for details.

encodeURI() in Javascript does not escape ; / ? : @ & = + $ , #, while these characters may exist in a TeX math. Among them & is frequently used, for example in a aligned environment.

However, when appending encodeURI(tokens[idx].content) to the URL //www.zhihu.com/equation?tex=, & is interpreted as an argument separator. This causes the resulting URL not desired (though seemingly harmless in Zhihu On VSCode). encodeURIComponent() is a better choice as it escapes more characters including $.

@sun123zxy sun123zxy changed the title replace encodeURI() with encodeURIComponent() to escape TeX replace encodeURI() with encodeURIComponent() to escape TeX math Feb 24, 2024
@sun123zxy
Copy link
Author

This is a part of work in an attempt to resolve niudai/VSCode-Zhihu#171. If things goes well I'll submit another pull request later to fix this issue.

@sun123zxy sun123zxy changed the title replace encodeURI() with encodeURIComponent() to escape TeX math replace encodeURI() with encodeURIComponent() to escape TeX math; replace \n with spaces in TeX math's <img alt=...> Feb 24, 2024
@sun123zxy
Copy link
Author

This is a part of work in an attempt to resolve niudai/VSCode-Zhihu#171. If things goes well I'll submit another pull request later to fix this issue.

Resolved in the later commit of this pull request. niudai/VSCode-Zhihu#171 is caused by the alt attribute of <img> in which TeX math is rendered. It seems that Zhihu reads this alt attribute to recover the original TeX code in the edit mode. Experimenting around shows that each appearance of \n results in a <br> appearance in the edit mode. So simply replace these \n in alt with spaces would work.
I understand that Zhihu on VSCode related projects are no longer under active maintenance, but people across the community have greatly profited from this amazing extension. Anyway hope this helps. Looking forward to the next release of Zhihu on VSCode fixing this.

@sun123zxy sun123zxy changed the title replace encodeURI() with encodeURIComponent() to escape TeX math; replace \n with spaces in TeX math's <img alt=...> Various bug fixs and enhancements on TeX math rendering Feb 25, 2024
@sun123zxy
Copy link
Author

sun123zxy commented Feb 25, 2024

Here's a new enhancement carried by the latest commit. It seems that Zhihu does not differentiate inline math and block math in its article editor. Current handling of block math only surrounds TeX SVG images with <p></p>. The math block is still of inline style, inconsistent with most of other markdown renderers. In this commit I added \displaystyle before each block math so things go more smoothly.

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.

行间公式中使用aligned环境,上传到知乎后代码块内出现大量<br>换行符
1 participant