I am building an amateur rich text editor with vanilla JavaScript and document.execCommand() is essential to enabling the core features of an text editor.
For example bold, italic and unordered list commands:
Array.from(toolbarBtn).forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
if (e.target.id === "toolbar__btn--bold") {
format('bold');
}
if (e.target.id === "toolbar__btn--italic") {
format('italic');
}
if (e.target.id === "toolbar__btn--unorderedlist") {
format('insertunorderedlist');
}
});
});
However, when looking up this command on MDN Web Docs, I saw that this command is considered to be obsolete:
Obsolete This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
So, I'm wondering are there any replacement method in vanilla JavaScript, that could create all the Rich Text Editor features like execCommand() does?
The Google search gave me no results, so at the same time, I wonder, how is that possible that the method is announced to be obsolete, but no alternative is suggested.