Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 09-22-2022, 03:21 PM   #16
Coldturkey
Junior Member
Coldturkey began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Mar 2018
Device: IPad mini
I don't think I was "pissy" but if so I apologise.
Where did KevinH provide the solution using the plugin? I've re-read the posts and can't see it.
Coldturkey is offline   Reply With Quote
Old 09-22-2022, 04:42 PM   #17
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 2,584
Karma: 15678901
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2 & Air/Surface Pro/Kindle PW
Quote:
Originally Posted by KevinH View Post
You do not need actual regex "function replace" to handle what you wanted but you could use it.

If you use just normal Sigil regex find replace, then something like the following should handle it:

Find: <div\s*xml:lang=\"es\-MX\">\s*<div>(\s*.*)</div>\s*</div>

Replace: <blockquote>\1</blockquote>

And make sure you have Dot All and Minimal Match options checked.

If you wanted to use the function replace capability then using the same Find value and flags, and then in the replace function you could use a xhtml parser to parse the captured snippet and change it to whatever you want. That is the power of function replacement.
Blue highlighted area.
Turtle91 is offline   Reply With Quote
Old 09-22-2022, 08:43 PM   #18
Coldturkey
Junior Member
Coldturkey began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Mar 2018
Device: IPad mini
I didn't think I was being "pissy’ but if so I apologise.
I've gone through the comments that KevinH made and I can't see an example of the plug-in being used which is what celiapgt asked for and what I am interested in.
Please point out where the example was provided.
Coldturkey is offline   Reply With Quote
Old 09-22-2022, 09:00 PM   #19
Coldturkey
Junior Member
Coldturkey began at the beginning.
 
Posts: 4
Karma: 10
Join Date: Mar 2018
Device: IPad mini
Hi Turtle91 thanks for your response but I'm sorry but the blue highlighted part isn't providing an example.
The syntax for using the existing find and replace function is provided but not for using the plug-in to do that
I'm not a coder so that statement doesn't tell me what the exact syntax for the solution would be.
I'm not across Python and frankly no longer have the mental capacity to learn another coding language.
I was hoping this plug-in would enable me to do somrthing like:
if text="made to" then replace with "started to"
else if text="making to" then replace with "began to"
Coldturkey is offline   Reply With Quote
Old 09-23-2022, 07:58 AM   #20
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 2,584
Karma: 15678901
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2 & Air/Surface Pro/Kindle PW
Quote:
Originally Posted by DiapDealer View Post


Besides... KevinH provided both a solution without using the plugin AND a roadmap for doing the same with a replacement function via the plugin.
Yes, he didn’t give an exact example, he gave a “roadmap”.

Your example is not really a “function” either… or, at least, it is something that would be easier as two simple find/replace actions.

As KevinH mentioned, the find phrase would be the same, but the replace portion would have to be some sort of function. Unfortunately you would need to know the language the plug-in uses. I haven’t used this plug-in yet, but I suspect it is similar to Calibre’s implementation. Here is an example of a replacement function that uses a spelling dictionary to replace mi-shyphenated words:

Code:
import regex
from calibre import replace_entities
from calibre import prepare_string_for_xml

def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):

    def replace_word(wmatch):
        # Try to remove the hyphen and replace the words if the resulting
        # hyphen free word is recognized by the dictionary
        without_hyphen = wmatch.group(1) + wmatch.group(2)
        if dictionaries.recognized(without_hyphen):
            return without_hyphen
        return wmatch.group()

    # Search for words split by a hyphen
    text = replace_entities(match.group()[1:-1])  # Handle HTML entities like &amp;
    corrected = regex.sub(r'(\w+)\s*-\s*(\w+)', replace_word, text, flags=regex.VERSION1 | regex.UNICODE)
    return '>%s<' % prepare_string_for_xml(corrected)  # Put back required entities
Turtle91 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[GUI Plugin] Mass Search/Replace un_pogaz Plugins 17 09-08-2022 05:12 AM
Editor plugin : problem with regex and special characters EbookMakers Development 4 11-14-2019 07:52 AM
[Plugin] ReworkChapterHeads - Add, replace and reformat chapter headings slowsmile Plugins 72 07-12-2019 11:36 PM
[Plugin] QuickPrefsEdit - Edit plugin prefs json files. slowsmile Plugins 3 07-25-2018 08:14 PM
Goodread Perception Expander plugin not shown on plugin list (kobo h2o) www KOReader 4 09-28-2017 10:34 AM


All times are GMT -4. The time now is 03:30 AM.


MobileRead.com is a privately owned, operated and funded community.