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 02-16-2014, 10:31 AM   #1
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Suggestion: Book level variables

Potential automation capability would be to allow book level variables and some simple math to change them.

Keep them disguised as html comments until the resolved values are inserted with a special save, but leave the comments in the epub

I'd like to see them work at the book level, across all files

CSS allows intra-file numbering, but not between files.

Meta-data about the epub could also be exposed.

VERY simple picture attached to show 3 files (or what would be) with a ##chapnum and a ##endnotenum variable being defined on the fly and initialized

Code:
  <!--##person = "Fred"-->
  <!--##chapnum = 1-->
  <!--##endnotenum = 1-->

  <h1>Chapter Number <!--##chapnum--></h1>

   <!--##chapnum=##chapnum + 1 -->
So as a simple ConOps, the first 3 comments define and initialize the variables, the fourth comment inserts the current value of the variable, and the fifth performs some simple math.

I envision the comments remaining, but only the 'inserts' actually having their values inserted after the placeholder comment

Some thoughts
Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	403
Size:	179.4 KB
ID:	119151  
phossler is offline   Reply With Quote
Old 02-16-2014, 11:38 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: 45,337
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You will be able to do this (and much more powerful things) using the upcoming function mode for search and replace which will allow you to write arbitrary functions that will be called for each match during search and replace. So you would insert

<!-- chapter # -->

in the text and then use

<!-- chapter # -->

as the search expression and the following simple function as the replace expression.

Code:
class ChapterNumbering(object):

  def __init__(self):
     self.number = 0

  def __call__(self, match):
     self.number += 1
     return str(self.number)

function = ChapterNumbering()
Then when you are ready to have your numbers generated, just run a bulk search and replace on all files and all the comments will be replaced by the chapter number.

And if you want to insert the chapter number after the comment instead of replacing the comment, you can do that as well, with a slight modification to the function.

Note that I haven't finished designing the function mode, so some details int he above may change.
kovidgoyal is offline   Reply With Quote
Advert
Old 02-16-2014, 12:47 PM   #3
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Much more powerful and flexible for sure

But ... is it too programmer-oriented to be used by the non-programmers?
phossler is offline   Reply With Quote
Old 02-16-2014, 01:21 PM   #4
mrmikel
Color me gone
mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.mrmikel ought to be getting tired of karma fortunes by now.
 
Posts: 2,089
Karma: 1445295
Join Date: Apr 2008
Location: Central Oregon Coast
Device: PRS-300
For common functions, we will need an MR library to archive useful ones. I am not a programmer, but I can copy and paste! (grin)

Maybe there can be some included either in help or the program itself, somehow.
mrmikel is offline   Reply With Quote
Old 02-16-2014, 02:56 PM   #5
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: 85400180
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 kovidgoyal View Post
You will be able to do this (and much more powerful things) using the upcoming function mode for search and replace which will allow you to write arbitrary functions that will be called for each match during search and replace. So you would insert

<!-- chapter # -->

in the text and then use

<!-- chapter # -->

as the search expression and the following simple function as the replace expression.

Code:
class ChapterNumbering(object):

  def __init__(self):
     self.number = 0

  def __call__(self, match):
     self.number += 1
     return str(self.number)

function = ChapterNumbering()
Then when you are ready to have your numbers generated, just run a bulk search and replace on all files and all the comments will be replaced by the chapter number.

And if you want to insert the chapter number after the comment instead of replacing the comment, you can do that as well, with a slight modification to the function.

Note that I haven't finished designing the function mode, so some details int he above may change.
This is just too awesome!
eschwartz is offline   Reply With Quote
Advert
Old 02-16-2014, 07:38 PM   #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: 45,337
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I dont really see a way of implementing this without programming. The original proposal is also using programming, just with a special purpose programming language designed for a single use case. As time passes more such use cases will be discovered and more special purpose programming languages will have to be invented for them. At which point the user will have to learn multiple, different programming languages to perform different automated tasks.

Much better to use a single, well designed, general purpose programming language. Python (the language in question) has a very easy to learn and newbie friendly syntax.

Certainly, the first few times someone uses it may be a little daunting, but providing simple examples/templates is a good way to get around that.
kovidgoyal is offline   Reply With Quote
Old 02-16-2014, 09:59 PM   #7
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Can't disagree with any of the comments.

I was modeling my idea based on the very simple (and not very flexible) way the CSS content property, and the counter-increment and counter-reset properties work (except using HTML comments in-line instead of CSS.)

For general-purpose-ness, will you expose book and file metadata to the function language, such as {tags} and {title} and {comments} and {filename} and {create_date}?
phossler is offline   Reply With Quote
Old 02-16-2014, 10:06 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: 45,337
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Yes, metadata will be available.
kovidgoyal is offline   Reply With Quote
Old 02-17-2014, 06:13 AM   #9
DrChiper
Bookish
DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.DrChiper ought to be getting tired of karma fortunes by now.
 
DrChiper's Avatar
 
Posts: 1,017
Karma: 2003162
Join Date: Jun 2011
Device: PC, t1, t2, t3, Clara BW, Clara HD, Libra 2, Libra Color, Nxtpaper 11
Quote:
Originally Posted by phossler View Post
But ... is it too programmer-oriented to be used by the non-programmers?
Perhaps some basic functions (like the one in the code example for just incrementing chapter numbering and such) can just be included. Then only users with very specific requirements need to program their own wishes. Perhaps those users can publish their solutions as "recipes" for the benefit of others in the future.
DrChiper is offline   Reply With Quote
Old 02-17-2014, 08:44 AM   #10
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 6,627
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
This is very similar to program mode for custom columns. There are some basic necessities, a library (quite useful as reference) and then you create your own functions (much easier to define a function than trying the "mixed" mode in my case).
Terisa de morgan is offline   Reply With Quote
Old 02-17-2014, 09:00 AM   #11
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
@kovidgoyal --

A thought occurs (sometimes I get lucky)

If I have an epub with inline comments, and I use the planned F&R capablity to apply changes (leaving the original comment but inserting its calculated value) would I be able to re-edit the original document?

For example if I use the F&R to insert chapter numbers and then rearrange the html files (invalidating the chapter numbering) would I be able to edit the original epub and re-replace and get an updated chapter numbering?

It might be worthwhile to consider allowing some very simple inline comments that are resolved into actual values

Last edited by phossler; 02-17-2014 at 09:03 AM.
phossler is offline   Reply With Quote
Old 02-17-2014, 09:51 AM   #12
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: 45,337
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Sure you can, simply insert the number after the comment instead of replacing it. Quoting my previous post

Quote:
And if you want to insert the chapter number after the comment instead of replacing the comment, you can do that as well, with a slight modification to the function.
kovidgoyal is offline   Reply With Quote
Old 02-17-2014, 10:42 AM   #13
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
Sure you can, simply insert the number after the comment instead of replacing it. Quoting my previous post

Understood that part, but I was asking about re-running the F&R a second time

ver 1 -- Chapter <!-- chapter # -->

apply F&R makes a ver 2 ...

ver 2 -- Chapter <!-- chapter # -->10

So far, so good.

Now if I edit ver 2 to say re-arrange files such that chap 10 should now be chap 5 (but many changes would affect the resolved value) it seems like I'd end up with ...

ver 3 -- Chapter <!-- chapter # -->510

since the "10" now looks like just some text to the second F&R

So I guess a workaround would be to always work in a 'baseline' copy and do the F&R and then Save with new name?

Last edited by phossler; 02-17-2014 at 10:46 AM.
phossler is offline   Reply With Quote
Old 02-17-2014, 11:02 AM   #14
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: 45,337
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No, you need to change the function to replace both the comment and the following number (if any), like this:

search expression

<!-- comment# -->(\d*)

function

Code:
def __call__(self, match):
   self.number += 1
   return '<!-- comment# -->' + str(self.number)
Then you can run it as many times as you like, each time the number will ge generated fresh.
kovidgoyal is offline   Reply With Quote
Old 02-17-2014, 11:22 AM   #15
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,087
Karma: 447222
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
No, you need to change the function to replace both the comment and the following number (if any), like this:
What would happen if the <!-- comment# --> was something like multiple and varing words or a epub metadata? For example


(ver1) epub text with tags = Fiction, Adventure, Escapist, PubDomain

"and the tags in my book are <!-- tags -->"


Find:

Code:
<!-- tags -->
Replace:

Code:
Tag function ()
[no idea how to actually write it]

Result #1:

"and the tags in my book are <!-- tags --> Fiction, Adventure, Escapist, PubDomain"

(ver 2) If I were to revise the tags to "Fiction, Adventure, Public Domain", then is it possible to replace the original "Fiction, Adventure, Escapist, PubDomain" with the updated tags?
phossler is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Suggestion] Change indentation to one letter per indentation level. John Peterson Development 1 10-22-2012 02:05 PM
taking book sharing to the next level... paola General Discussions 35 09-30-2012 08:32 PM
Question: find and replace with variables? veezh Recipes 4 12-21-2010 05:23 AM
Regex capturing variables Lonas Sigil 9 08-14-2010 03:05 PM
Noob: just getting my head around all the variables KAM Sony Reader 16 02-04-2009 06:16 PM


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


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