Depending on where you want to insert the text, you can utilize the
replace function mode with the function below
Code:
import regex
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
if not file_name.lower().startswith('chapter'):
return match.group()
name = regex.sub(r'(.+?)(\d+)\.x?html?', r'\1 \2', file_name).title()
header = f'<h1>{name}</h1>'
return regex.sub('(<body[^>]*>)', r'\1' + '\n' + header, match.group(), regex.MULTILINE)
The search string should be: .+
Then press replace all.
This will insert the chapter heading as a h1 header at the very top (just below <body>)