Editor: HTML entities replacement doesn't work in Calibre 64-bit for windows

Bug #1265147 reported by arspr on 2013-12-31
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Undecided
Unassigned

Bug Description

The summary tells you everything ;-)

The new feature doesn't work in my Calibre 64-bit installation. BUT it correctly works in my Calibre 32-bit installation.

(Entities are nevertheless correctly rendered and identified in editor (in italics light grayish blue) and HTML fix/Beautify do replace them).

Running 1.17 on Vista 64-bit.

I cannot reproduce on my windows 7 64 bit machine. Entity replacement
works in HTML files, for example typing … replaces automatically
with ellipsis aftertyping the ;. Are you sure you did not turn it off in
preferences accidentally?

 status invalid

Changed in calibre:
status: New → Invalid
arspr (arspr) wrote :

Nope. More over, I've changed between my recently installed 32 bit version and my old 64 bit version without modifying any setting...

I'll perform more tests just in case I made some mistake or if it happens only in one book but not in others...

(I also explicitly tested with … as is the example you give in the flyover help of the option)

arspr (arspr) wrote :

I've double- and triple-checked and I always get the issue in Calibre 64-bit (either running from source or running normally).

I'm going to post a thread in Mobileread.

Nevertheless, remember that I have set a development environment on my PC. So I you guide me, I can try debugging it...

(And another related comment: XML entities " and ' are not automatically converted into " and ' when typing, but they are when Beautifying or when Fixing HTML. Incoherent behaviour here?)

Kovid Goyal (kovid) wrote :

It is not always safe to replace the ' and " entities, it can lead to invalid markup. Fix HTML can easily detect such situations and avoid them. The live replace in the editor cannot.

If you wish to debug it, in the file editor/text.py look at the function replace_possible_entity(), stick some print statements into it to see what is happening and run the editor as

calibre-debug -t file.epub

from a console. This will allow you to see the output from the print statements. To start with, see what values the variables text and m have, like this:

print (text, m) (insert a new line after line 555)

arspr (arspr) wrote :

Done.

I attach a screenshot which covers both runs.

When running Calibre 32 bit and typing a … I automatically get:
8 &hellip; <_sre.SRE_Match object at 0x05167E20>
And the &hellip; is converted.

But when running Calibre 64 bit, just when it is opened I get an error:
C:\Program Files\Calibre2\pylib.zip\dateutil\parser.py:336: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal

Then nothing happens when I type &hellip; on the Test.epub example.

Any more instructions?

Kovid Goyal (kovid) wrote :

If nothing is happening, that means teh function is not being called, the only way I can see for that to happen is if you have the preference turned off. See line 548 just above that function.

arspr (arspr) wrote :

I don't know what I'm exactly doing, but I think there's something weird.

I copy my current text.py around that area so you can see what I've modified (just two added prints):

    def keyPressEvent(self, ev):
        QPlainTextEdit.keyPressEvent(self, ev)
        print (ev.key(), Qt.Key_Semicolon, tprefs['replace_entities_as_typed'], self.syntax)
        if ev.key() == Qt.Key_Semicolon and tprefs['replace_entities_as_typed'] and self.syntax == 'html':
            self.replace_possible_entity()

    def replace_possible_entity(self):
        c = self.textCursor()
        c.setPosition(c.position() - min(c.positionInBlock(), 10), c.KeepAnchor)
        text = unicode(c.selectedText())
        m = entity_pat.search(text)
        print (text, m)
        if m is None:

And then as the screenshot shows the problem is that ev.key() for ";" is 44, but Qt.Key_Semicolon is 59 when running Calibre 64-bit. In Calibre 32-bit ";" key is also 59.

Any more tests?

Fixed in branch master. The fix will be in the next release. calibre is usually released every Friday.

 status fixreleased

Changed in calibre:
status: Invalid → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers