01-13-2019, 10:34 AM | #1 |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
CFI Parser
Hi, @Kovid.
I want to modify ACE Plugin so it can output the results directly on the Editor. This way the user could click on the line and go directly to where the error is (like EPUBCheck Plugin). But, there is one thing on the way: ACE uses a non-standard EPUBCFI output. The starting point is not the spine. It uses CFI references only inside the file, like this: Code:
toc.xhtml#epubcfi(/4[idParaDest-e]/2/4[toc]) Doc.xhtml#epubcfi(/4[idParaDest-b]/2/2/4[tit]/4) I thought maybe I could inject the first part of the reference, before passing it to parser.py, making it whole again. Like this: Spine item to ref: Code:
<spine toc="ncx">
<itemref idref="Cover"/>
<itemref idref="Doc"/>
<itemref idref="Doc-1"/>
<itemref idref="Doc-2"/>
<itemref idref="Doc-3"/>
<itemref idref="toc"/>
..
<itemref idref="Doc-38"/>
<itemref idref="Doc-39"/>
</spine>
Code:
epubcfi(6/12!//4[idParaDest-e]/2/4[toc])
Can you help me with that? If I could make the CFI reference to work with your parser, then I will work on the rest of the code to achieve the goal of clickable references. Last edited by thiago.eec; 01-13-2019 at 06:43 PM. |
01-13-2019, 10:29 PM | #2 |
creator of calibre
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Not sure what you are asking. The parser does not care if the first step is a spine reference or not, for instance to parse
Code:
epubcfi(/4[idParaDest-e]/2/4[toc]) which will give you: Code:
({u'steps': [{u'id': u'idParaDest-e', u'num': 4}, {u'num': 2}, {u'id': u'toc', u'num': 4}]}, {}, {}, u'') |
01-14-2019, 04:13 AM | #3 |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Hi, Kovid.
By the spec, a epubcfi reference starts at the spine (at least that was what I understood). Let's supose I call the parser with just that: Code:
epubcfi(/4[idParaDest-e]/2/4[toc]) ------------------------- Another question: how can I use the parser the get line and column? I thought the parser would get the CFI reference and convert it to (col,line). |
01-14-2019, 04:28 AM | #4 |
creator of calibre
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
all the parser does is convert a serialized CFI reference into a form that is easier to access programmatically, it does not know anything about spines, lines and cols. In fact CFI cannot be used to go to a particular line and column. The best you can do in general is go to the line that contains the start of the tag referenced by the CFI. I dont know why the ACE tool chose CFI as a way to report error locations, it is not suited for that task, at all. Its a way to reference locations in an rendered HTML tree, not HTML source.
|
01-14-2019, 04:45 AM | #5 | |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Quote:
P.S.: I thought it would be possible to get line and column after reading this post of KevinH. He used you parser to achieve that. It surely would be easier if it gave a (lin,col), like EPUBCheck. |
|
01-14-2019, 04:59 AM | #6 |
creator of calibre
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I dont see how that post achieves that?? All it does is return the line and col of the containing tag as far as I can tell.
As for converting CFI to the the containing tag, there is code to do that for the viewer (it uses CFI internally for bookmarking), but not for the editor, it would need to be added. |
01-14-2019, 05:21 AM | #7 | |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Quote:
Code:
editor.go_to_line(item.line, item.col) Last edited by thiago.eec; 01-14-2019 at 06:01 AM. |
|
01-14-2019, 08:04 AM | #8 |
creator of calibre
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
01-14-2019, 09:08 AM | #9 |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Thanks a lot, Kovid!
I'll check this when I get home. |
01-17-2019, 10:51 AM | #10 | |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Quote:
Thank you very much for the code. It's working perfectly. Altough, I've noticed an odd behavior that I don't know if it is by design. Steps to reproduce: 1) My Editor is set to wrap long lines. 2) When I click on a partial CFI, it goes to the beginning of the line referenced, as expected. 3) When the CFI has an ID for the target tag, then it will try to place the cursor on that ID. Nice. 4) But... it only works if the ID is in the first "line". 5) If I resize the code window, and the ID attribute goes to the second "line", then it will place the cursor at the beginning of the real line, like there was no ID. |
|
01-17-2019, 07:46 PM | #11 |
creator of calibre
Posts: 43,850
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Probably a performance optimization -- open a ticket for it and I will lok into it, see if it can be implemented for at least a couple of lines without too much impact.
|
01-18-2019, 05:18 AM | #12 | |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Hi, Kovid.
I didn't notice any impact on performance. Running ACE with the plugin takes roughly the same time as with the command line tool (on my sistem, the diference is around 0.3s). When I click on a message (wich uses the CFI function), the file opens instantaneously, with the cursor on the right line. Quote:
I've incorporated your code into the plugin for older versions of calibre, and let it run normally for the 3.38 and later versions. Take a look at the go_to_line() function. -------------- As for the issue itself, its not about the position of the ID, as I supected before. It affects any attribute wich spans for 2 "lines". The cursor will be placed at the end of that attribute value. P.S.: in case you need a book to test, use the attached file (scrambled). The issue is more easily noticed on the footnote references (when ACE complains about the correspondent ARIA role for it, doc-noteref). |
|
01-18-2019, 11:45 AM | #13 | |
Guru
Posts: 927
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
|
Quote:
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Blogger/Blogspot Comment Parser & More | EnergyLens | Recipes | 4 | 11-23-2014 11:04 AM |
EPUB indexing with CFI ? | boneill | Library Management | 0 | 09-05-2014 04:55 PM |
cfi.coffee to cfi.js | Anthon | Calibre | 11 | 03-16-2012 06:05 PM |
Clippings Parser | wiccan2 | Kindle Developer's Corner | 10 | 09-21-2011 01:21 PM |
Parser can't identify form used for user/pass | Solari | Calibre | 3 | 03-01-2009 07:04 PM |