showdown.Converter.makeHtml.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. showdown.extensions.testext = function () {
  11. return [{
  12. type: 'output',
  13. filter: function (text) {
  14. runCount = runCount + 1;
  15. return text;
  16. }
  17. }];
  18. };
  19. var runCount,
  20. 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. });