I can't get this to work.The function considers that it has made just 1 replacement but actually it hasn't. Please view image at:
My find code is:
Code:
<body[^>]*>\K(.+)</body>
And my function is:
Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
from calibre.utils.config import JSONConfig
m = match[0]
if number == 1:
fname = 'beatstones.json'
data['equiv'] = JSONConfig(fname)
if not data['equiv']:
print(f'Problem loading {fname}, no treatment will be done')
return data['equiv'].get(m, m)
import regex
m = match.group()
for key in equiv:
m = regex.sub(rf'\b{key}\b', equiv[key], m)
return m
There are no errors reported. As far as I can see there are no problems from the json file and I can extract the keys from it. It must be a problem with the function but, with my limited knowledge, I can't find it.