For those interested in a Python Function replace capability:
I have continued to update the RegexFunctionReplace to work with current Sigil.
I have attached a screen cap which show it run a titlecase function on the contents of every h1 tag as a simple example:
Code:
Find: <h1\s[^>]*>([^<>]*)</h1>
Code:
# titlecase replacement python function
def replace(match, number, file_name, metadata, data):
def titlecaseit(text):
textlow = text.lower()
result=''
prevc = None
for i, c in enumerate(textlow):
if c.isspace():
result = result + c
else:
if i == 0 or prevc.isspace():
result = result + c.upper()
else:
result = result + c
prevc = c
return result
if match is None:
return ''
if match:
sp = match.start(1) - match.start(0)
ep = match.end(1) - match.start(0)
rv = match.group(0)
newtitle = titlecaseit(match.group(1))
rv = rv[0:sp] + newtitle + rv[ep:]
return rv
return match.group(0)
This is a duplicate of the simple TitleCase code used by Sigil's own TitleCase routine just written in python. Please note this is meant as a simple demonstration function.
That program was run on the Alice in Wonderland epub where one of the xhtml files had been modified to have an h1 tag with "contents" in it.
That h1 tag was found and "fixed".
So I really need to see some examples of things that people are really using python function replacement for so that I know what additional capabilities are actually needed.
So @Turtle91 and others what functions do you actually need and use?
I am still figuring out if and how this might be3 integrated into Sigil itself instead of a plugin, but updating the plugin would certainly help.
If anyone wants a copy of the updated plugin code, please let me know.
FYI: I still need to handle dark mode vs light mode and highlight colours for the updated RegexFunctionReplace plugin as settings and way to see if dark or light when launched.