Browse Source

Added block quote autoformatting.

Szymon Kupś 8 years ago
parent
commit
aa243e546b

+ 1 - 0
packages/ckeditor5-autoformat/package.json

@@ -9,6 +9,7 @@
   },
   "devDependencies": {
     "@ckeditor/ckeditor5-basic-styles": "^0.8.1",
+    "@ckeditor/ckeditor5-block-quote": "^0.1.1",
     "@ckeditor/ckeditor5-dev-lint": "^2.0.2",
     "@ckeditor/ckeditor5-editor-classic": "^0.7.3",
     "@ckeditor/ckeditor5-enter": "^0.9.1",

+ 7 - 0
packages/ckeditor5-autoformat/src/autoformat.js

@@ -64,6 +64,7 @@ export default class Autoformat extends Plugin {
 		this._addListAutoformats();
 		this._addBasicStylesAutoformats();
 		this._addHeadingAutoformats();
+		this._addBlockQuoteAutoformats();
 	}
 
 	/**
@@ -145,4 +146,10 @@ export default class Autoformat extends Plugin {
 			}
 		}
 	}
+
+	_addBlockQuoteAutoformats() {
+		if ( this.editor.commands.has( 'blockQuote' ) ) {
+			new BlockAutoformatEngine( this.editor, /^>\s$/, 'blockQuote' );
+		}
+	}
 }

+ 31 - 1
packages/ckeditor5-autoformat/tests/autoformat.js

@@ -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';
@@ -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;
@@ -108,6 +109,26 @@ 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>' );
+		} );
+	} );
+
 	describe( 'Inline autoformat', () => {
 		it( 'should replace both `**` with bold', () => {
 			setData( doc, '<paragraph>**foobar*[]</paragraph>' );
@@ -221,6 +242,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 ],

+ 3 - 2
packages/ckeditor5-autoformat/tests/manual/autoformat.js

@@ -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';
@@ -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;

+ 8 - 6
packages/ckeditor5-autoformat/tests/manual/autoformat.md

@@ -2,15 +2,17 @@
 
 1. Type `#` and press space in empty paragraph to replace it with the heading.
 
-2. Type `*` or `-` and press space in empty paragraph to replace it with list item.
+1. Type `*` or `-` and press space in empty paragraph to replace it with list item.
 
-3. Type number from the range **1-3** to replace empty paragraph with numbered list item.
+1. Type `> ` and press space in empty paragraph to replace it with block quote.
 
-4. Type `*foobar*`/`_foobar_` to italicize `foobar`. `*`/`_` should be removed.
+1. Type number from the range **1-3** to replace empty paragraph with 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 autoformatting again.
+
+1. Typing a different pattern in already converted block **must not** trigger autoformatting. For example, typing `- ` in heading should not convert heading to list.