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-13-2015, 01:07 PM   #1
geniale
Member
geniale began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Sep 2015
Device: none
Unhappy ID in my ebook - regular expression

I need some help with my problem. I don't have any knowledge of programming and I want to put many id in a epub file.

in my file i have this:
<p class="calibre2"><sup class="calibre3">45</sup>
and i want to put this <a name= "#v15004045"></a>45
i have to make 45 id.

<p class="calibre2"><sup class="calibre3">4</sup> will be
<p class="calibre2"><sup class="calibre3"><a name= "#v15004045"></a>4</sup>
Is that right? How can i do it? Is there an automatic way to do this?
geniale is offline   Reply With Quote
Old 09-13-2015, 02:56 PM   #2
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,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
ids should be unique -- how are you distinguishing them!

If the targets already contain the number, use a regex that captures the number, and replaces it in the id.

Can you show examples that indicate how the ids should be constructed.
eschwartz is offline   Reply With Quote
Advert
Old 09-14-2015, 04:43 AM   #3
ni_c
Enthusiast
ni_c began at the beginning.
 
Posts: 40
Karma: 10
Join Date: Jul 2015
Device: none
are you trying to make internal links to a different part of the document?

idk what function name="" has but according to this its not a supported function of 'a'

Taking a guess at what your asking, if you want 4 to link to 45,
then 4 needs a url that points to the 45 id, like

<p class="calibre2"><sup class="calibre3" id="v15004045">45</sup></p>

<p class="calibre2"><a href="part0000.html#v15004045">4</a></p>

just swap part0000.html with whatever file 45 is located in with your doc

Last edited by ni_c; 09-14-2015 at 05:01 AM.
ni_c is offline   Reply With Quote
Old 09-14-2015, 05:34 AM   #4
geniale
Member
geniale began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Sep 2015
Device: none
My epub file has 17 chapters:
v3001.html
v3002.html
.......
v30017.html

Every chapter has almost 24 paragraph with this html:
<p class="calibre2"><sup class="calibre3">1</sup>
<p class="calibre2"><sup class="calibre3">2</sup>
.....
<p class="calibre2"><sup class="calibre3">24</sup>

Is there a way to add in every paragraph a bookmark or id like this:
id="id v3001001"
id="id v3001002"
......
id="id v3001024"

The final string it should be:
<p id="id v3001001" class="calibre1"><sup class="calibre2">1</sup>
<p id="id v3001002" class="calibre1"><sup class="calibre2">2</sup>
....
<p id="id v3001024" class="calibre1"><sup class="calibre2">24</sup>

In other word the string should read chapter name (v3001, v3002... v3014) and add paragraph number (001, 002... 024) and the final result (v3001001, v3001002... v3001024) and all this in every chapter (v3017001, v3017002... v3017024).

Any suggestion? Can anyone tell me que regular expression or is there another way?
Thank you.

Last edited by geniale; 09-14-2015 at 06:02 AM.
geniale is offline   Reply With Quote
Old 09-14-2015, 09:38 AM   #5
ni_c
Enthusiast
ni_c began at the beginning.
 
Posts: 40
Karma: 10
Join Date: Jul 2015
Device: none
really does sound like a huge task, and the toc.ncx alone would freak me out, id tackle it if it were my job, but for personal use not my style. Would suggest waiting for Kovid for his opinion.

btw pretty sure id's dont work with blank spaces added, would wanto add an underscore or dash to join them like "id_v..."

good luck
ni_c is offline   Reply With Quote
Advert
Old 09-14-2015, 11:45 AM   #6
geniale
Member
geniale began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Sep 2015
Device: none
Post

Quote:
Originally Posted by ni_c View Post
really does sound like a huge task, and the toc.ncx alone would freak me out, id tackle it if it were my job, but for personal use not my style. Would suggest waiting for Kovid for his opinion.

btw pretty sure id's dont work with blank spaces added, would wanto add an underscore or dash to join them like "id_v..."

good luck
*********
Thanks for your answer!! I imagine that it looks like a huge task but if you look from another angle i think you have the solution. You know regular expression formulas but i don't. Could you answer me 3 questions?

1. how can i extract the v3001.html with a regular expresion?
2. how can i extract the 1, 2, 3 or 4 of a paragraph and put it in a 000 format
3. how can i put this two in <p class="calibre2"><sup class="calibre3">1</sup>

I need something like this:
<p id="v3001001" class="calibre1"><sup class="calibre2">1</sup>
<p id="v3001002" class="calibre1"><sup class="calibre2">2</sup>
.......
<p id="v3001024" class="calibre1"><sup class="calibre2">24</sup>

or

<p class="calibre1"><sup class="calibre2" id="v3001001">1</sup>
<p class="calibre1"><sup class="calibre2" id="v3001002">2</sup>
.........
<p class="calibre1"><sup class="calibre2" id="v3001024">24</sup>


Which formulas i have to use?
geniale is offline   Reply With Quote
Old 09-14-2015, 12:14 PM   #7
Thom*
The Fumbler
Thom* began at the beginning.
 
Posts: 66
Karma: 10
Join Date: Jun 2015
Device: android 4.2/fbreader
If I understand correctly, you could try this.

In the search window, make sure that "regex" and "current file" are selected.

Search for:
<p class="calibre2"><sup class="calibre3">(.*?)</sup>
Replace with:
<p id="id_v300100\1" class="calibre1"><sup class="calibre2">\1</sup>
Run this for chapter 1.

