Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #7 from ckeditor/t/ckeditor5/5978
Browse files Browse the repository at this point in the history
Fix: Spell checker is now disabled inside code blocks. Closes ckeditor/ckeditor5#5978.
  • Loading branch information
Reinmar authored Dec 17, 2019
2 parents 4515b26 + 20b3ddc commit cd03e20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ export function modelToViewCodeBlockInsertion( model, languageDefs, useLabels =
const targetViewPosition = mapper.toViewPosition( model.createPositionBefore( data.item ) );
const preAttributes = {};

// The attribute added only in the editing view.
// Attributes added only in the editing view.
if ( useLabels ) {
preAttributes[ 'data-language' ] = languagesToLabels[ codeBlockLanguage ];
preAttributes.spellcheck = 'false';
}

const pre = writer.createContainerElement( 'pre', preAttributes );
Expand Down
18 changes: 12 additions & 6 deletions tests/codeblockediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,13 +575,19 @@ describe( 'CodeBlockEditing', () => {
it( 'should convert empty codeBlock to empty pre tag', () => {
setModelData( model, '<codeBlock language="plaintext"></codeBlock>' );

expect( getViewData( view ) ).to.equal( '<pre data-language="Plain text"><code class="language-plaintext">[]</code></pre>' );
expect( getViewData( view ) ).to.equal(
'<pre data-language="Plain text" spellcheck="false">' +
'<code class="language-plaintext">[]</code>' +
'</pre>' );
} );

it( 'should convert non-empty codeBlock to pre tag', () => {
setModelData( model, '<codeBlock language="plaintext">Foo</codeBlock>' );

expect( getViewData( view ) ).to.equal( '<pre data-language="Plain text"><code class="language-plaintext">{}Foo</code></pre>' );
expect( getViewData( view ) ).to.equal(
'<pre data-language="Plain text" spellcheck="false">' +
'<code class="language-plaintext">{}Foo</code>' +
'</pre>' );
} );

it( 'should convert codeBlock with softBreaks to pre tag #1', () => {
Expand All @@ -594,7 +600,7 @@ describe( 'CodeBlockEditing', () => {
);

expect( getViewData( view ) ).to.equal(
'<pre data-language="Plain text">' +
'<pre data-language="Plain text" spellcheck="false">' +
'<code class="language-plaintext">{}Foo<br></br>Bar<br></br>Biz</code>' +
'</pre>' );
} );
Expand All @@ -611,7 +617,7 @@ describe( 'CodeBlockEditing', () => {
);

expect( getViewData( view ) ).to.equal(
'<pre data-language="Plain text">' +
'<pre data-language="Plain text" spellcheck="false">' +
'<code class="language-plaintext">[]<br></br><br></br>Foo<br></br><br></br></code>' +
'</pre>' );
} );
Expand All @@ -635,7 +641,7 @@ describe( 'CodeBlockEditing', () => {
);

expect( getViewData( view ) ).to.equal(
'<pre data-language="Zwykły tekst">' +
'<pre data-language="Zwykły tekst" spellcheck="false">' +
'<code class="language-plaintext">{}foo</code>' +
'</pre>' );

Expand Down Expand Up @@ -666,7 +672,7 @@ describe( 'CodeBlockEditing', () => {
setModelData( model, '<codeBlock language="cpp">foo</codeBlock>' );

expect( getViewData( view ) ).to.equal(
'<pre data-language="C++">' +
'<pre data-language="C++" spellcheck="false">' +
'<code>{}foo</code>' +
'</pre>' );

Expand Down

0 comments on commit cd03e20

Please sign in to comment.