Sigil-Ebook / PageEdit

ePub XHTML Visual Editor
GNU General Public License v3.0
245 stars 28 forks source link

Nested unordered lists not created correctly #20

Closed jpbrown-15 closed 4 years ago

jpbrown-15 commented 4 years ago

When creating a nested unordered list from text, PageEdit creates the following logical structure:

<ul>
          <li></li>
          <ul>
                    <li></li>
          </ul>
</ul>

The nested ul has a parent of ul which violates the specification (and causes a failure with EpubCheck for epub 3.0 files). The child ul should be a child of li and therefore the closing /li tag is in the wrong location. The closing /li tag should follow the closure of the child /ul.

The correct structure should be:

<ul>
          <li>
                   <ul>
                              <li></li>
                   </ul>
          </li>
</ul>

Once the /li closing tag is moved after the child /ul tag, the file will pass the EpubCheck.

kevinhendricks commented 4 years ago

Exactly which lines of text were selected and where exactly the cursor was positioned when pressing the icon determines the nesting. This function is DOM execCommand and is internal to WebEngine and is not under our control.

kevinhendricks commented 4 years ago

FWIW, If you are worried about code passing epubcheck as opposed to just working in most browsers, PageEdit is probably not the tool to use as live DOM editing can and does often mess up. So either use something like Sigil and save PageEfit for minor editing tasks and proofing and not epub creation, unless you plan to use Sigil or the PageEdit Inspector to cleanup the resulting code.

kevinhendricks commented 4 years ago

Closing this as "can not fix" since the fix itself would be internal to either QtWebEngine or Chrome itself.

jpbrown-15 commented 4 years ago

Sorry, maybe I misunderstand the role of Sigil and PageEdit. I thought Sigil was intended to allow you to create epub documents and PageEdit to give you a visual gui to structure the xhtml so you didn't have to hand code it (the functionality that used to be part of Sigil).

I was simply trying to use Sigil to create a well formed epub that conformed to the specification. So, I added content in by using Sigil to create a new xhtml file. I then configured Sigil to launch PageEdit as the xhtml editor. Using content I had created in another app, I pasted only the text into PageEdit's window and then applied the bullet list to a portion of the selected text. Bullets were created. I then selected a subset of the bulleted text and clicked the button to indent it, causing a nested unordered list. A subsection of the text was indented and shows the new bullet font. That all works for rendering.

Saving the xhtml in PageEdit and closing the window, I then returned to Sigil. At this point, you can see the closing of the li and ul elements is not correct for nested ul tags. From here you can run the EpubCheck plugin (if installed) which had a problem with the ul nesting structure. Or, if you don't have the plugin installed, you can use the website: http://validator.idpf.org/ or you can download epubcheck zip and run it from the command line. All produce the same error stating: ERROR(RSC-005): Error while parsing file: element "ul" not allowed here; expected the element end-tag or element "li", "script" or "template"

Yes, manually editing the xhtml via Sigil to move the closing li to after the nested ul closing tag does allow it to pass the EpubCheck plugin. That's what I did.

So, this wasn't about display of the xhtml, it was about how PageEdit produced the xhtml surrounding the nesting of ul tags. I wouldn't think this has anything to do with QtWebEngine or Chrome, but then again, perhaps I don't understand what PageEdit's role is and what it uses external libraries to do.

Is there an alternate tool that you use and launch from Sigil to give the WYSIWYG xhtml editing other than PageEdit?

kevinhendricks commented 4 years ago

No, but WYSIWYG relies on live editing of an html document while it is being viewed. This in turn uses the DOM built in editing commands that are part of QtWebEngine and Chrome. They are not under our control.

So depending on user actions, liveediting of the DOM can result in absolutely horrible code that works in a browser environment which is quite forgiving but is not truly valid html or xhtml.

So actual editing in Sigil's CodeView is required to clean it up so that things like epubcheck do not complain. That is why we removed the WYSIWYG editing from Sigil itself and created PageEdit but recommend PageEdit for proofing and simple edits not larger structural changes.

There is no WYSIWYG editor that can guarantee to create perfectly valid xhtml code all the time. So WYSIWYG should be restricted to simple edits, and proofing when creating epubs.

Most writers use Word or some other word processing to actually write the book, hopefully employing styles that can be mapped into xhtml/css. Then once written, the book is converted into an epub (using one of Sigil's input plugins) and then cleaned up and restructured using Sigil'sCodeView and then proofed or minor edits in PageEdit if needed.

Again, what you want "fixed", can not be fixed in PageEdit's source code. It is an inherent live editing done by the "browser engine" which in this case is QtWebEngine which uses Google Chrome's browser engine.

That is why I closed this issue as can't fix and I strongly recommend you do not rely on WYSIWYG live editing done in a browser unless used for only simple changes, without further cleaning in Sigil's CodeView.