let PageDown and MathJax work together

前端 未结 4 1866
小蘑菇
小蘑菇 2021-01-30 07:15

I am implementing a UI which is supposed to look pretty much like the one on math.stackexchange.com:

  1. Using fancy Markdown like you are used to on stackoverflow
相关标签:
4条回答
  • 2021-01-30 08:00

    I just combined marked (another Markdown library than Pagedown) and "MathJax" into "markdown+mathjax live editor".

    See the demo: http://kerzol.github.io/markdown-mathjax/editor.html

    And get the source: https://github.com/kerzol/markdown-mathjax

    0 讨论(0)
  • 2021-01-30 08:16

    Geoff Dalgas on the Stack Overflow just released their MathJax + PageDown integration code as a gist. See the Meta post for more details.

    0 讨论(0)
  • 2021-01-30 08:17

    There are several problems with your current setup. First, the example you have borrowed from is an example of updating a single equation, not paragraphs that includes multiple equations. For that, you would need to consider the second dynamic example (from the MathJax examples page). You should be getting an error message in your browser console that will have to do with a null value (math will be null unless you start out with some math in the editor to begin with).

    But there is a second issue, which is that the wmd editor will be updating the wmd-preview area, and you should coordinate with it to do the MathJax updating, as otherwise it might change the content of the div while MathJax is working on it. Wmd is also smarter about when it does updates than just on every keypress (e.g., arrow keys don't cause updates), so it will be more efficient to coordinate as well. The SE version of wmd has hooks to allow you to do that, and I suspect the one you are using does as well.

    Finally, you are going to have to do more work to protect the mathematics from the Markdown engine so that things like underscores and backslashes don't get processed by Markdown when they appear in mathematics. That is a bit tricky, but without that, you will run into lots of problems with your TeX code not getting processed properly.

    To deal with the last two issues, you might consider looking at the code used by MSE for hooking MathJax into wmd. Perhaps that will give you some clues about how to do it.

    0 讨论(0)
  • 2021-01-30 08:18

    I've created a basic example for how to get Pagedown and MathJax working together using a slight modification of Stack Exchange's mathjax-editing.js.

    Stack Exchange's code is based on Davide Cervone's, see his comment on another answer.

    The code for the example can be viewed on github.

    0 讨论(0)
提交回复
热议问题