|
![]() |
|
Thread Tools | Search this Thread |
![]() |
#1 |
Enthusiast
![]() Posts: 26
Karma: 10
Join Date: Feb 2020
Device: Boox Poke 3, prev Kindle Paperwhite 4
|
Can we run Function mode in Search & replace during the conversion process?
I came across an issue where if I had a list like this:
after it's converted to MOBI in Calibre it's transformed to this:
I realized that this is an issue with the Kindle and not the MOBI itself (I'm using MOBI and not AZW3 so that I can upload to Amazon Kindle and sync across devices). I found a way to fix this by using the Function mode in Search & replace in the editor. However, I don't see the function mode for Search & replace in Common options > Search & replace. Am I missing something here? It seems intuitive to be able to run this automatically during the conversion process. Thanks! ------------------------------------ Here's how to fix the bullet list spacing issue. I noticed that there are other people experiencing the same issue...
Find: <li.*?</li> Function: Code:
import re def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs): s = re.sub('<p[^>]*>', '', match.group()) return re.sub('</p[^>]*>', '', s) |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
No function mode and the editor were created long after conversion. But given your function is so simple you can do it with just plain regular expressions
Code:
<li(.*?)>\s*<p.*?>(.+?)</p>\s*</li> and replace with <li\1>\2</li> |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Enthusiast
![]() Posts: 26
Karma: 10
Join Date: Feb 2020
Device: Boox Poke 3, prev Kindle Paperwhite 4
|
Total regex noob here. I learned something new today.
Thanks kovidgoyal! This will do ![]() |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Multiple Search/Replace as a batch process | idf560 | Library Management | 7 | 05-22-2020 12:30 AM |
Bulk metadata Search/Replace: template function question | meghane_e | Library Management | 3 | 01-24-2019 09:32 PM |
Regex in search problems (NOT Search&Replace; the search bar) | lairdb | Calibre | 3 | 03-15-2017 07:10 PM |
Missing "function mode" for editor's Search & Replace | atux | Editor | 3 | 01-17-2016 08:40 AM |
Search & Replace problems with pdf conversion | Longmatys | Conversion | 1 | 01-25-2012 04:59 AM |