Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ckeditor/ckeditor5-autoformat

Package Overview
Dependencies
Maintainers
1
Versions
712
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-autoformat - npm Package Compare versions

Comparing version 10.0.4 to 11.0.0

12

CHANGELOG.md
Changelog
=========
## [11.0.0](https://github.com/ckeditor/ckeditor5-autoformat/compare/v10.0.4...v11.0.0) (2019-02-28)
### Features
* `BlockAutoformatEditing` will not format the text if the command is disabled. `InlineAutoformatEditing` will not format the text if the callback returned `false`. Closes [#64](https://github.com/ckeditor/ckeditor5-autoformat/issues/64). ([cc7f454](https://github.com/ckeditor/ckeditor5-autoformat/commit/cc7f454))
* Cancel `BlockAutoformatEditing` autoformatting if given callback returned `false`. Closes [#66](https://github.com/ckeditor/ckeditor5-autoformat/issues/66). ([9b066f1](https://github.com/ckeditor/ckeditor5-autoformat/commit/9b066f1))
### BREAKING CHANGES
* Upgraded minimal versions of Node to `8.0.0` and npm to `5.7.1`. See: [ckeditor/ckeditor5#1507](https://github.com/ckeditor/ckeditor5/issues/1507). ([612ea3c](https://github.com/ckeditor/ckeditor5-cloud-services/commit/612ea3c))
## [10.0.4](https://github.com/ckeditor/ckeditor5-autoformat/compare/v10.0.3...v10.0.4) (2018-12-05)

@@ -5,0 +17,0 @@

2

LICENSE.md

@@ -5,3 +5,3 @@ Software License Agreement

**ckeditor5-autoformat** – https://github.com/ckeditor/ckeditor5-autoformat <br>
Copyright (c) 2003-2018, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
Copyright (c) 2003-2019, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.

@@ -8,0 +8,0 @@ Licensed under the terms of [GNU General Public License Version 2 or later](http://www.gnu.org/licenses/gpl.html).

{
"name": "@ckeditor/ckeditor5-autoformat",
"version": "10.0.4",
"version": "11.0.0",
"description": "Autoformatting feature for CKEditor 5.",

@@ -13,28 +13,28 @@ "keywords": [

"dependencies": {
"@ckeditor/ckeditor5-core": "^11.1.0"
"@ckeditor/ckeditor5-core": "^12.0.0"
},
"devDependencies": {
"@ckeditor/ckeditor5-basic-styles": "^10.1.0",
"@ckeditor/ckeditor5-block-quote": "^10.1.1",
"@ckeditor/ckeditor5-cloud-services": "^10.1.1",
"@ckeditor/ckeditor5-editor-classic": "^11.0.2",
"@ckeditor/ckeditor5-engine": "^12.0.0",
"@ckeditor/ckeditor5-enter": "^10.1.3",
"@ckeditor/ckeditor5-heading": "^10.1.1",
"@ckeditor/ckeditor5-list": "^11.0.3",
"@ckeditor/ckeditor5-paragraph": "^10.0.4",
"@ckeditor/ckeditor5-typing": "^11.0.2",
"@ckeditor/ckeditor5-undo": "^10.0.4",
"@ckeditor/ckeditor5-basic-styles": "^11.0.0",
"@ckeditor/ckeditor5-block-quote": "^11.0.0",
"@ckeditor/ckeditor5-cloud-services": "^11.0.0",
"@ckeditor/ckeditor5-editor-classic": "^12.0.0",
"@ckeditor/ckeditor5-engine": "^13.0.0",
"@ckeditor/ckeditor5-enter": "^11.0.0",
"@ckeditor/ckeditor5-heading": "^11.0.0",
"@ckeditor/ckeditor5-list": "^12.0.0",
"@ckeditor/ckeditor5-paragraph": "^11.0.0",
"@ckeditor/ckeditor5-typing": "^12.0.0",
"@ckeditor/ckeditor5-undo": "^11.0.0",
"eslint": "^5.5.0",
"eslint-config-ckeditor5": "^1.0.7",
"husky": "^0.14.3",
"eslint-config-ckeditor5": "^1.0.11",
"husky": "^1.3.1",
"lint-staged": "^7.0.0"
},
"engines": {
"node": ">=6.9.0",
"npm": ">=3.0.0"
"node": ">=8.0.0",
"npm": ">=5.7.1"
},
"author": "CKSource (http://cksource.com/)",
"license": "GPL-2.0-or-later",
"homepage": "https://ckeditor.com",
"homepage": "https://ckeditor.com/ckeditor-5",
"bugs": "https://github.com/ckeditor/ckeditor5-autoformat/issues",

@@ -51,4 +51,3 @@ "repository": {

"scripts": {
"lint": "eslint --quiet '**/*.js'",
"precommit": "lint-staged"
"lint": "eslint --quiet '**/*.js'"
},

@@ -63,3 +62,8 @@ "lint-staged": {

"packages/**"
]
],
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
}
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.

@@ -81,4 +81,6 @@ */

/* eslint-disable no-new */
new InlineAutoformatEditing( this.editor, /(\*\*)([^*]+)(\*\*)$/g, 'bold' );
new InlineAutoformatEditing( this.editor, /(__)([^_]+)(__)$/g, 'bold' );
const boldCallback = getCallbackFunctionForInlineAutoformat( this.editor, 'bold' );
new InlineAutoformatEditing( this.editor, /(\*\*)([^*]+)(\*\*)$/g, boldCallback );
new InlineAutoformatEditing( this.editor, /(__)([^_]+)(__)$/g, boldCallback );
/* eslint-enable no-new */

@@ -88,8 +90,9 @@ }

if ( commands.get( 'italic' ) ) {
/* eslint-disable no-new */
const italicCallback = getCallbackFunctionForInlineAutoformat( this.editor, 'italic' );
// The italic autoformatter cannot be triggered by the bold markers, so we need to check the
// text before the pattern (e.g. `(?:^|[^\*])`).
/* eslint-disable no-new */
new InlineAutoformatEditing( this.editor, /(?:^|[^*])(\*)([^*_]+)(\*)$/g, 'italic' );
new InlineAutoformatEditing( this.editor, /(?:^|[^_])(_)([^_]+)(_)$/g, 'italic' );
new InlineAutoformatEditing( this.editor, /(?:^|[^*])(\*)([^*_]+)(\*)$/g, italicCallback );
new InlineAutoformatEditing( this.editor, /(?:^|[^_])(_)([^_]+)(_)$/g, italicCallback );
/* eslint-enable no-new */

@@ -100,3 +103,5 @@ }

/* eslint-disable no-new */
new InlineAutoformatEditing( this.editor, /(`)([^`]+)(`)$/g, 'code' );
const codeCallback = getCallbackFunctionForInlineAutoformat( this.editor, 'code' );
new InlineAutoformatEditing( this.editor, /(`)([^`]+)(`)$/g, codeCallback );
/* eslint-enable no-new */

@@ -129,2 +134,6 @@ }

new BlockAutoformatEditing( this.editor, pattern, () => {
if ( !command.isEnabled ) {
return false;
}
this.editor.execute( 'heading', { value: commandValue } );

@@ -151,1 +160,26 @@ } );

}
// Helper function for getting `InlineAutoformatEditing` callbacks that checks if command is enabled.
//
// @param {module:core/editor/editor~Editor} editor
// @param {String} attributeKey
// @returns {Function}
function getCallbackFunctionForInlineAutoformat( editor, attributeKey ) {
return ( writer, rangesToFormat ) => {
const command = editor.commands.get( attributeKey );
if ( !command.isEnabled ) {
return false;
}
const validRanges = editor.model.schema.getValidRanges( rangesToFormat, attributeKey );
for ( const range of validRanges ) {
writer.setAttribute( attributeKey, true, range );
}
// After applying attribute to the text, remove given attribute from the selection.
// This way user is able to type a text without attribute used by auto formatter.
writer.removeSelectionAttribute( attributeKey );
};
}
/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.

@@ -10,2 +10,4 @@ */

import LiveRange from '@ckeditor/ckeditor5-engine/src/model/liverange';
/**

@@ -30,3 +32,3 @@ * The block autoformatting engine. It allows to format various block patterns. For example,

*
* To convert a paragraph to heading 1 when `- ` is typed, using just the commmand name:
* To convert a paragraph to heading 1 when `- ` is typed, using just the command name:
*

@@ -54,2 +56,3 @@ * new BlockAutoformatEditing( editor, /^\- $/, 'heading1' );

let callback;
let command = null;

@@ -60,6 +63,6 @@ if ( typeof callbackOrCommand == 'function' ) {

// We assume that the actual command name was provided.
const command = callbackOrCommand;
command = editor.commands.get( callbackOrCommand );
callback = () => {
editor.execute( command );
editor.execute( callbackOrCommand );
};

@@ -69,2 +72,6 @@ }

editor.model.document.on( 'change', ( evt, batch ) => {
if ( command && !command.isEnabled ) {
return;
}
if ( batch.type == 'transparent' ) {

@@ -81,2 +88,3 @@ return;

}
const item = entry.position.textNode || entry.position.nodeAfter;

@@ -99,8 +107,12 @@

const end = writer.createPositionAt( item.parent, match[ 0 ].length );
const range = writer.createRange( start, end );
const range = new LiveRange( start, end );
const wasChanged = callback( { match } );
// Remove matched text.
writer.remove( range );
if ( wasChanged !== false ) {
writer.remove( range );
}
callback( { match } );
range.detach();
} );

@@ -107,0 +119,0 @@ } );

/**
* @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
* @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.

@@ -55,3 +55,3 @@ */

* @param {Function|String} attributeOrCallback The name of attribute to apply on matching text or a callback for manual
* formatting.
* formatting. If callback is passed it should return `false` if changes should not be applied (e.g. if a command is disabled).
*

@@ -62,5 +62,13 @@ * // Use attribute name:

* // Use formatting callback:
* new InlineAutoformatEditing( editor, /(\*\*)([^\*]+?)(\*\*)$/g, ( writer, validRanges ) => {
* new InlineAutoformatEditing( editor, /(\*\*)([^\*]+?)(\*\*)$/g, ( writer, rangesToFormat ) => {
* const command = editor.commands.get( 'bold' );
*
* if ( !command.isEnabled ) {
* return false;
* }
*
* const validRanges = editor.model.schema.getValidRanges( rangesToFormat, 'bold' );
*
* for ( let range of validRanges ) {
* writer.setAttribute( command, true, range );
* writer.setAttribute( 'bold', true, range );
* }

@@ -133,3 +141,5 @@ * } );

// A format callback run on matched text.
formatCallback = formatCallback || ( ( writer, validRanges ) => {
formatCallback = formatCallback || ( ( writer, rangesToFormat ) => {
const validRanges = editor.model.schema.getValidRanges( rangesToFormat, attributeKey );
for ( const range of validRanges ) {

@@ -176,7 +186,10 @@ writer.setAttribute( attributeKey, true, range );

editor.model.enqueueChange( writer => {
const validRanges = editor.model.schema.getValidRanges( rangesToFormat, attributeKey );
// Apply format.
formatCallback( writer, validRanges );
const hasChanged = formatCallback( writer, rangesToFormat );
// Strict check on `false` to have backward compatibility (when callbacks were returning `undefined`).
if ( hasChanged === false ) {
return;
}
// Remove delimiters - use reversed order to not mix the offsets while removing.

@@ -183,0 +196,0 @@ for ( const range of rangesToRemove.reverse() ) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc