Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 02-06-2020, 08:30 PM   #1
omin
Enthusiast
omin began at the beginning.
 
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:
  • First item
  • Second Item
  • Third Item

after it's converted to MOBI in Calibre it's transformed to this:

  • First item

  • Second Item

  • Third Item

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)
omin is offline   Reply With Quote
Old 02-06-2020, 09:26 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,367
Karma: 27230406
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>
kovidgoyal is offline   Reply With Quote
Advert
Old 02-08-2020, 08:53 PM   #3
omin
Enthusiast
omin began at the beginning.
 
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
omin is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 08:36 PM.


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