For those following the suggestion for a python function replace capability, I have grabbed current RegexFunctionReplace plugin and have updated it to PySide6 and added some code to do Python Syntax Highlighting, fixed autosave, run it to test. And it all works again.
To expand it to allow all other Regex flags would be easily done (although those flags canbe set by codes in the Find Field), and to add the ability to do just a find and later replace in just the current file is doable as well.
It does function well. But there are no simple pre-wriiten routines provided, which we could add as well.
I then studied how to possibly integrate it into Sigil itself but there are a few issues that create problems:
ReplaceAll in Sigil is stateless and always work starting with the current file so numbering would be an issue.
Internally we use Qt's QString which is a sequence of utf-16le values, And pcre2 internally works on those. The issue is a match result from pcre2 internal to Sigil uses offsets in the text to each start and end positions within that text all based on positions in utf-16le sequences (ie in QChars).
But Python str type used utf-32le values for each char which means any position offset values provided by Sigil's pcre2 could/would be invalid when provided to Python.
So each PCRE2 match result would have to be properly translated and rebuilt to be used inside Python.
It is not that all of this is insurmountable, but it would require a lot of work. So I really need to see that the revised RegexFunctionReplace plugin can NOT be made to do the job, and that this is something that would be used often by many Sigil users.
|