showdown.Converter.makeHtml.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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('makeHtml() with option omitExtraWLInCodeBlocks', function () {
  10. var converter = new showdown.Converter({omitExtraWLInCodeBlocks: true}),
  11. text = 'var foo = bar;',
  12. html = converter.makeHtml(' ' + text);
  13. it('should omit extra line after code tag', function () {
  14. var expectedHtml = '<pre><code>' + text + '</code></pre>';
  15. html.should.equal(expectedHtml);
  16. });
  17. });
  18. describe('makeHtml() with option prefixHeaderId', function () {
  19. var converter = new showdown.Converter(),
  20. text = 'foo header';
  21. it('should prefix header id with "section"', function () {
  22. converter.setOption('prefixHeaderId', true);
  23. var html = converter.makeHtml('# ' + text),
  24. expectedHtml = '<h1 id="sectionfooheader">' + text + '</h1>';
  25. html.should.equal(expectedHtml);
  26. });
  27. it('should prefix header id with custom string', function () {
  28. converter.setOption('prefixHeaderId', 'blabla');
  29. var html = converter.makeHtml('# ' + text),
  30. expectedHtml = '<h1 id="blablafooheader">' + text + '</h1>';
  31. html.should.equal(expectedHtml);
  32. });
  33. });
  34. describe('makeHtml() with option metadata', function () {
  35. var converter = new showdown.Converter(),
  36. text1 =
  37. '---SIMPLE\n' +
  38. 'foo: bar\n' +
  39. 'baz: bazinga\n' +
  40. '---\n',
  41. text2 =
  42. '---TIVIE\n' +
  43. 'a: b\n' +
  44. 'c: 123\n' +
  45. '---\n';
  46. it('should correctly set metadata', function () {
  47. converter.setOption('metadata', true);
  48. var expectedHtml = '',
  49. expectedObj = {foo: 'bar', baz: 'bazinga'},
  50. expectedRaw = 'foo: bar\nbaz: bazinga',
  51. expectedFormat = 'SIMPLE';
  52. converter.makeHtml(text1).should.equal(expectedHtml);
  53. converter.getMetadata().should.eql(expectedObj);
  54. converter.getMetadata(true).should.equal(expectedRaw);
  55. converter.getMetadataFormat().should.equal(expectedFormat);
  56. });
  57. it('consecutive calls should reset metadata', function () {
  58. converter.makeHtml(text2);
  59. var expectedObj = {a: 'b', c: '123'},
  60. expectedRaw = 'a: b\nc: 123',
  61. expectedFormat = 'TIVIE';
  62. converter.getMetadata().should.eql(expectedObj);
  63. converter.getMetadata(true).should.equal(expectedRaw);
  64. converter.getMetadataFormat().should.equal(expectedFormat);
  65. });
  66. });
  67. });