Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 03:05 PM   #1
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 53,899
Karma: 182150167
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Oddity in Mend and Prettify

I was looking at an epub for another person who was running into errors and ran into an oddity using Mend and Prettify.

An example is one line originally has a missing " after the bold while another had a missing " before the bold:
Code:
  <p>This is a <span class="bold>test line</span> with a missing " after the bold.></p>
  <p>This is a <span class=bold">test line</span> with a missing " before the bold.></p>
After Mend and Prettify, the lines read:
Code:
  <p>This is a <span class="bold&gt;test line&lt;/span&gt; with a missing " after="" the="" bold.=""></span></p>
  <p>This is a <span class="bold"">test line</span> with a missing " before the bold.&gt;</p>
The whole ePub was full of similar items since the author manually added most of the spans in violation of common sense.
DNSB is offline   Reply With Quote
Old Yesterday, 03:54 PM   #2
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 9,956
Karma: 7500000
Join Date: Nov 2009
Device: many
Yes, Xhtml spec requires all attributes to be quoted - either with single or double quotes.

If they had run Sigil's well formed check, it should detect things like unopened or unclosed attributes and warned them but sometimes if a suitable quote is found "nearby", even that gets confused.

The missing end quote means the attribute value actually encompassed the closing > and converted it to & lt ; to prevent its loss since > are not allowed inside attribute quoted strings without them being xml encoded. It repeated that and converted bare text to attributes and ended that attribute later.

The missing quotes around an attribute are really hard to detect at times and this was one of them. Luckily, all text has been either encoded, made into empty attributes or saved in some way. So you can fix it by hand.

That said, gumbo follows the same whatwg spec for xhtml so Preview was seeing that code and internally doing pretty much the same thing as gumbo showed.

Please try Sigil's built in well formed check or epubcheck on the initial broken attribute code to see if either would better warn you of the breakage properly.

Last edited by KevinH; Yesterday at 04:14 PM.
KevinH is offline   Reply With Quote
Old Yesterday, 04:01 PM   #3
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 9,956
Karma: 7500000
Join Date: Nov 2009
Device: many
Actually, I tested your example and Preview clearly shows the following error message.
So Preview is interpreting that text the exact same way gumbo did in Mend and Prettify.

And Sigil's well formed check detected the missing unclosed attribute value and the Validation window showed:

Code:
Section0001.xhtml Line 11: Offset N/A  Message: Attribute "class" has unmatched quotes on attribute value.  near column 15
Unfortunately, I did not design the whatwg/gumbo parser but it seems that missing quotes in attribute names is not a common enough occurence to create a better self mend process probably because real html does not need attributes to have quotes or even have any value.

Not much I can do here. Both Preview and Sigil's own Well-formed check indicate there is a problem and Sigils' own well-formed check even correctly identifies what is wrong.

In general making sure everything is well formed and that Checkpoints are made before running Mend or Mend and Prettify or any Sigil Tool is probably the best approach.
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2026-08-19 at 4.00.01 PM.png
Views:	11
Size:	49.4 KB
ID:	225266  

Last edited by KevinH; Yesterday at 04:10 PM.
KevinH is offline   Reply With Quote
Old Yesterday, 04:14 PM   #4
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 53,899
Karma: 182150167
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Any of well-formed check, epubcheck or epubveri options works to warn me of the errors.

I triggered the issue when the original ePub did not believe in line breaks so each file was a solid mass of text and I pretty-printed it using mend and prettify from the Tools menu. I dumped that version, reopened the original and pretty-printed it. After that, I ended up using search/replace & regex to do most of the cleanup to get the book ready to be published. The author couldn't remember which web page she used to do the AI assisted conversion from her word processor file to ePub but will not use it again.
DNSB is offline   Reply With Quote
Old Yesterday, 05:37 PM   #5
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 29,672
Karma: 212352863
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
I'm fairly certain that BeautifulSoup can correct mismatched and/or missing attribute quotes by parsing and re-serializing. If so, a plugin to correct something like this shouldn't be terribly difficult.
DiapDealer is online now   Reply With Quote
Old Yesterday, 05:49 PM   #6
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 9,956
Karma: 7500000
Join Date: Nov 2009
Device: many
Certainly worth a shot. We could include it as python3lib code and run it before every Mend and Prettify. But I did not think BS4 when using the lxml parser for xml/xhtml did that? Maybe only the html5lib parsing then reserializing as xhtml?

