showdown.Converter.makeHtml.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. });