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

在Markdown转HTML的显示页面,有些数学公式不能正常显示。 #87

Closed
anby2015 opened this issue May 13, 2015 · 4 comments
Closed

Comments

@anby2015
Copy link

在用editormd.markdownToHTML时,如果 数学公式的内容有 "<" 或者 ">"符号时,数学公式显示不出来。
比如 : 公式是 $$x &lt; y &lt; Z $$,在控制台会报错:"Error: KaTeX parse error: Unexpected character: '&' at position 2: x ̲'&'lt; y '&'lt; Z "
公式是 $$x\leq y &lt; z $$,在控制台会报错:"Error: KaTeX parse error: Unexpected character: '&' at position 8: x\leq y ̲'&'lt; Z"
公式是 $$x &gt; y &gt; Z $$,在控制台会报错:"Error: KaTeX parse error: Unexpected character: '&' at position 2: x ̲ '&'gt; y '&'gt; Z ".

@pandao
Copy link
Owner

pandao commented May 13, 2015

@anby2015 已标记,稍后修正。

@anby2015
Copy link
Author

谢谢。

@anby2015
Copy link
Author

我找到解决这个问题的方法了。
修改editormd.markdownToHTML函数,在其调用katex.render()进行解析前,替换要的解析的字符串里的符号。把实体符号'&'lt; 替换成左尖括号,实体符号'&'gt;替换成右尖括号,这样数学公式就可以正常显示了。
具体修改代码:
把第3783行:

katex.render(tex.html(), tex[0]);

修改为:

var tex_html = tex.html();
tex_html = tex_html.replace(/&lt;/g, '<');
tex_html = tex_html.replace(/&gt;/g, '>');
katex.render(tex_html, tex[0]);

@pandao
Copy link
Owner

pandao commented Jun 2, 2015

@anby2015 fixed @v1.4.5

@pandao pandao closed this as completed Jun 2, 2015
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

No branches or pull requests

2 participants