Last edited by KevinH; Yesterday at 05:51 PM.
KevinH is offline   Reply With Quote
Old Yesterday, 05:58 PM   #7
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 29,672
Karma: 212352863
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by KevinH View Post
Certainly worth a shot. We could include it as python3lib code and run it before every Mend and Prettify. But I did not think BS4 when using the lxml parser for xml/xhtml did that? Maybe only the html5lib parsing then reserializing as xhtml?
It very well could be the html5lib parser now that you mention it.
DiapDealer is online now   Reply With Quote
Old Today, 10:39 AM   #8
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 29,672
Karma: 212352863
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
For the record, none of the parsers I've tried this with will fix the unbalanced attribute quotes, and properly escape the naked quote (nor eliminate the extraneous >) in the sample provided.

Seems like a non-starter.
DiapDealer is online now   Reply With Quote
Old Today, 12:46 PM   #9
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 9,956
Karma: 7500000
Join Date: Nov 2009
Device: many
That is what I feared. The current whatwg spec when it starts to parse an attribute really does not handle these cases at all.

The only way this is detected by our well formed check is that it parses by extracting the tag first (ie. it assumes that the > char truly ends the tag and is not something someone just forgot to xml encode) and with a known tag end in hand the missing end quote can be detected. But the modern whawg tokenizer does not work that way, and so the > char does not end the tag, and the error is treated as a missing xml encoding of the > char and building up the attribute value continues merrily along.

Neither way is guaranteed correct. They just make different assumptions as to the cause of the error.

I would think that missing ending quotes on attribute values in xhtml is much more prevalent than a spurious > char that was not xml encoded by mistake. But I have no data to back that view up.

Last edited by KevinH; Today at 12:51 PM.
KevinH is offline   Reply With Quote
Old Today, 01:10 PM   #10
BeckyEbook
Wizard
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
Posts: 1,013
Karma: 3640080
Join Date: Jan 2017
Location: Poland
Device: Various
I have a proposal to consider: Safe Mend.
Before running Mend, we first run "Well-Formed Check EPUB." If there are no errors, we proceed as usual.
If there are errors, we display the following message to the user: "Mending canceled: XML not well-formed."

Note that this isn’t anything new. This option already exists in Sigil when running "Restructure EPUB to Sigil Norm" or "Merge".

It could be optional, but I think it would be useful.

A reference from three years ago, where we struggled with various types of quotation marks surrounding the value of an attribute.
BeckyEbook is offline   Reply With Quote
Old Today, 01:35 PM   #11
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 9,956
Karma: 7500000
Join Date: Nov 2009
Device: many
Unfortunately, there is no such thing as perfectly safe Mend. Only the user knows what they actually wanted for the code they wrote that does not follow the rules.

Mend by definition just uses the whatwg tokenizing and parsing specification (ie. google's gumbo parer) that forces the given xhtml/html to be well-formed enough that it can can create a DOM tree. All Mend does is take that created internal DOM tree and serialize it so you can see exactly how your code was interpreted by the browser. This is exactly what browsers do.

Mend properly handles most errors and almost never actually loses text. It is and was much much safer than Tidy ever was.

So using Mend is generally just fine for fixing most errors. So running a well-formed check and only then running Mend if it passes being well-formed is typically overkill and also no guarantee of correctness. But treating your code the exact same way a browser does is valuable so you can see what is different.

So it is much much better to get into the habit of creating a Checkpoint first before running any Sigil tool and using Sigil's diff function to examine the changes.

Or at least checking each page in Preview to verify there are no current parsing warning pink warnings at the top of each page.

Now if you said that passing a wellformed check before running prettify was a good idea, I think I would agree in general and something we can play with to decide.

Last edited by KevinH; Today at 02:01 PM.
KevinH is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mend and Prettify frequently fails to run after splitting a file in v2.8.0 byword Sigil 10 07-05-2026 08:38 PM
Disappointed with 'Mend and Prettify' when <table>'s included. philja Sigil 9 12-11-2025 08:38 PM
About "Mend and Prettify Code" RbnJrg Sigil 1 10-06-2025 07:12 PM
Sigil Prettify Code iMilazzo Sigil 26 05-12-2025 10:09 AM
Prettify HTML questions n9qqk Sigil 13 03-06-2018 12:47 PM


All times are GMT -4. The time now is 07:40 PM.


MobileRead.com is a privately owned, operated and funded community.