Browse Source

Merge pull request #28 from ckeditor/t/26

Feature: Block quote support. Closes #26.
Aleksander Nowodzinski 8 years ago
parent
commit
39101bdd82

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

@@ -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",

+ 15 - 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();
 	}
 
 	/**
@@ -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' );
+		}
+	}
 }

+ 49 - 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,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>' );
@@ -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 ],

+ 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;

+ 9 - 7
packages/ckeditor5-autoformat/tests/manual/autoformat.md

@@ -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.