View Single Post
Old 11-22-2014, 08:14 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
Function Mode - Not a feature request

Don't know any python so a small request

Cook booking the example for auto numbering (changed to H1's) and if I re-run it then it adds another number (I was even able to figure out how to add the word 'Chapter' all by myself )


Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    section_number = '%d. ' % number
    return match.group(1) + 'Chapter ' +  section_number + match.group(2)

Q - Can someone tell me the tweak to have the function to delete any leading text up to and including the space after the '.' first? If files are rearranged or added or deleted then numbers will be off and re-running the RegEx-Function just adds more. I could do a 'regular' regular expression, but adding the logic to the function would be much handier

Code:
<?xml version='1.0' encoding='utf-8'?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

<head>
  <title>blah</title>
</head>

<body>

  <h1>Chapter 4. Chapter 4. Chapter 4. blah</h1>

</body>

</html>
phossler is offline   Reply With Quote