test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* global describe, it */
  2. require('should')
  3. var markdownIt = require('markdown-it')
  4. var md = markdownIt()
  5. var markdownitMathjax = require('..')
  6. md.use(markdownitMathjax())
  7. describe('Tex in-line math', function () {
  8. it('should work properly', function () {
  9. md.render('$1 *2* 3$').should.eql('<p>\\(1 *2* 3\\)</p>\n')
  10. })
  11. it('should not be processed if space after first marker', function () {
  12. md.render('$ 1 *2* 3$').should.eql('<p>$ 1 <em>2</em> 3$</p>\n')
  13. })
  14. it('should not be processed if space before second marker', function () {
  15. md.render('$1 *2* 3 $').should.eql('<p>$1 <em>2</em> 3 $</p>\n')
  16. })
  17. it('should not be processed if number around', function () {
  18. md.render('$1 *2* 3$5').should.eql('<p>$1 <em>2</em> 3$5</p>\n')
  19. })
  20. })
  21. describe('Tex displayed math', function () {
  22. it('should work properly', function () {
  23. md.render('$$1 *2* 3$$').should.eql('<p>\\[1 *2* 3\\]</p>\n')
  24. })
  25. it('should work properly with more than 2 dollar signs', function () {
  26. md.render('$$$1 *2* 3$$$').should.eql('<p>$\\[1 *2* 3\\]$</p>\n')
  27. })
  28. })
  29. describe('LaTeX in-line math', function () {
  30. it('should work properly', function () {
  31. md.render('\\\\(1 *2* 3\\\\)').should.eql('<p>\\(1 *2* 3\\)</p>\n')
  32. })
  33. })
  34. describe('LaTeX displayed math', function () {
  35. it('should work properly', function () {
  36. md.render('\\\\[1 *2* 3\\\\]').should.eql('<p>\\[1 *2* 3\\]</p>\n')
  37. })
  38. })
  39. describe('LaTeX section', function () {
  40. it('should work properly', function () {
  41. md.render('\\begin{section}1 *2* 3\\end{section}').should.eql('<p>\\begin{section}1 *2* 3\\end{section}</p>\n')
  42. })
  43. })
  44. describe('Custom wrapping', function () {
  45. var md = markdownIt()
  46. md.use(markdownitMathjax({
  47. beforeMath: '<span>',
  48. afterMath: '</span>'
  49. }))
  50. it('should work properly', function () {
  51. md.render('\\begin{section}1 *2* 3\\end{section}').should.eql('<p><span>\\begin{section}1 *2* 3\\end{section}</span></p>\n')
  52. })
  53. })