showdown.Converter.makeHtml.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * Created by Estevao on 15-01-2015.
  3. */
  4. describe('showdown.Converter', function () {
  5. 'use strict';
  6. require('source-map-support').install();
  7. require('chai').should();
  8. var showdown = require('../bootstrap').showdown;
  9. describe('Converter.options extensions', function () {
  10. var runCount;
  11. showdown.extension('testext', function () {
  12. return [{
  13. type: 'output',
  14. filter: function (text) {
  15. runCount = runCount + 1;
  16. return text;
  17. }
  18. }];
  19. });
  20. var converter = new showdown.Converter({extensions: ['testext']});
  21. it('output extensions should run once', function () {
  22. runCount = 0;
  23. converter.makeHtml('# testext');
  24. runCount.should.equal(1);
  25. });
  26. });
  27. describe('makeHtml() with option omitExtraWLInCodeBlocks', function () {
  28. var converter = new showdown.Converter({omitExtraWLInCodeBlocks: true}),
  29. text = 'var foo = bar;',
  30. html = converter.makeHtml(' ' + text);
  31. it('should omit extra line after code tag', function () {
  32. var expectedHtml = '<pre><code>' + text + '</code></pre>';
  33. html.should.equal(expectedHtml);
  34. });
  35. });
  36. describe('makeHtml() with option prefixHeaderId', function () {
  37. var converter = new showdown.Converter(),
  38. text = 'foo header';
  39. it('should prefix header id with "section"', function () {
  40. converter.setOption('prefixHeaderId', true);
  41. var html = converter.makeHtml('# ' + text),
  42. expectedHtml = '<h1 id="sectionfooheader">' + text + '</h1>';
  43. html.should.equal(expectedHtml);
  44. });
  45. it('should prefix header id with custom string', function () {
  46. converter.setOption('prefixHeaderId', 'blabla');
  47. var html = converter.makeHtml('# ' + text),
  48. expectedHtml = '<h1 id="blablafooheader">' + text + '</h1>';
  49. html.should.equal(expectedHtml);
  50. });
  51. });
  52. describe('makeHtml() with option metadata', function () {
  53. var converter = new showdown.Converter(),
  54. text1 =
  55. '---SIMPLE\n' +
  56. 'foo: bar\n' +
  57. 'baz: bazinga\n' +
  58. '---\n',
  59. text2 =
  60. '---TIVIE\n' +
  61. 'a: b\n' +
  62. 'c: 123\n' +
  63. '---\n';
  64. it('should correctly set metadata', function () {
  65. converter.setOption('metadata', true);
  66. var expectedHtml = '',
  67. expectedObj = {foo: 'bar', baz: 'bazinga'},
  68. expectedRaw = 'foo: bar\nbaz: bazinga',
  69. expectedFormat = 'SIMPLE';
  70. converter.makeHtml(text1).should.equal(expectedHtml);
  71. converter.getMetadata().should.eql(expectedObj);
  72. converter.getMetadata(true).should.equal(expectedRaw);
  73. converter.getMetadataFormat().should.equal(expectedFormat);
  74. });
  75. it('consecutive calls should reset metadata', function () {
  76. converter.makeHtml(text2);
  77. var expectedObj = {a: 'b', c: '123'},
  78. expectedRaw = 'a: b\nc: 123',
  79. expectedFormat = 'TIVIE';
  80. converter.getMetadata().should.eql(expectedObj);
  81. converter.getMetadata(true).should.equal(expectedRaw);
  82. converter.getMetadataFormat().should.equal(expectedFormat);
  83. });
  84. });
  85. });