Python/Javascript: WYSIWYG html editor - Handle large documents fast and/or design theory

喜你入骨 提交于 2020-01-15 05:54:26

问题


Background:

I am writing an ebook editing program in python. Currently it utilizes a source-code view for editing, and I would like to port it over to a wysiwyg view for editing. The best (only?) html renderer I could find for python was webkit (I am using the PyQt version).

Question:

How do I accomplish wysiwyg editing? The requirements/issues are as follows:

  1. An ebook may be up to 10,000 paragraphs / 1,000,000 characters.
    • PyQt Webkit (ContentEditable): No problem.
    • PyQt Webkit (TinyMce, etc): Takes forever to open them!
  2. The format is <body><p>...</p><p>...</p>...</body>. The body element contains only paragraphs, there are no divs, etc (but in the paragraph there may be spans, links, etc.). Editing must take place with no significant delays as far as the user is concerned.
    • PyQt Webkit (ContentEditable): If you try deleting text across multiple paragraphs, it takes forever!! My understanding is that this is because it resets the common-parent of the elements being changed - i.e. the entire body element, since two different paragraphs are being deleted/merged. But, there should be no need for this - it should need only delete/merge/change those individual paragraphs!

I am open to implementing my own wysiwyg editing, but for the life of me I can't figure out how to delete/cut/paste/merge/change the html code correctly. I searched online for articles about html wysiwyg design theory, and came up dry.

Thanks!


回答1:


Can i suggest a complete another approach ? Since your ebook is only <p></p>:

  • Split the text on <p></p> to get an indexed array of all your paragraphs
  • Make your own pagination system, and fill the screen with N paragraphs, that automatically get enough text to show from the indexed array
  • When you are doing selection, you can use [paragraph index + character index in the paragraph] for selection start / end
  • Then implement cut/copy/paste/delete/undo/redo based on thoses assumptions.

(Note: when you'll do a selection, since the start point is saved, you can safely change the text on the screen / pagination, until the selection end.)



来源:https://stackoverflow.com/questions/8412215/python-javascript-wysiwyg-html-editor-handle-large-documents-fast-and-or-desi

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