8
0

code.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import MarkdownDataProcessor from '/ckeditor5/markdown-gfm/gfmdataprocessor.js';
  6. import { stringify } from '/tests/engine/_utils/view.js';
  7. describe( 'GFMDataProcessor', () => {
  8. let dataProcessor;
  9. beforeEach( () => {
  10. dataProcessor = new MarkdownDataProcessor();
  11. } );
  12. describe( 'code', () => {
  13. describe( 'toView', () => {
  14. it( 'should process inline code', () => {
  15. const viewFragment = dataProcessor.toView( 'regular text and `inline code`' );
  16. expect( stringify( viewFragment ) ).to.equal( '<p>regular text and <code>inline code</code></p>' );
  17. } );
  18. it( 'should properly process backticks when combined', () => {
  19. const viewFragment = dataProcessor.toView( '`<fake a="` content of attribute `">`' );
  20. expect( stringify( viewFragment ) ).to.equal( '<p><code><fake a="</code> content of attribute <code>"></code></p>' );
  21. } );
  22. it( 'should properly process backticks inside code spans', () => {
  23. const viewFragment = dataProcessor.toView( '`` `backticks` ``' );
  24. // This should be checked - why there is a space after `bacticks`.
  25. expect( stringify( viewFragment ) ).to.equal( '<p><code>`backticks` </code></p>' );
  26. } );
  27. it( 'should process code blocks indented with tabs', () => {
  28. const viewFragment = dataProcessor.toView( ' code block' );
  29. expect( stringify( viewFragment ) ).to.equal( '<pre><code>code block</code></pre>' );
  30. } );
  31. it( 'should process code blocks indented with spaces', () => {
  32. const viewFragment = dataProcessor.toView( ' code block' );
  33. expect( stringify( viewFragment ) ).to.equal( '<pre><code>code block</code></pre>' );
  34. } );
  35. it( 'should process multi line code blocks indented with tabs', () => {
  36. const viewFragment = dataProcessor.toView( ' first line\n second line' );
  37. expect( stringify( viewFragment ) ).to.equal( '<pre><code>first line\nsecond line</code></pre>' );
  38. } );
  39. it( 'should process multi line code blocks indented with spaces', () => {
  40. const viewFragment = dataProcessor.toView( ' first line\n second line' );
  41. expect( stringify( viewFragment ) ).to.equal( '<pre><code>first line\nsecond line</code></pre>' );
  42. } );
  43. it( 'should process multi line code blocks with trailing spaces', () => {
  44. const viewFragment = dataProcessor.toView( ' the lines in this block \n all contain trailing spaces ' );
  45. expect( stringify( viewFragment ) ).to.equal( '<pre><code>the lines in this block \nall contain trailing spaces </code></pre>' );
  46. } );
  47. } );
  48. } );
  49. } );