- Support insertion, modification and deletion of markdown document
- Support entire markdown syntax, possibly more (i.e., github style)
- Easy and intuitive, duh
- Ability to extend, shrink selection range. I.e., manipulate selection programmatically (not included in this document yet)
In my view, there are two ways to go about this problem. The first, is to provide a low-level text editing platform which users can use to implement their own functions to perform three operations outlined above. Second, is to provide a markdown specific API.
It is possible to have both implementations, it just means that the second implementation will use the low-level text editing API itself.
API/function names are not important at this stage, should focus on an approach, then we can come up with the names quite easily as most of the names should be intuitive.
Cross node editing is going to be epic hard.
Here we have a custom selection object:
var selection = editor.getSelection();
var text = selection.getText();
// => Hello (string)
selection.prepend('# ');
// => # Hello
selection.surroundWith('#');
// => # Hello #
selection.surroundWith('**');
// => **Hello** (edits document)
selection.replaceWith('[' + text + '](' + link ')');
// => [Hello](https://github.com)
selection.replaceWith('[text][github]');
editor.append('[github]: https://github.com');
// => [Hello][github]
// => [github]: https://github.com
selection.prependLines('> ');
=> > Hello
selection.prependLines('\t');
selection.prependLines(' ');
selection.indent();
=> Hello
selection.prepend('Oh! ');
// => Oh! Hello
selection.append(' World!');
// => Hello World!
selection.insertAt(2, 'eee');
// => Heeeello
Q: How to handle new lines?
selection.delete();
// =>
The idea here is to expose specific functions to the client such that a single operation is carried out on selection to mutate the current state (of the selection).
Here we have a selection API:
var selection = editor.getSelection();
var text = selection.getText();
// => Hello (string)
selection.bold();
// => **Hello**
// Excuse the ES6 style :P
['italic', 'code'].forEach((style) => selection[style]());
// => *Hello*
// => `Hello`
var url = 'https://github.com';
selection.link(url);
// => [Hello](https://github.com)
This API will indent each line in the selection.
selection.blockquote();
// => > Hello
selection.codeblock();
// => Hello
From other post:
I think initial implementation would only take a few hours of testing (on main browsers). Main fear is implementing work arounds.
Yeah this is totally the way to go. I think I can base this off some of the code I wrote earlier.
Yeah this sounds explorable.
From this post:
How about leave those out for now. We can easily implement them later based off
append
,prepend
. Could even come as a module as you mentioned earlier.Yeah this shouldn't be too more more effort.
I'll start a separate project as a proof of concept, then we can incorporate into the main code base once almost everyone is happy with how the API works. Hard to please everyone nowadays.