09-05-2015, 11:01 PM | #1 |
Member
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
|
[REQ] Apply XSLT/external filter on editor's text
Hi!
It would be very nice, if one could apply XSL transforms on the editor's text, in addition to the search and replace. Reason being, that it is often much more convenient when re-working badly scanned and HTML'ized ebooks from another source (think MS Office exports) to use XPath than regex for the XHTML. Generically implemented, this could even be a feature, that allows the current editor's text being routed through any command-line program and reloaded upon successful exit of that program. Which would allow for all kinds of external filters. |
09-06-2015, 12:19 AM | #2 |
creator of calibre
Posts: 44,539
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
calibre-debug --explode-book
|
Advert | |
|
09-06-2015, 04:11 AM | #3 |
Ex-Helpdesk Junkie
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Alternatively, write up an editor plugin which enables this. calibre already includes the necessary libraries for XSLT manipulation, I believe -- you would just need to wire it up to a GUI and plug it into the editor.
|
09-06-2015, 10:24 AM | #4 |
Member
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
|
|
09-06-2015, 10:33 AM | #5 |
Member
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
|
Hey! That's a very nice and convenient function, I didn't know as of yet. Definitely gonna use it in the future.
But it defeats the purpose of using the Calibre Editor. I mean, it's also possible to run 'sed' on files in the document, this way, rather than using the regex search/replace function in the editor ;-) |
Advert | |
|
09-06-2015, 11:36 AM | #6 |
creator of calibre
Posts: 44,539
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
I dont see the difference. In either case you are applying an XSLT transform to the text. So all you have to do is hit save in the editor, then run your tool with calibre-debug. If you want it integrated in the editor, to avoid the separate step of running your tool, you will need to write an editor plugin for that.
Although, if I were you, I'd ditch XSLT and just directly use lxml. Much nicer to use than XSLT. |
09-06-2015, 01:23 PM | #7 | ||
Member
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
|
Quote:
Also, there is this: http://stackoverflow.com/questions/1...contained-tags ;-) Using XML technology for editing X(HT)ML just seems logical to me. But it's not just about XSL. A function, that would allow to route currently opened editor document through external program and reload it, could make for many features, that the user can set up themselves. Something like this: https://packagecontrol.io/packages/FilterPipes Quote:
I am an XML author, not a Python coder. I work mainly with XML technologies (XProc, XPath, XSL, etc.). So I have much more experience here. Being natively developed for XML-transforms, using XSL, imho, is just more natural for XML than anything else. So I would like to re-define my feature whish as: Have currently opened document send to external program and reloaded upon successful completion. If this can be implemented as a plugin, I will look into it, but since I am not a Python coder (and am busy with another, huge, project) I see not much chance, that I am going to be successful. What attribute would I need to get 'filename of frontmost document' ? Is it: Code:
foo = calibre.gui2.tweak_book.boss.Boss.currently_editing Thanks. EDIT: I just realized, that for that, what I want to implement, I'd need a scratch-buffer, into which I quickly can add some XSLT. Is such a thing available? I should have explained this earlier, since this may make it more understandable, why I want it to be appliable from within the editor. Last edited by bmix; 09-06-2015 at 01:33 PM. Reason: Added comment. |
||
09-06-2015, 01:39 PM | #8 |
creator of calibre
Posts: 44,539
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Yes, it can be implemented as a plugin.
As for XSLT, if you are happy with it, more power to you, I dont care what tool you like to use Looka t the example editor plugin int he maual. If you want to get the name of the currently open file, use self.boss.currently_editing |
09-06-2015, 01:40 PM | #9 |
Member
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
|
Thanks, will do.
|
09-06-2015, 01:40 PM | #10 |
creator of calibre
Posts: 44,539
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
And the manual has extensive API documentation for the Boss and container objects, which should allow you to implement this plugin fairly easily.
|
09-06-2015, 01:57 PM | #11 | |
Ex-Helpdesk Junkie
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Quote:
That would appear to be xslt 1.0 only. In order to use Saxon -- or any other tool you have a specific attachment to that doesn't come with calibre -- you'd need to bundle it in the plugin, and most likely require the user installs a JVM separate from calibre, then fiddle with their environment variables on Windows. I am not aware of any Saxon bindings for python, so it'd be subprocesses all the way. You'll have to decide whether that is worth the additional benefits XSLT v2 brings. Last edited by eschwartz; 09-06-2015 at 01:59 PM. |
|
Tags |
filter, xslt |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
E-book readers (E-ink) with text editor and can connect to external USB keyboard? | stupidtss | Which one should I buy? | 7 | 07-20-2014 10:01 AM |
Text editor? | Fedwin | Kindle Developer's Corner | 2 | 05-06-2014 08:45 PM |
Why do you still use a text editor? | neufsix | Workshop | 10 | 04-21-2013 09:14 PM |
Classic Text Adventures and/or External Keyboards for the nook? | ajroach42 | Nook Developer's Corner | 4 | 03-25-2011 06:17 PM |
Onyx Text Editor? | Risto | Andere Lesegeräte | 1 | 05-25-2010 06:34 AM |