-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text transformation feature – dashes, "smart" quotes, etc. #1490
Comments
This topic was briefly discussed here: #1366. The short answer is: it probably is possible to implement those transformations using what is already available in autoformat feature but those kinds of transformations weren't on our mind when we created |
Ok. It would be nice to have a ckeditor-typography package, which would do something like this: https://github.com/pnevyk/tipograph I know I could perhaps create it myself, and maybe I will, but if you did it, it would probably be correctly done from the beginning... |
Agree. We actually planned this package and there might've even been a ticket for it (can't find it though). The autoformatting feature is about formatting, so it's a bit different topic. Text transformations would be a separate thing. I'm moving this ticket to the main repo and confirming. |
We were unable to fit this feature in the current iteration, however we added mentions (#998) which included some APIs (most importantly text watcher) that will be helpful while implementing this feature. We're looking to implement it during next iteration. |
@mlewand the text watcher will probably be moved to other place. Also it needs some work to make it more usable - right now it is focused on the Mention feature needs. This should be properly exposed in next iteration. |
@mlewand Some insights about the feature:
Probably we should go with a set of default, most requested options: dashes, quotes, maybe some ligatures for some common things.
The OpenOffice Writer has an AutoCorrect feature which does this and additional things (out of the scope of this feature): The Google docs have it under: Edit: MS Word have those features split to AutoCorrect and Math AutoCorrect : References: |
While implementing a feature some questions camoe out:
|
|
Ad 4: Instead of pattern you can provide RegExp instance. But matching text inside paragraph will not work as we assume that change is done at the caret so the The stuff with RegExp would work but only if we allow custom callback for { from /abc/g, ( wholeTextBeforeCaret ) => return doSomethingWith( wholeTextBeforeCaret ) } but instead of Ad1. The |
regarding 1. Yea, I added this |
@mlewand no I don't wan't to convert RegExp objects - only the Strings which are regex patterns. If someone would like to define: { from: 'CKS', to: 'CKSource' } I'm convinced that we need to create a RegExp like this: new RegExp( 'CKS$' ); so the text watcher (I mean the transformation) will trasnform: Some CKS here and CKS there is CKS[] to Some CKS here and CKS there is CKSource[] and not to: Some CKSource here and CKSource there is CKSource[] This makes sense because one can undo text transformation and thus do not need to worry of the erlier undone transformation to be transformed again. |
So after F2F talk with @mlewand it indeed make no sense to mess with config as I described. The reason behind this was to simplify configuration but at the same time simple strings transformation such as |
Could you sum up, guys, what's the plan for this feature? How will the configuration look like? And how it will be triggered? |
Sure. So if you'd like to fiddle with current state of this there's a PR which implements (use
Still to decide/implement:
For named configurations as see it as group name (ie. For group stubs checkout currently implemented (very limited just to showcase groups): const DEFAULT_TRANSFORMATIONS = [
// Common symbols:
{ from: '(c)', to: '©' },
{ from: '(r)', to: '®' },
{ from: '(tm)', to: '™' },
// Mathematical:
{ from: '1/2', to: '½' },
{ from: '<=', to: '≤' },
// Typography:
{ from: '...', to: '…' },
{ from: ' -- ', to: ' – ' },
{ from: ' --- ', to: ' — ' },
// Quotations:
// English primary.
{ from: buildQuotesRegExp( '"' ), to: '$1“$2”' },
// English secondary.
{ from: buildQuotesRegExp( '\'' ), to: '$1‘$2’' }
]; As you can see there are some rules:
|
@Reinmar and a showcase: |
Feature: Introduced the text transformation feature. Additionally, the `TextWatcher` util was moved to this package from `@ckeditor/ckeditor5-mention`. Closes ckeditor/ckeditor5#1490.
Would this be the correct plugin to handle things like:
Or
Or
If this would be the correct plugin, let's treat this issue as a feature request? Thank you.
The text was updated successfully, but these errors were encountered: