links.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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( 'links', () => {
  13. describe( 'toView', () => {
  14. it( 'should autolink', () => {
  15. const viewFragment = dataProcessor.toView( 'Link: <http://example.com/>.' );
  16. expect( stringify( viewFragment ) ).to.equal( '<p>Link: <a href="http://example.com/">http://example.com/</a>.</p>' );
  17. } );
  18. it( 'should autolink #2', () => {
  19. const viewFragment = dataProcessor.toView( 'Link: http://example.com/.' );
  20. expect( stringify( viewFragment ) ).to.equal( '<p>Link: <a href="http://example.com/">http://example.com/</a>.</p>' );
  21. } );
  22. it( 'should autolink with params', () => {
  23. const viewFragment = dataProcessor.toView( 'Link: <http://example.com/?foo=1&bar=2>.' );
  24. expect( stringify( viewFragment ) ).to.equal(
  25. '<p>Link: <a href="http://example.com/?foo=1&bar=2">http://example.com/?foo=1&bar=2</a>.</p>'
  26. );
  27. } );
  28. it( 'should autolink inside list', () => {
  29. const viewFragment = dataProcessor.toView( '* <http://example.com/>' );
  30. expect( stringify( viewFragment ) ).to.equal(
  31. '<ul>' +
  32. '<li><a href="http://example.com/">http://example.com/</a></li>' +
  33. '</ul>'
  34. );
  35. } );
  36. it( 'should autolink inside blockquote', () => {
  37. const viewFragment = dataProcessor.toView( '> Blockquoted: <http://example.com/>' );
  38. expect( stringify( viewFragment ) ).to.equal(
  39. '<blockquote>' +
  40. '<p>Blockquoted: <a href="http://example.com/">http://example.com/</a></p>' +
  41. '</blockquote>'
  42. );
  43. } );
  44. it( 'should not autolink inside inline code', () => {
  45. const viewFragment = dataProcessor.toView( '`<http://example.com/>`' );
  46. expect( stringify( viewFragment ) ).to.equal( '<p><code><http://example.com/></code></p>' );
  47. } );
  48. it( 'should not autolink inside code block', () => {
  49. const viewFragment = dataProcessor.toView( ' <http://example.com/>' );
  50. expect( stringify( viewFragment ) ).to.equal( '<pre><code><http://example.com/></code></pre>' );
  51. } );
  52. } );
  53. } );
  54. } );