Change id_v3001 to "id_v3002" in the replace string.
Run this for chapter 2.

etc.

With the info you provided I don't see any alternative but to run this once for each chapter.
I haven't tested this, but it should work.
Thom* is offline   Reply With Quote
Old 09-14-2015, 03:10 PM   #8
geniale
Member
geniale began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Sep 2015
Device: none
Lightbulb

Quote:
Originally Posted by Thom* View Post
If I understand correctly, you could try this.

In the search window, make sure that "regex" and "current file" are selected.

Search for:
<p class="calibre2"><sup class="calibre3">(.*?)</sup>
Replace with:
<p id="id_v300100\1" class="calibre1"><sup class="calibre2">\1</sup>
Run this for chapter 1.

Change id_v3001 to "id_v3002" in the replace string.
Run this for chapter 2.

etc.

With the info you provided I don't see any alternative but to run this once for each chapter.
I haven't tested this, but it should work.
***************
Thanks for your answer. Only that there is a problem.
from 1 to 9 the result is:
<p id="v3001001" class="calibre1"><sup class="calibre2">\1</sup>
from 10 to 99 the result is:
<p id="v30010099" class="calibre1"><sup class="calibre2">\1</sup>
from 100 to 999 the result is:
<p id="v300100999" class="calibre1"><sup class="calibre2">\1</sup>

I need an id of only 7 numbers.
There are 8 numbers in case of 99, and there are 9 numbers in case of 999.

Has anyone else another idea to change ALL the chapters with ONE regular expression?
geniale is offline   Reply With Quote
Old 09-15-2015, 12:36 AM   #9
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by geniale View Post
Has anyone else another idea to change ALL the chapters with ONE regular expression?
I don't think it is possible. I don't think the regex parser has access to the file name put it into the result string.

It's possible that the Function Mode can do something. There is an example to allow automatic numbering within the matches. Adapting that might work.
davidfor is offline   Reply With Quote
Old 09-15-2015, 03:10 AM   #10
geniale
Member
geniale began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Sep 2015
Device: none
Thumbs up

Quote:
Originally Posted by davidfor View Post
I don't think it is possible. I don't think the regex parser has access to the file name put it into the result string.

It's possible that the Function Mode can do something. There is an example to allow automatic numbering within the matches. Adapting that might work.
An example please, i have no idea and i don't understand what do you mean
geniale is offline   Reply With Quote
Old 09-15-2015, 04:18 AM   #11
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Why is it essential to have an Id that is always exactly seven numbers.
Why are you complaining about case 999 when you have said that 24 is your largest value.
Why does all have to be done in one single expression and not in multiple passes.
It seems you turn each offered help into a Not Good Enough gripe.
Buy a regex programming book. Or...Convert back to Word doc and fix it there. Or, convert to Kepub which adds Id to every paragraph anyway....
Or continue to try people's patience...
cybmole is offline   Reply With Quote
Old 09-15-2015, 04:26 AM   #12
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
PS. A 2nd regex shrinking all eight number Id back to seven is simple to write. Please explain why, if that is not acceptable.
no sense in bothering giving you that code if it does not meet your ridiculous one pass criteria
cybmole is offline   Reply With Quote
Old 09-15-2015, 06:23 AM   #13
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by geniale View Post
An example please, i have no idea and i don't understand what do you mean
Did you look at the link? It is the help for the function mode and has examples. Including, as I said, an example for automatically numbering. Beyond that, I can't say much as I haven't used it much myself.
davidfor is offline   Reply With Quote
Old 09-15-2015, 08:09 AM   #14
geniale
Member
geniale began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Sep 2015
Device: none
Unhappy

Quote:
Originally Posted by cybmole View Post
Why is it essential to have an Id that is always exactly seven numbers.
Why are you complaining about case 999 when you have said that 24 is your largest value.
Why does all have to be done in one single expression and not in multiple passes.
It seems you turn each offered help into a Not Good Enough gripe.
Buy a regex programming book. Or...Convert back to Word doc and fix it there. Or, convert to Kepub which adds Id to every paragraph anyway....
Or continue to try people's patience...
Sorry, it wasn't my intention to complain or to be a Not Good enough person.

I only asked if there is the posibility to insert an id of 7 numbers with this format v0000000 (1 book, 3 chapter, 3 paragraf) and where the las 3 numbers are for the paragraph.
I need this id for an android program that uses that format. The HTML files after making that changes i will copy-paste to the folder of this APP. I have more than 550 parragraphs.

Once again sorry!!!!!!
geniale is offline   Reply With Quote
Old 09-15-2015, 09:28 AM   #15
cybmole
Wizard
cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.cybmole ought to be getting tired of karma fortunes by now.
 
Posts: 3,720
Karma: 1759970
Join Date: Sep 2010
Device: none
Ok , I would do it in stages. Generate the para numbers, then add the chapter numbers. Something like MS Word has extensive numbering tools, for creating scientific papers, so do most of the work before making the e pub, maybe.
And ask the folks who sold you the app for tools to assist. What is the app?
cybmole is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
More than 3 regular expression? james968 Conversion 1 04-04-2012 05:39 AM
Regular Expression Help iKarampa Calibre 13 12-15-2010 07:17 AM
Regular expression help krendk Calibre 4 12-04-2010 04:32 PM
Regular Expression Help smartmart Calibre 5 10-17-2010 05:19 AM
Help with the regular expression Dysonco Calibre 9 03-22-2010 10:45 PM


All times are GMT -4. The time now is 01:16 AM.


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