/** * @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( 'code', () => { it( 'should process inline code', () => { testDataProcessor( 'regular text and `inline code`', '
regular text and inline code
this is code and this is too
regular text and inline code
`backticks`
some `backticks` inside
code block
//
'code block',
// When converting back tabs are normalized to ```.
'```\n' +
'code block\n' +
'```'
);
} );
it( 'should process code blocks indented with spaces', () => {
testDataProcessor(
' code block',
// GitHub is rendering as:
// code block
//
'code block',
// When converting back tabs are normalized to ```.
'```\n' +
'code block\n' +
'```'
);
} );
it( 'should process multi line code blocks indented with tabs', () => {
testDataProcessor(
' first line\n' +
' second line',
// GitHub is rendering as:
// first line
// second line
//
'first line\n' +
'second line',
// When converting back tabs are normalized to ```.
'```\n' +
'first line\n' +
'second line\n' +
'```'
);
} );
it( 'should process multi line code blocks indented with spaces', () => {
testDataProcessor(
' first line\n' +
' second line',
// GitHub is rendering as:
// first line
// second line
//
'first line\n' +
'second line',
// When converting back spaces are normalized to ```.
'```\n' +
'first line\n' +
'second line\n' +
'```'
);
} );
it( 'should process multi line code blocks with trailing spaces', () => {
testDataProcessor(
' the lines in this block \n' +
' all contain trailing spaces ',
// GitHub is rendering as:
// the lines in this block
// all contain trailing spaces
//
'the lines in this block \n' +
'all contain trailing spaces ',
// When converting back tabs are normalized to ```, while the test function remove trailing spaces.
'```\n' +
'the lines in this block\n' +
'all contain trailing spaces\n' +
'```'
);
} );
it( 'should process code block with language name', () => {
testDataProcessor(
'```js\n' +
'var a = \'hello\';\n' +
'console.log(a + \' world\');\n' +
'```',
// GitHub is rendering as special html with syntax highlighting.
// We will need to handle this separately by some feature.
'var a = \'hello\';\n' +
'console.log(a + \' world\');'
);
} );
it( 'should process code block with language name and using ~~~ as delimiter', () => {
testDataProcessor(
'~~~ bash\n' +
'#!/bin/bash\n' +
'~~~',
// GitHub is rendering as special html with syntax highlighting.
// We will need to handle this separately by some feature.
'#!/bin/bash',
// When converting back ~~~ are normalized to ```.
'```bash\n' +
'#!/bin/bash\n' +
'```'
);
} );
it( 'should process code block with language name and using ``````` as delimiter', () => {
testDataProcessor(
'```````js\n' +
'var a = \'hello\';\n' +
'console.log(a + \' world\');\n' +
'```````',
// GitHub is rendering as special html with syntax highlighting.
// We will need to handle this separately by some feature.
'var a = \'hello\';\n' +
'console.log(a + \' world\');',
// When converting back ``````` are normalized to ```.
'```js\n' +
'var a = \'hello\';\n' +
'console.log(a + \' world\');\n' +
'```'
);
} );
it( 'should process code block with language name and using ~~~~~~~~~~ as delimiter', () => {
testDataProcessor(
'~~~~~~~~~~ js\n' +
'var a = \'hello\';\n' +
'console.log(a + \' world\');\n' +
'~~~~~~~~~~',
// GitHub is rendering as special html with syntax highlighting.
// We will need to handle this separately by some feature.
'var a = \'hello\';\n' +
'console.log(a + \' world\');',
// When converting back ~~~~~~~~~~ are normalized to ```.
'```js\n' +
'var a = \'hello\';\n' +
'console.log(a + \' world\');\n' +
'```'
);
} );
it( 'should process empty code block', () => {
testDataProcessor(
'```js\n' +
'```',
// GitHub is rendering as special html with syntax highlighting.
// We will need to handle this separately by some feature.
'',
// When converting back, empty code blocks will be removed.
// This might be an issue when switching from source to editor
// but changing this cannot be done in to-markdown converters.
''
);
} );
it( 'should process code block with empty line', () => {
testDataProcessor(
'```js\n' +
'\n' +
'```',
// GitHub is rendering as special html with syntax highlighting.
// We will need to handle this separately by some feature.
'',
// When converting back, empty code blocks will be removed.
// This might be an issue when switching from source to editor
// but changing this cannot be done in to-markdown converters.
''
);
} );
it( 'should process nested code', () => {
testDataProcessor(
'````` code `` code ``` `````',
// GitHub is rendering as:
// code `` code ```
code `` code ```
' +
'```\n' +
'Code\n' +
'```' +
''
);
} );
it( 'should handle triple and quatruple ticks inside code', () => {
testDataProcessor(
'`````\n' +
'````\n' +
'```\n' +
'Code\n' +
'```\n' +
'````\n' +
'`````',
'' +
'````\n' +
'```\n' +
'Code\n' +
'```\n' +
'````' +
''
);
} );
} );
} );