View Single Post
Old 02-27-2024, 10:04 AM   #17
lomkiri
Zealot
lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.lomkiri ought to be getting tired of karma fortunes by now.
 
lomkiri's Avatar
 
Posts: 136
Karma: 1000102
Join Date: Jul 2021
Device: N/A
====== Important ======

I realized that a paragraph starting with " — «" and with no further dialog will be split, that is not wanted (and thus you cannot pass the function twice without bad effects). So the new function is :

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

    # Moodify this if you change the form the dialog begins
    abort_if_starting_with_emdash = regex.match('\\s—', match[3])
    
    if match[2] or abort_if_starting_with_emdash:
        return match[0]
    
    else:
        return match[1] + match[3] +'</span></p>\n\n  ' + match[1] + ' — ' + match[4]
This one can be executed twice, and doesn't split either a paragraph with only one dialog.

Anyway, it is advisable to always make a backup of your file when you apply new regexes in "replace all" mode. And to check the result with the button "See what was changed".

Another considerations :
— in french, you need a non-break-space or a narrow-non-break-space after "«" and before "»"
— It is better (but not mandatory) to avoid spaces at the beginning and end of paragraph (so <p class="calibre8"> <span class="calibre3"> — « blabla »</span> </p> becomes <p class="calibre8"><span class="calibre3">— « blabla »</span></p>. But apply first the function, because it is based on the form with spaces, or modify the regex (and the variable "abort_if_starting_with_emdash" in the function).

Last edited by lomkiri; 02-27-2024 at 10:20 AM.
lomkiri is offline   Reply With Quote