Definition of ExecCommand function for bold?

空扰寡人 提交于 2019-11-30 15:40:14

I see that CKEditor was mentioned in one of previous comments :) So this is how we handle executing commands:

  • We do everything manually. As you can see DOM API isn't sufficient and implementations differ between browsers, so I guess (but I haven't checked this) that HTML containing some text with applied styles in one browser won't work in other (because one browser applied strong and second b or span with inline style).
  • First of all we need custom Range and Selection implementations. You can't use them, but there's a cool Rangy lib.
  • Next component that you need is set of methods for applying, removing and checking styles. Here's our impl.
  • And the last component is trivial - custom commands, because it's convenient to mimic W3C's APIs and ideas.

I researched this problem a year ago and could not found any solution except using regex instead EC on nested tags. I developted my text editor without using ExecCommand.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!