- 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
Some notes:
bold
,italic
,blockquote
, etc are really nice to have, but EpicEditor supports replacing your editor with any parser. If you did this you'd have to provide an API for setting what ablockquote
means in, lets say, wiki.#2 is less important, but would be really cool. Because we could implement #1 as a selection extension for Markdown.