Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 05-23-2012, 05:32 PM   #1
Ravenik
Junior Member
Ravenik began at the beginning.
 
Posts: 4
Karma: 10
Join Date: May 2012
Device: Sony PRS-T1
How to obtain a new page for every chapter in regular expression (search/replace)?

Hi, I am a beginner in Calibre. I convert .epub -> .epub in order to break to a new page for every chapter.
I have chapters' heads in the format: ". XX ." where XX is a number.
My question is if I can force a new page for the destination epub before every chapter, using regular expression? What will I put in Replacement Text to result in a new page?

Currently I have:

Search:
Code:
<p class="calibre2"><span>[\s]*(\. \d\d? \.)
The Test search results OK, finding 77 occurances (correctly=the number of chapters)!!!!!

Replacement:
Code:
<div class="mbp_pagebreak"/></div><p class="mojrozdz1"><span>\1
I thought that <div class="mbp_pagebreak"/></div> will result in new pages (probably also in separate 77 .html files), but it does not.

Generally the above search/replace reg.exp. fails in two ways:
  1. "calibre2" class name is not replaced with "mojrozdz". "mojrozdz" does not occur in the result html files!
  2. <div class="mbp_pagebreak"/></div> does not occur in result file and furthermore there is no new page and no new .html file for each chapter

Please help me to understand what is wrong in my procedure as regards aforementioned failures 1. and 2. ? Calibre 0.8.52
Ravenik is offline   Reply With Quote
Old 05-24-2012, 12:55 AM   #2
ldolse
Wizard
ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.
 
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
The pagebreak you're trying to insert is specific to mobi, not ePub. Try this:

Search Pattern:
Code:
<p[^>]*>\s*<span[^>]*>\s*(\.\s*\d+\s*\.)\s*</span>\s*</p>
Replacement:
Code:
<h2>\1</h2>
Then you need to go to Structure detection and change the chapter detection xpath to:
Code:
//h:h2

Calbre probably flattens the css in a way that mojrozdz1 disappears from your perspective (although it's also possible your regex was bad) - the correct way to do a custom style is to use extra css under Look and Feel. So take whatever you styles you want in mojrozdz1 and add them there for h2:
Code:
h2{text-align:center;}
When your doing these kinds of replacements it's good to enable debugging so you can see what the html looks like at each stage of the conversion. You want to look at html in the parsed and/or structure debug folders to see the results of your search and replace.

Last edited by ldolse; 05-24-2012 at 01:04 AM.
ldolse is offline   Reply With Quote
Old 05-24-2012, 07:04 AM   #3
Ravenik
Junior Member
Ravenik began at the beginning.
 
Posts: 4
Karma: 10
Join Date: May 2012
Device: Sony PRS-T1
Hi, Thanks a lot, your solution works! Now I think I will study a bit about xpath syntax.
Ravenik is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with regular expression search/replace bfollowell Sigil 12 06-20-2013 07:36 PM
Regular Expression: does not replace with spaces murphycc Conversion 3 02-11-2012 01:31 PM
Search & Replace - Regular expression oldbwl Calibre 2 01-09-2011 09:33 AM
Regular expression for chapter combining bremler Sigil 2 12-23-2010 09:06 AM
Find/Replace with regular expression hydrolith Sigil 6 03-01-2010 08:42 PM


All times are GMT -4. The time now is 11:33 PM.


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