/** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ import { testDataProcessor } from '../_utils/utils'; describe( 'GFMDataProcessor', () => { describe( 'links', () => { it( 'should not autolink', () => { testDataProcessor( 'Link: http://example.com/.', '
Link: http://example.com/.
' ); } ); it( 'should not autolink with params', () => { testDataProcessor( 'Link: http://example.com/?foo=1&bar=2.', 'Link: http://example.com/?foo=1&bar=2.
' ); } ); it( 'should not autolink inside list', () => { testDataProcessor( '* http://example.com/', '' + '', ); } ); it( 'should not autolink inside inline code', () => { testDataProcessor( '`Blockquoted: http://example.com/
' + '
',
// When converting back, code block will be normalized to ```.
'```\n' +
'Already linked: http://example.com/
' ); } ); it( 'should not process already linked #2', () => { testDataProcessor( 'Already linked: [**http://example.com/**](http://example.com/)', 'Already linked: http://example.com/
' ); } ); it( 'should process inline links', () => { testDataProcessor( '[URL](/url/)', '' ); } ); it( 'should process inline links with title', () => { testDataProcessor( '[URL and title](/url/ "title")', '' ); } ); it( 'should process inline links with title preceded by two spaces', () => { testDataProcessor( '[URL and title](/url/ "title preceded by two spaces")', '', // When converting back spaces will be normalized to one space. '[URL and title](/url/ "title preceded by two spaces")' ); } ); it( 'should process inline links with title preceded by tab', () => { testDataProcessor( '[URL and title](/url/ "title preceded by tab")', '', // When converting back tab will be normalized to one space. '[URL and title](/url/ "title preceded by tab")' ); } ); it( 'should process inline links with title that has spaces afterwards', () => { testDataProcessor( '[URL and title](/url/ "title has spaces afterward" )', '', // When converting back spaces will be removed. '[URL and title](/url/ "title has spaces afterward")' ); } ); // it( 'should process empty link', () => { // testDataProcessor( // '[Empty]()', // // '' // ); // } ); it( 'should process reference links', () => { testDataProcessor( 'Foo [bar][1].\n\n' + '[1]: /url/ "Title"', 'Foo bar.
', // After converting back reference links will be converted to normal links. // This might be a problem when switching between source and editor. 'Foo [bar](/url/ "Title").' ); } ); it( 'should process reference links - without space', () => { testDataProcessor( 'Foo [bar][1].\n\n' + '[1]: /url/ "Title"', 'Foo bar.
', 'Foo [bar](/url/ "Title").' ); } ); it( 'should process reference links - with embedded brackets', () => { testDataProcessor( 'With [embedded [brackets]][b].\n\n' + '[b]: /url/', 'With embedded [brackets].
', 'With [embedded \\[brackets\\]](/url/).' ); } ); it( 'should process reference links - with reference indented once', () => { testDataProcessor( 'Indented [once][].\n\n' + ' [once]: /url', 'Indented once.
', 'Indented [once](/url).' ); } ); it( 'should process reference links - with reference indented twice', () => { testDataProcessor( 'Indented [twice][].\n\n' + ' [twice]: /url', 'Indented twice.
', 'Indented [twice](/url).' ); } ); it( 'should process reference links - with reference indented three times', () => { testDataProcessor( 'Indented [trice][].\n\n' + ' [trice]: /url', 'Indented trice.
', 'Indented [trice](/url).' ); } ); it( 'should process reference links when title and reference are same #1', () => { testDataProcessor( '[this][this]\n\n' + '[this]: foo', '', '[this](foo)' ); } ); it( 'should process reference links when title and reference are same #2', () => { testDataProcessor( '[this][this]\n\n' + '[this]: foo', '', '[this](foo)' ); } ); it( 'should process reference links when only title is provided and is same as reference #1', () => { testDataProcessor( '[this][]\n\n' + '[this]: foo', '', '[this](foo)' ); } ); it( 'should process reference links when only title is provided and is same as reference #2', () => { testDataProcessor( '[this][]\n\n' + '[this]: foo', '', '[this](foo)' ); } ); it( 'should process reference links when only title is provided and is same as reference #3', () => { testDataProcessor( '[this]\n\n' + '[this]: foo', '', '[this](foo)' ); } ); it( 'should not process reference links when reference is not found #1', () => { testDataProcessor( '[this][]', '[this][]
', '\\[this\\]\\[\\]' ); } ); it( 'should not process reference links when reference is not found #2', () => { testDataProcessor( '[this]', '[this]
', '\\[this\\]' ); } ); it( 'should process reference links nested in brackets #1', () => { testDataProcessor( '[a reference inside [this][]]\n\n' + '[this]: foo', '[a reference inside this]
', '\\[a reference inside [this](foo)\\]' ); } ); it( 'should process reference links nested in brackets #2', () => { testDataProcessor( '[a reference inside [this]]\n\n' + '[this]: foo', '[a reference inside this]
', '\\[a reference inside [this](foo)\\]' ); } ); it( 'should not process reference links when title is same as reference but reference is different', () => { testDataProcessor( '[this](/something/else/)\n\n' + '[this]: foo', '', '[this](/something/else/)' ); } ); it( 'should not process reference links suppressed by backslashes', () => { testDataProcessor( 'Suppress \\[this] and [this\\].\n\n' + '[this]: foo', 'Suppress [this] and [this].
', 'Suppress \\[this\\] and \\[this\\].' ); } ); it( 'should process reference links when used across multiple lines #1', () => { testDataProcessor( 'This is [multiline\n' + 'reference]\n\n' + '[multiline reference]: foo', 'This is multiline
reference
This is multiline
reference