Ckeditor5: Create autoformatting engine and command with default config

Created on 4 Oct 2016  路  14Comments  路  Source: ckeditor/ckeditor5

Create lists/headings when line started with # or * or \d. In the future should also create blockquotes.

It should be considered that this feature should not directly require other (link, heading, blockquote) features to exist. So integration must be performed very loosely. Either through a config (e.g. regexp/callback => command/callback) or a set of micro features (which, at this point, can require the link, heading, blockquote ones) which enable the autoformatting for their specific case.

If the engine of the autoformatter will be implemented correctly, the second idea (with specified classes) should be as doable as the declarative config. So the first thing to work on will be a flexible engine.

autoformat feature

Most helpful comment

What's wrong with behaviour "3"? How often you'd type "1. " at the beginning of a bulleted list? ;)

  • 1.09.1939 - wybuch II wojny 艣wiatowej

:P

All 14 comments

When I remove prefix /#{1,3}/, I get error because function transform fails to get end property in argument range:

https://github.com/ckeditor/ckeditor5-engine/blob/master/src/model/liveposition.js#L149

This needs a further check, even though I "fixed" it by checking the existence of the end property. Any knowledge about a similar issue would be valuable.

Above problem was reported (https://github.com/ckeditor/ckeditor5-engine/issues/624) and fixed.

Some problems were solved and a couple of updates were made to other features to make Autoformat feature work.
But now, when there finally is a non-breaking example, I can clearly see that there is one flaw in our assumed structure of Autoformat. When, for example, I create numbered list, I still can invoke pattern for heading or bulleted list.

I think, that instead of separate new AutoformatEngine(...) calls we should create single AutoformatEngine and add patterns to that instance.
When a pattern is matched, we should "ask" other patterns to check if they are already applied to processed element.

This is not going to work (at least, not always). Features are independent of each other. It's only a convenience why we define Autoformat feature. But the engine can be then used by other features to add their new formatting experience.

But, in fact, I should first ask what's the actual TC? Because I don't see conflicts between those features. They should have exclusive regexp patterns and that's it.

As a TC I wrote:

When, for example, I create numbered list, I still can invoke pattern for heading or bulleted list.

Or in details (apostrophes added to stop MD from trimming spaces):

  1. Type '- ' and Autoformat changes current paragraph to bulleted list,
  2. When you try to type '- ' again, nothing will happen, because I check if we are already in the bulleted list,
  3. Type '1. ' in that bulleted item, Autoformat fires and changes bulleted item to numbered item.

My first idea how to solve it is to make Autoformat aware of patterns and provide with each pattern a check function to check if that particular pattern was applied in current paragraph.

So each feature provides a pattern, callback, and check function. This way every feature is still separated, but Autoformat has all the "tools" to decide when to apply formatting and when not.

What's wrong with behaviour "3"? How often you'd type "1. " at the beginning of a bulleted list? ;)

The same thing will happen with # and all future Autoformat patterns. If you think this is a minor issue, I will happily continue my work without worrying about it. :)

I think this is ok for now. We need MVP and we'll be able to see it in action. However, this is super clear that the support for undo must be correct, so such unwanted autoformatting can be undone.

Do you see any obvious situation where typing # at the beginning of heading is common? Because right now it will work like a toggle mechanism. I guess this should be fixed.

What's wrong with behaviour "3"? How often you'd type "1. " at the beginning of a bulleted list? ;)

  • 1.09.1939 - wybuch II wojny 艣wiatowej

:P

There's no space after "1." in "1.09" ;)

Besides, you can always undo that step!

Besides2, we can change this behaviour easily to only work in paragraphs. Let's have a working solution first, though.

List of recent changes:

  • Simplified Autoformat feature,

    • Moved branch.remove() to AutoformatEngine,

    • Removed callbacks in favor of simple command names,

  • Removed loop checking every changed element in change event,
  • Removed needlessly complicated range creation,
  • Removed useless callback parameters,
  • Restricted Autoformat to work only in paragraphs,
  • Removed dead branches of code, that showed up after adding check above,
  • Updated tests.

TODO: After closing the ticket package.json in ckeditor5 should be updated with this package.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jodator picture jodator  路  3Comments

oleq picture oleq  路  3Comments

hybridpicker picture hybridpicker  路  3Comments

benjismith picture benjismith  路  3Comments

wwalc picture wwalc  路  3Comments