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 #28 from ckeditor/t/26
Browse files Browse the repository at this point in the history
Feature: Block quote support. Closes #26.
  • Loading branch information
oleq committed May 18, 2017
2 parents d22c5b6 + 19f6a0d commit 4c1e83e
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 10 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"devDependencies": {
"@ckeditor/ckeditor5-basic-styles": "^0.8.1",
"@ckeditor/ckeditor5-dev-lint": "^3.0.0",
"@ckeditor/ckeditor5-block-quote": "^0.1.1",
"@ckeditor/ckeditor5-editor-classic": "^0.7.3",
"@ckeditor/ckeditor5-enter": "^0.9.1",
"@ckeditor/ckeditor5-heading": "^0.9.1",
Expand Down
15 changes: 15 additions & 0 deletions src/autoformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class Autoformat extends Plugin {
this._addListAutoformats();
this._addBasicStylesAutoformats();
this._addHeadingAutoformats();
this._addBlockQuoteAutoformats();
}

/**
Expand Down Expand Up @@ -155,4 +156,18 @@ export default class Autoformat extends Plugin {
}
}
}

/**
* Adds autoformatting related to {@link module:block-quote/blockquote~BlockQuote}.
* When typed:
* * `> ` - a paragraph will be changed to a block quote.
*
* @private
*/
_addBlockQuoteAutoformats() {
if ( this.editor.commands.has( 'blockQuote' ) ) {
// eslint-disable-next-line no-new
new BlockAutoformatEngine( this.editor, /^>\s$/, 'blockQuote' );
}
}
}
50 changes: 49 additions & 1 deletion tests/autoformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ListEngine from '@ckeditor/ckeditor5-list/src/listengine';
import HeadingEngine from '@ckeditor/ckeditor5-heading/src/headingengine';
import BoldEngine from '@ckeditor/ckeditor5-basic-styles/src/boldengine';
import ItalicEngine from '@ckeditor/ckeditor5-basic-styles/src/italicengine';
import BlockQuoteEngine from '@ckeditor/ckeditor5-block-quote/src/blockquoteengine';
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
import { setData, getData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
Expand All @@ -21,7 +22,7 @@ describe( 'Autoformat', () => {

beforeEach( () => {
return VirtualTestEditor.create( {
plugins: [ Enter, Paragraph, Autoformat, ListEngine, HeadingEngine, BoldEngine, ItalicEngine ]
plugins: [ Enter, Paragraph, Autoformat, ListEngine, HeadingEngine, BoldEngine, ItalicEngine, BlockQuoteEngine ]
} )
.then( newEditor => {
editor = newEditor;
Expand Down Expand Up @@ -108,6 +109,44 @@ describe( 'Autoformat', () => {
} );
} );

describe( 'Block quote', () => {
it( 'should replace greater-than character with heading', () => {
setData( doc, '<paragraph>>[]</paragraph>' );
doc.enqueueChanges( () => {
batch.insert( doc.selection.getFirstPosition(), ' ' );
} );

expect( getData( doc ) ).to.equal( '<blockQuote><paragraph>[]</paragraph></blockQuote>' );
} );

it( 'should not replace greater-than character when inside heading', () => {
setData( doc, '<heading1>>[]</heading1>' );
doc.enqueueChanges( () => {
batch.insert( doc.selection.getFirstPosition(), ' ' );
} );

expect( getData( doc ) ).to.equal( '<heading1>> []</heading1>' );
} );

it( 'should not replace greater-than character when inside numbered list', () => {
setData( doc, '<listItem indent="0" type="numbered">1. >[]</listItem>' );
doc.enqueueChanges( () => {
batch.insert( doc.selection.getFirstPosition(), ' ' );
} );

expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">1. > []</listItem>' );
} );

it( 'should not replace greater-than character when inside buletted list', () => {
setData( doc, '<listItem indent="0" type="bulleted">1. >[]</listItem>' );
doc.enqueueChanges( () => {
batch.insert( doc.selection.getFirstPosition(), ' ' );
} );

expect( getData( doc ) ).to.equal( '<listItem indent="0" type="bulleted">1. > []</listItem>' );
} );
} );

describe( 'Inline autoformat', () => {
it( 'should replace both `**` with bold', () => {
setData( doc, '<paragraph>**foobar*[]</paragraph>' );
Expand Down Expand Up @@ -221,6 +260,15 @@ describe( 'Autoformat', () => {
expect( getData( doc ) ).to.equal( '<paragraph>*foobar*[]</paragraph>' );
} );

it( 'should not replace `>` with block quote', () => {
setData( doc, '<paragraph>>[]</paragraph>' );
doc.enqueueChanges( () => {
batch.insert( doc.selection.getFirstPosition(), ' ' );
} );

expect( getData( doc ) ).to.equal( '<paragraph>> []</paragraph>' );
} );

it( 'should use only configured headings', () => {
return VirtualTestEditor.create( {
plugins: [ Enter, Paragraph, Autoformat, ListEngine, HeadingEngine ],
Expand Down
5 changes: 3 additions & 2 deletions tests/manual/autoformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classic';
import Autoformat from '../../src/autoformat';
import Enter from '@ckeditor/ckeditor5-enter/src/enter';
import List from '@ckeditor/ckeditor5-list/src/list';
import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote';
import Typing from '@ckeditor/ckeditor5-typing/src/typing';
import Heading from '@ckeditor/ckeditor5-heading/src/heading';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
Expand All @@ -17,8 +18,8 @@ import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic';

ClassicEditor.create( document.querySelector( '#editor' ), {
plugins: [ Enter, Typing, Paragraph, Undo, Bold, Italic, Heading, List, Autoformat ],
toolbar: [ 'headings', 'numberedList', 'bulletedList', 'bold', 'italic', 'undo', 'redo' ]
plugins: [ Enter, Typing, Paragraph, Undo, Bold, Italic, Heading, List, Autoformat, BlockQuote ],
toolbar: [ 'headings', 'numberedList', 'bulletedList', 'blockQuote', 'bold', 'italic', 'undo', 'redo' ]
} )
.then( editor => {
window.editor = editor;
Expand Down
16 changes: 9 additions & 7 deletions tests/manual/autoformat.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
## Autoformat

1. Type `#` and press space in empty paragraph to replace it with the heading.
1. Type `#` and press the space in an empty paragraph to replace it with a heading.

2. Type `*` or `-` and press space in empty paragraph to replace it with list item.
1. Type `*` or `-` and the press space in an empty paragraph to replace it with a list item.

3. Type number from the range **1-3** to replace empty paragraph with numbered list item.
1. Type `> ` and press the space in an empty paragraph to replace it with a block quote.

4. Type `*foobar*`/`_foobar_` to italicize `foobar`. `*`/`_` should be removed.
1. Type a number from the range **1-3** to replace an empty paragraph with a numbered list item.

5. Type `**foobar**`/`__foobar__` to bold `foobar`. `**`/`__` should be removed.
1. Type `*foobar*`/`_foobar_` to italicize `foobar`. `*`/`_` should be removed.

6. For every autoformat pattern: Undo until you'll see just the pattern (e.g. `- `). Typing should be then possible without triggering autoformatting again.
1. Type `**foobar**`/`__foobar__` to bold `foobar`. `**`/`__` should be removed.

7. Typing a different pattern in already converted block **must not** trigger autoformatting. For example, typing `- ` in heading should not convert heading to list.
1. For every autoformat pattern: Undo until you'll see just the pattern (e.g. `- `). Typing should be then possible without triggering the autoformatting again.

1. Typing a different pattern in an already converted block **must not** trigger the autoformatting. For example, typing `- ` in a heading should not convert a heading to a list.

0 comments on commit 4c1e83e

Please sign in to comment.