Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 08-06-2024, 07:08 AM   #1
ptm@xact.co.uk
Junior Member
ptm@xact.co.uk began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2024
Device: none
Question XHTML closing tag issue

Simply by parsing and committing an xhtml file, using the container, I see the following changes to the content.

Before parsing:
<span x="y"/>
<div id="w"/>

After committing:
<span x="y"></span>
<div id="w"></div>

Is there a 'tweak' setting or other method I can use to preserve the compact version of for tags with only attributes and no content?
ptm@xact.co.uk is offline   Reply With Quote
Old 08-06-2024, 07:43 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 44,200
Karma: 23000010
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No there isn't, IIRC.
kovidgoyal is online now   Reply With Quote
Advert
Old Yesterday, 11:40 AM   #3
ptm@xact.co.uk
Junior Member
ptm@xact.co.uk began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2024
Device: none
I have not looked at the Calibre code. Hopefully there is an option on the serializer to use compact closing tags (i.e. <sometag/>) instead of <sometag></sometag>. If this is the case, how difficult do you think it would be to add a tweak to set this option? Is this something you or I can look at? I would need a few hints where to start looking.
ptm@xact.co.uk is offline   Reply With Quote
Old Yesterday, 11:44 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 44,200
Karma: 23000010
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
This is done deliberately, see line 441 in oeb/base.py
kovidgoyal is online now   Reply With Quote
Old Yesterday, 01:20 PM   #5
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 75,383
Karma: 133807966
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by ptm@xact.co.uk View Post
I have not looked at the Calibre code. Hopefully there is an option on the serializer to use compact closing tags (i.e. <sometag/>) instead of <sometag></sometag>. If this is the case, how difficult do you think it would be to add a tweak to set this option? Is this something you or I can look at? I would need a few hints where to start looking.
Most tags are <sometag>Text from the book</sometag>. That's why it should not be done. <sometag/>This is text from the book will not work.
JSWolf is offline   Reply With Quote
Advert
Old Today, 06:25 AM   #6
ptm@xact.co.uk
Junior Member
ptm@xact.co.uk began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2024
Device: none
Quote:
Originally Posted by kovidgoyal View Post
This is done deliberately, see line 441 in oeb/base.py
I see the comment about some browser based renderers. I wonder if this is still true. I've no idea when this code was written. But my boss needs self closing tags. So if, at line 160 we had:

Code:
def close_self_closing_tags(raw):
    if self_closing_tags_permitted():
        return raw
    for_unicode = isinstance(raw, str)
    repl = as_string_type(r'<\g<tag>\g<arg>></\g<tag>>', for_unicode)
    pat = self_closing_pat(for_unicode)
    return pat.sub(repl, raw)
And in 'tweaks', wherever they are coded, the self_closing_tags_permitted() function is added. Returning false by default, but true if so configured by the user. Then we get the best of both worlds. Am I on the right track?
ptm@xact.co.uk is offline   Reply With Quote
Old Today, 07:54 AM   #7
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 44,200
Karma: 23000010
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I'm not going to change that as it is a completely cosmetic change that has the potential to break rendering in the real world. You are welcome to run calibre from source and make the change for yourself.
kovidgoyal is online now   Reply With Quote
Old Today, 09:47 AM   #8
ptm@xact.co.uk
Junior Member
ptm@xact.co.uk began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Aug 2024
Device: none
Quote:
Originally Posted by kovidgoyal View Post
I'm not going to change that as it is a completely cosmetic change that has the potential to break rendering in the real world. You are welcome to run calibre from source and make the change for yourself.
May I ask you to reconsider? The Client using our plugin says it is a requirement. They suggest <tag></tag> (with no text between) is badly formed XML. The suggestion in my previous post would maintain backwards compatibility. So I do not believe it would affect anyone, unless they use the 'tweak' setting.

Implementing such a change myself (apart from not having a Linux system to do the build) would mean our Client could no longer install any future Calibre updates.

Fingers crossed, best regards
Paul
ptm@xact.co.uk is offline   Reply With Quote
Old Today, 10:14 AM   #9
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 44,200
Karma: 23000010
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
<tag></tag> is perfectly well formed XML. I suggest you tell your client to read the XML specifications.

You don't need Linux to do a build, indeed you don't need to do a build at all. calibre can run from source without needing building see https://manual.calibre-ebook.com/develop.html

I am not going to accept this change in calibre as it has the potential to break things for people for no actual benefit to any calibre user.
kovidgoyal is online now   Reply With Quote
Reply

Tags
xhtml tags


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting self closing tags (xhtml) roger64 Editor 2 03-04-2018 05:49 AM
TOC nav.xhtml issue ebookscovers Conversion 1 05-06-2017 11:12 AM
questions on self-closing tags and legal xhtml in epubs KevinH ePub 5 04-23-2012 10:12 PM
Issue closing ebook reader in Linux hairybiker Calibre 8 05-31-2011 02:17 PM
Issue with converting xhtml to epub using Calibre sg31 Calibre 0 10-20-2009 06:26 PM


All times are GMT -4. The time now is 11:28 AM.


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