Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 09-05-2015, 11:01 PM   #1
bmix
Member
bmix began at the beginning.
 
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.
bmix is offline   Reply With Quote
Old 09-06-2015, 12:19 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,539
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
calibre-debug --explode-book
kovidgoyal is offline   Reply With Quote
Advert
Old 09-06-2015, 04:11 AM   #3
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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.
eschwartz is offline   Reply With Quote
Old 09-06-2015, 10:24 AM   #4
bmix
Member
bmix began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
Quote:
Originally Posted by eschwartz View Post
calibre already includes the necessary libraries for XSLT manipulation
I am not sure, which XSL version this covers. If it is being libxml, then this would allow for XSL v1 only. Personally I use Saxon, since that is XML v2 capable, which is much more powerful.
bmix is offline   Reply With Quote
Old 09-06-2015, 10:33 AM   #5
bmix
Member
bmix began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
Quote:
Originally Posted by kovidgoyal View Post
calibre-debug --explode-book
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 ;-)
bmix is offline   Reply With Quote
Advert
Old 09-06-2015, 11:36 AM   #6
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,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.
kovidgoyal is offline   Reply With Quote
Old 09-06-2015, 01:23 PM   #7
bmix
Member
bmix began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
Quote:
Originally Posted by kovidgoyal View Post
I dont see the difference. In either case you are applying an XSLT transform to the text.
We would be applying a 'search & replace' to the text also, if we'd use 'sed' instead of the 'search & replace' on the text in the editor.

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:
Although, if I were you, I'd ditch XSLT and just directly use lxml. Much nicer to use than XSLT.
Well, niceness is a matter of taste ;-)

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.
bmix is offline   Reply With Quote
Old 09-06-2015, 01:39 PM   #8
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,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
kovidgoyal is offline   Reply With Quote
Old 09-06-2015, 01:40 PM   #9
bmix
Member
bmix began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Mar 2014
Location: Budapest/Hungary
Device: Kindle4,reMarkable2,MoonReader Pro
Thanks, will do.
bmix is offline   Reply With Quote
Old 09-06-2015, 01:40 PM   #10
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,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.
kovidgoyal is offline   Reply With Quote
Old 09-06-2015, 01:57 PM   #11
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
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:
Originally Posted by bmix View Post
I am not sure, which XSL version this covers. If it is being libxml, then this would allow for XSL v1 only. Personally I use Saxon, since that is XML v2 capable, which is much more powerful.
calibre already ships with python2-lxml -- python bindings for libxml2 and libxslt -- bundled into the binary distribution (and a linux source/distro install requires it as a dependency).
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.
eschwartz is offline   Reply With Quote
Reply

Tags
filter, xslt


Forum Jump

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


All times are GMT -4. The time now is 04:32 PM.


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