문제

I have a problem posting text in a html form. The text (from a textarea) to be posted to a new page to show may have the following properties:

  1. including latex code to be handled by MathJax between two dollar sign
  2. needs to preserve the line break
  3. may including html code such as a input tag

I have tried the following methods:

  • replace "\r\n" sub-strings to html "br" tag and then post the text to innerHTML of a div or span to keep line breaks. But then I need remove the html part in the text beforehand, otherwise, if the text include a "input" tag, I will then have a input box in the resulted page!

    What's more, if I remove html tags, then I will accidently remove the sub string like a < b, b > c, (if '<' and 'b', 'b' and '>' are adjacent, seems StackOverFlow can't deal with it, too!)

  • using a pre tag to keep line breaks, then MathJax doesn't work!

So, can anyone save me for this problem? Thanks in advance! By the way, I use ruby on rails on my project.

도움이 되었습니까?

해결책

You could allow MathJax to process <pre> tags by removing them from the skipTags array in the text2jax block of your configuration. See the documentation for more details.

다른 팁

At last, I use skipTags as Mr Cervone mentioned above and put the text into the pre tag. To convert(and preserve) the HTML tag into plaintext format, I use a method provided by ruby called CGI.escapeHTML.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top