View Single Post
Old 02-15-2025, 03:22 PM   #23
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,893
Karma: 6120478
Join Date: Nov 2009
Device: many
Updated RegexFunctionReplace plugin for Sigil

Hi All,

Okay, I borrowed a bunch of the case change code from calibre and adapted it to work in our Sigil plugin environment. It is ready for testing and feedback.

I have made the following changes since v0.1.0

  • updated to use PySide6 from PyQt5
  • added a working PythonSyntaxHighlighter
  • modified to better indicate replace all progress and completion
  • modified editor to use QPlainTextEdit instead of QTextEdit
  • modified editor to set tab stops to 4 spaces
  • handle dark vs light syntax coloring changes based on Palette.Change events
  • now implements the following case change functions (built-in)
    • uppercase
    • lowercase
    • capitalize
    • titlecase
    • swapcase
    • uppercase_ignore_tags
    • lowercase_ignore_tags
    • capitalize_ignore_tags
    • titlecase_ignore_tags
    • swapcase_ignore_tags
  • All borrowed from calibre and modified to work without icu and in our plugin framework)

Note: Just as was done in the original version, the gui used by this plugin autosaves any new functions you create and once it has completed you simply close the gui to exit


Note: There is no gui to set regular expression flags yet but you can set them right at the start of the Find string as follows:

(?aiLmsu)
  • a: use ASCII instead of the default Unicode
  • i: ignore case
  • L: locale dependent
  • m: multi line
  • s: dotall (dot matches all)
  • u: use Unicode (the default)

For example to search a multi-line source and set dotall in a regular expression to find h1 through h3 tags that have no nested tags in them (just text) you could use the following Find:

(?sm)<h[123]\s[^>]*>([^<>]*)</h[123]>

and of course you can patterns to be non-greedy as normal:
ie. make *?, +?, ??, or {m,n}? [...] match as little text as possible.


So anyone who has used calibre's python function replace to work with case changes, please give this a try and report back any successes and or issues.

It should be very very close to what calibre provides at least for these case change functions.
Attached Files
File Type: zip RegexFunctionReplace_v030.zip (12.0 KB, 115 views)

Last edited by KevinH; 02-16-2025 at 09:12 AM.
KevinH is offline   Reply With Quote