瀏覽代碼

Merge branch 'fix-numbered-list' of https://github.com/vladikoff/ckeditor5-autoformat into vladikoff-fix-numbered-list

Szymon Kupś 8 年之前
父節點
當前提交
7197765f35

+ 1 - 1
packages/ckeditor5-autoformat/src/autoformat.js

@@ -54,7 +54,7 @@ export default class Autoformat extends Plugin {
 
 		if ( commands.get( 'numberedList' ) ) {
 			// eslint-disable-next-line no-new
-			new BlockAutoformatEngine( this.editor, /^\d+[.|)]?\s$/, 'numberedList' );
+			new BlockAutoformatEngine( this.editor, /^\d+[.|)]\s$/, 'numberedList' );
 		}
 	}
 

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

@@ -82,7 +82,7 @@ describe( 'Autoformat', () => {
 	} );
 
 	describe( 'Numbered list', () => {
-		it( 'should replace digit with numbered list item', () => {
+		it( 'should replace digit with numbered list item using the dot format', () => {
 			setData( doc, '<paragraph>1.[]</paragraph>' );
 			doc.enqueueChanges( () => {
 				batch.insertText( ' ', doc.selection.getFirstPosition() );
@@ -91,6 +91,24 @@ describe( 'Autoformat', () => {
 			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
 		} );
 
+		it( 'should replace digit with numbered list item using the parenthesis format', () => {
+			setData( doc, '<paragraph>1)[]</paragraph>' );
+			doc.enqueueChanges( () => {
+				batch.insert( doc.selection.getFirstPosition(), ' ' );
+			} );
+
+			expect( getData( doc ) ).to.equal( '<listItem indent="0" type="numbered">[]</listItem>' );
+		} );
+
+		it( 'should not replace digit character when there is no . or ) in the format', () => {
+			setData( doc, '<paragraph>1[]</paragraph>' );
+			doc.enqueueChanges( () => {
+				batch.insert( doc.selection.getFirstPosition(), ' ' );
+			} );
+
+			expect( getData( doc ) ).to.equal( '<paragraph>1 []</paragraph>' );
+		} );
+
 		it( 'should not replace digit character when inside numbered list item', () => {
 			setData( doc, '<listItem indent="0" type="numbered">1.[]</listItem>' );
 			doc.enqueueChanges( () => {

+ 3 - 1
packages/ckeditor5-autoformat/tests/manual/autoformat.md

@@ -6,7 +6,9 @@
 
 1. Type `>` and press the space in an empty paragraph to replace it with a block quote.
 
-1. Type a number from the range **1-3** to replace an empty paragraph with a numbered list item.
+1. Type a number from the range **1-3** followed by a `.` and press space to replace an empty paragraph with a numbered list item.
+
+1. Type a number from the range **1-3** followed by a `)` and press space to replace an empty paragraph with a numbered list item.
 
 1. Type `*foobar*`/`_foobar_` to italicize `foobar`. `*`/`_` should be removed.