02-22-2016, 10:24 PM | #1 |
Cultivator
Posts: 94
Karma: 216
Join Date: Feb 2015
Device: PRST2
|
:help: Auto Numbering With Starting Number Inserted?
I found this would help me reducing time instead editing one by one,
i have to replace h2 with Chapter section with auto numbering, i dont understand how to implement the function to my desire, I want to start with number 501 then if matching each of search will generate itself <h2>Chapter 502</h2> to each html files match inside.. any helP? or can i know how to use Regex Function better? maybe a reusable collection of it? Please point me to the link .. Thanks Code:
From Calibre Function Mode Auto numbering sections Now we will see something a little different. Suppose your HTML file has many sections, each with a heading in an <h2> tag that looks like <h2>Some text</h2>. You can create a custom function that will automatically number these headings with consecutive section numbers, so that they look like <h2>1. Some text</h2>. def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): section_number = '%d. ' % number return match.group(1) + section_number + match.group(2) # Ensure that when running over multiple files, the files are processed # in the order in which they appear in the book replace.file_order = 'spine' Use it with the find expression: (?s)(<h2[^<>]*>)(.+?</h2>) Place the cursor at the top of the file and click Replace all. This function uses another of the useful extra arguments to replace(): the number argument. When doing a Replace All number is automatically incremented for every successive match. Another new feature is the use of replace.file_order – setting that to 'spine' means that if this search is run on multiple HTML files, the files are processed in the order in which they appear in the book. See Choose file order when running on multiple HTML files for details. |
02-22-2016, 10:27 PM | #2 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): section_number = 'Chapter %d. ' % (number + 501) return match.group(1) + section_number + match.group(2) |
Advert | |
|
02-25-2016, 01:17 AM | #3 |
Cultivator
Posts: 94
Karma: 216
Join Date: Feb 2015
Device: PRST2
|
thankyou kovid...
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Auto-numbering | Mondriaan | Calibre | 3 | 07-12-2015 07:20 AM |
Is this possible: Auto-add book/magazine then auto e-mail to device? | runningwithbulls | Library Management | 5 | 09-10-2012 12:27 PM |
Possible to control auto-number generation of folder numbers? | EtrnLwanderer | Calibre | 2 | 02-29-2012 10:29 PM |
Issue with Auto Numbering | Pinecone | Library Management | 3 | 07-15-2011 04:50 PM |
How to stop eBookLibrary from auto-starting? | Kypt | Sony Reader | 11 | 10-31-2009 09:03 PM |