Skip to content
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

Discussion on how we can better implement document.execCommand(); or feasable workarounds. #3461

Closed
DennisSuitters opened this issue Oct 27, 2019 · 9 comments

Comments

@DennisSuitters
Copy link
Member

As per the title, there has been a lot of issues regarding how some elements are used incorrectly, and elements used that are considered deprecated by the W3C.

As you (reader), would figure, I've been doing a lot of research into this, and have even opened issues with the Chromium (Blink) Team, and tried speaking to members of the Mozilla (Gecko) team about how document.execCommand(); incorrectly uses markup elements.

I've found through various article's, that each Rendering Engine uses their own implementations, for e.g. EdgeHTML will use <strong/> (correct for HTML5) instead of <b/> (deprecated for HTML5 possibly others). Where Gecko (Firefox) uses <b/> (https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand).

And Summernote isn't (obviously) the only editor with this issue (thankfully). I found this https://stackoverflow.com/questions/12158503/definition-of-execcommand-function-for-bold/12166267#12166267 which indicates that CKEditor has created their own workaround, but is licensed, so can't simply be copy/pasted to solve our issues.

So, do we keep pestering Browser Vendors, HTML Rendering Engine developers to fix how their Browser and Rendering Engines interact with DOM Elements? Or do we create workarounds, which will bloat, and make the code, and in turn page slower?

Don't get me wrong, Browser Vendors have done a fantastic job providing software to allow us to view Web Pages, but I believe if they want to preach how they are better than their competition, then they need to fix the underlying API that they allow developers access to, to use the DOM recommended by W3C.

Now, I get that there is backwards compatibility to take into account, then there's Email, and different Document Types that browsers can use, so in that vein, I think they should be using the elements depending on the DocType declared in the Document, which I know they already look at when a page is loaded.

I also find it misleading, that the different browser Development tools are capable of notifying us which DOM Elements, and well as CSS elements are deprecated. It's almost as though the teams developing these tools and software don't even talk to each other.

Anyway, I'm opening this issue, and not just having it as an in-house team only as I know there are a lot of talented contributors that can have valid input.

@DennisSuitters
Copy link
Member Author

Oh, and something that I find ridiculous is that Google, even though they produce and work on Chrome, their own browser-based editor (Google Docs), doesn't use the document.execCommand(); API Function.

@easylogic
Copy link
Member

easylogic commented Oct 27, 2019

@diemendesign I agree with you.

To implement document.execCommand() function, we need a specially document structure for summernote.

For example, as you say, we must can apply strong tag in anytime.
This is able to difference by every browsers and editors both.
It seems to very challenge that implement w3c or summernote spec .

But i want to try this.

The idea is that the Web should no longer be browser-dependent.
The browser will still come out, and the changes we make cannot keep up.
If our document format is clear and in the same direction, I think we can solve many browser-specific issues.

@IgnacioHR
Copy link
Contributor

Now that document.execCommand(); is deprecated, I think it is time to think on alternatives.

Mozilla execCommand, official documentation

Stackoverflow, question

I propose to create an interface to handle the modifications in an abstract way, we could even create an interface just with one method called execCommand, then, we could create concrete implementations of that interface for every DOCTYPE and some defaults...

@DennisSuitters
Copy link
Member Author

DennisSuitters commented Jul 10, 2020

As mentioned in the other issue you commented on @IgnacioHR Moz still refer's back to using execCommand(), as pointed out in the Stackoverflow link provided (thank you). Some research is needed me thinks.
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content

@DennisSuitters
Copy link
Member Author

I found this https://stackoverflow.com/questions/12158503/definition-of-execcommand-function-for-bold/12166267#12166267
Which looks like from one of the CKEditor developers. Maybe we need to do similar.

@IgnacioHR
Copy link
Contributor

IgnacioHR commented Jul 10, 2020 via email

@orchardguides
Copy link

It would be a shame to lose the functionality provided by document.execCommand(). Used properly, this command makes it remarkably easy to create editors that can be used to style HTML documents in highly sophisticated ways.

In my own work, I've been able to develop an online editor that allows users to insert Tables, Lists, and other elements and style these elements in pretty much any manner allowed by CSS. In addition, the editor implements undo/redo works flawlessly. And all of this was accomplished in less than 1,400 lines of HTML, Javascript, and CSS.

If we lose document.execCommand(), I guess that my editor just stops working.

I think the mistake that developers make when using document.execCommand() is that they commit changes to the contenteditable without going through document.execCommand(). Instead, they alter the document using javascript directly. This, of course, messes up the undo/redo functions. When every change is routed through execCommand, every change is automatically registered with undo/redo and a separate mutationObserver is not required.

If you want to see how I insert and format elements such as Tables and Lists using only document.execCommand(), the source code for my project is available at: https://github.com/orchardguides/Kei-HTML-Editor

An online working copy of this editor can also be viewed at http://orchardguides.com/KeiEditor/

@DennisSuitters
Copy link
Member Author

The biggest issue I have with the implementation of document.execCommand(), is each Browser producing different results and implementing it in their own way, which overall isn't such a bad thing how they code it as such. Regardless of how it's coded, the results produced using the function should have the same results output regardless of the Browser used.

Manipulating classes over inline styling is also something that needs addressing as well. Current Javascript (even though each Browser again behaves in it's own way) has new functionality to help greatly with this, which begs the question as to why that functionality hasn't been implemented into the execCommand() seeing as though the new Class manipulation functions are present, mayhaps, they aren't support in all Browser as yet.

@DennisSuitters
Copy link
Member Author

I'm going to close this, as it's something that we are going to have to work on, as the document.execCommand(); even though it's still referenced in documentation by Moz, and possibly others, it is considered deprecated, and we need to take steps to stop using it, as eventually at some future point, Browsers will stop supporting it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants