| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /**
- * @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`',
- '<p>regular text and <code>inline code</code></p>'
- );
- } );
- it( 'should properly process multiple code', () => {
- testDataProcessor(
- '`this is code` and this is `too`',
- '<p><code>this is code</code> and this is <code>too</code></p>'
- );
- } );
- it( 'should process spaces inside inline code', () => {
- testDataProcessor(
- 'regular text and` inline code`',
- '<p>regular text and<code>inline code</code></p>',
- // When converting back it will be normalized and spaces
- // at the beginning of inline code will be removed.
- 'regular text and`inline code`'
- );
- } );
- it( 'should properly process backticks inside code spans #1', () => {
- testDataProcessor(
- '`` `backticks` ``',
- '<p><code>`backticks`</code></p>'
- );
- } );
- it( 'should properly process backticks inside code spans #2', () => {
- testDataProcessor(
- '``some `backticks` inside``',
- '<p><code>some `backticks` inside</code></p>'
- );
- } );
- it( 'should process code blocks indented with tabs', () => {
- testDataProcessor(
- ' code block',
- // GitHub is rendering as:
- // <pre><code>code block
- // </code></pre>
- '<pre><code>code block</code></pre>',
- // 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:
- // <pre><code>code block
- // </code></pre>
- '<pre><code>code block</code></pre>',
- // 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:
- // <pre><code>first line
- // second line
- // </code></pre>
- '<pre><code>first line\n' +
- 'second line</code></pre>',
- // 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:
- // <pre><code>first line
- // second line
- // </code></pre>
- '<pre><code>first line\n' +
- 'second line</code></pre>',
- // 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:
- // <pre><code>the lines in this block
- // all contain trailing spaces
- // </code></pre>
- '<pre><code>the lines in this block \n' +
- 'all contain trailing spaces </code></pre>',
- // 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.
- '<pre><code class="language-js">var a = \'hello\';\n' +
- 'console.log(a + \' world\');</code></pre>'
- );
- } );
- 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.
- '<pre><code class="language-bash">#!/bin/bash</code></pre>',
- // 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.
- '<pre><code class="language-js">var a = \'hello\';\n' +
- 'console.log(a + \' world\');</code></pre>',
- // 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.
- '<pre><code class="language-js">var a = \'hello\';\n' +
- 'console.log(a + \' world\');</code></pre>',
- // 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.
- '<pre><code class="language-js"></code></pre>',
- // 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.
- '<pre><code class="language-js"></code></pre>',
- // 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:
- // <p><code>code `` code ```</code></p>
- '<p><code>code `` code ```</code></p>',
- // When converting back ````` will be normalized to ``.
- '`code `` code ``` `'
- );
- } );
- it( 'should handle triple ticks inside code', () => {
- testDataProcessor(
- '````\n' +
- '```\n' +
- 'Code\n' +
- '```\n' +
- '````',
- '<pre><code>' +
- '```\n' +
- 'Code\n' +
- '```' +
- '</code></pre>'
- );
- } );
- it( 'should handle triple and quatruple ticks inside code', () => {
- testDataProcessor(
- '`````\n' +
- '````\n' +
- '```\n' +
- 'Code\n' +
- '```\n' +
- '````\n' +
- '`````',
- '<pre><code>' +
- '````\n' +
- '```\n' +
- 'Code\n' +
- '```\n' +
- '````' +
- '</code></pre>'
- );
- } );
- } );
- } );
|