Answers.Body: <p>Somehow I missed that … thanks to <a href="https://ebooks.stackexchange.com/questions/9/clean-up-converted-ebook/12#12">Donald.McLean’s answer</a>, I found it.</p>
  
  <p>In the ePub editor, I hit <kbd>Ctrl</kbd>+<kbd>F</kbd>, and a search &amp; replace tool showed up at the bottom:</p>
  
  <p><img src="https://i.sstatic.net/dgsAQ.png" alt="enter image description here"></p>
  
  <p>I have used the regex mode and the following patterns:</p>
  
  <ul>
  <li><p><code>-&lt;/p&gt;\n&lt;p[^&gt;]*&gt;</code> replaced with <em>nothing</em> to remove paragraph breaks within words. I hit <em>Replace all</em> here.</p></li>
  <li><p><code>\s&lt;/p&gt;\n&lt;p[^&gt;]*&gt;</code> replaced with a single space to remove paragraph breaks within sentences. This had to be done manually, unfortunately, because there were some spaces at the end of lines which should stay separated.</p></li>
  <li><p><code>\n&lt;p[^&gt;]*&gt;\d+&lt;/p&gt;</code> replaced with <em>nothing</em> to remove orphaned page numbers. <em>Replace all</em> again.</p></li>
  </ul>
  
  <p>I have also installed, but not yet tested, the plugin <strong><a href="http://www.mobileread.mobi/forums/showthread.php?t=154371" rel="noreferrer">Modify ePub</a></strong> by Grant Drake. It offers some automated tasks:</p>
  
  <p><img src="https://i.sstatic.net/jHtQO.png" alt="enter image description here"></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-18T22:16:04.063Z
Answers.LastActivityDate: 2013-12-19T05:31:08.023Z
Answers.LastEditDate: 2017-04-13T13:00:05.480Z
Answers.UserDisplayName: fuxia
Answers.Body: <p>In Calibre you can play around Heuristic Processing option while converting your files.
  <a href="https://i.sstatic.net/iJjmZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iJjmZ.png" alt="Calibre book converting options"></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-16T03:52:31.190Z
Answers.LastActivityDate: 2019-01-16T03:52:31.190Z
Answers.UserDisplayName: Valery Noname
Answers.Body: <p>I have not found an elegant way to do this yet. However, the inelegant way works: 
  1. Highlight on the epub to clean. 
  2. Click on convert. 
  3. Set the conversion settings to clean all the things you want (especially in the heuristics section to scan and fix things) and make sure that the output file is epub format. </p>
  
  <p>It will save the original messy file as "original_epub" and create a second epub file. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-06T23:51:55.313Z
Answers.Text: Is it Calibre that you're using for this suggestion?
Answers.UserDisplayName: Tom
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-02T07:43:57.963Z
Answers.Text: These instructions do apply to Calibre. The answer above this one (at present) by @valery-noname has a more complete description.
Answers.UserDisplayName: John T
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-06T19:57:53.823Z
Answers.LastActivityDate: 2014-08-06T19:57:53.823Z
Answers.UserDisplayName: Cthulhu's Son
Answers.Body: <p>Since Epubs are <a href="https://www.w3.org/publishing/epub3/epub-spec.html#sec-intro-spec-org" rel="nofollow noreferrer">just zip archives</a>, you can unzip them and operate on the plain text files underneath. From there, you can use Python or just the find and replace function in a text editor to remove the offending characters.</p>
  <p>One thing to note is that when you rezip it, it is critical that the <code>mimetype</code> file is put in the archive first. Additionally, many readers require the zip file to have no compression, and all require the <code>mimetype</code> to be uncompressed. Check out <a href="https://ebooks.stackexchange.com/a/447/16929">this answer</a> to make sure you put it back together correctly.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-11T05:41:08.123Z
Answers.LastActivityDate: 2022-10-11T05:41:08.123Z
Answers.UserDisplayName: gfaster
Answers.Body: <p>I used "wondershare PDF converter" to convert my pdf to epub, then I opened the epub with Calibre and removed the line breaks with these regex :</p>
  
  <pre><code>&lt;span style=""&gt;([^.&gt;&lt;]*)&lt;/span&gt;\s*&lt;/p&gt;\s*&lt;p&gt;
  </code></pre>
  
  <p>replaced by </p>
  
  <pre><code>&lt;span style=""&gt;\1&lt;/span&gt;
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>¬&lt;/span&gt;\s*&lt;/p&gt;\s*&lt;p&gt;
  </code></pre>
  
  <p>replaced by</p>
  
  <pre><code>&lt;/span&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-05-30T13:51:13.767Z
Answers.LastActivityDate: 2019-05-30T13:51:13.767Z
Answers.UserDisplayName: Anthony
Answers.Body: <p>Calibre has a feature that allows you to unpack an ePub file into the component parts (usually chapters), which you can then edit. When you have finished your edits, Calibre will repackage them back into an ePub file.</p>
  
  <p>From the main Calibre view, right click on the book listing. You should get a popup menu with an option to "Edit book". Selecting this will give you a book editing window where you can edit the individual parts of the book.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2013-12-18T21:47:12.043Z
Answers.LastActivityDate: 2013-12-18T21:47:12.043Z
Answers.UserDisplayName: Donald.McLean
Body: <p>I have some ebooks which are converted from other formats to ePub. Some are ill-formatted: there are hard line breaks in words and orphaned page numbers between paragraphs.</p>
  
  <p>Example:<br>
  <img src="https://i.sstatic.net/kDeOD.png" alt="Screenshot from Calibre"></p>
  
  <p>How can I repair these ebooks? Do I have to open and edit the source files, or is there a better way?</p>
  
  <p>I use Calibre on Windows to organize the ebooks, if that matters, but I am not bound to that program, and I can use Linux too.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-02-06T12:50:19.643Z
Comments.Text: thank you guysfor all your tips from 2014 ...they have saved me now in 2021!
Comments.UserDisplayName: Gonzalo Reyero
Tags: <epub><conversion><calibre>
Title: Clean up converted ebook
UserDisplayName: fuxia
ThreadText: # Clean up converted ebook
  
  (Asked by: username_0 on 2013-12-18)
  
  I have some ebooks which are converted from other formats to ePub. Some are ill-formatted: there are hard line breaks in words and orphaned page numbers between paragraphs.
  
  Example:  
  ![Screenshot from Calibre](https://i.sstatic.net/kDeOD.png)
  
  How can I repair these ebooks? Do I have to open and edit the source files, or is there a better way?
  
  I use Calibre on Windows to organize the ebooks, if that matters, but I am not bound to that program, and I can use Linux too.
  
  **Tags:** epub, conversion, calibre
  
  > **Comments:**
  > **username_1**: thank you guysfor all your tips from 2014 ...they have saved me now in 2021!  
  
  ---
  
  ## 6 answers
  
  ### Answer by username_8 on 2013-12-18. Score: 22 | Accepted answer
  
  Calibre has a feature that allows you to unpack an ePub file into the component parts (usually chapters), which you can then edit. When you have finished your edits, Calibre will repackage them back into an ePub file.
  
  From the main Calibre view, right click on the book listing. You should get a popup menu with an option to "Edit book". Selecting this will give you a book editing window where you can edit the individual parts of the book.
  
  
  ---
  
  ### Answer by username_0 on 2013-12-18. Score: 24
  
  Somehow I missed that … thanks to [username_8’s answer](https://ebooks.stackexchange.com/questions/9/clean-up-converted-ebook/12#12), I found it.
  
  In the ePub editor, I hit `Ctrl`+`F`, and a search & replace tool showed up at the bottom:
  
  ![enter image description here](https://i.sstatic.net/dgsAQ.png)
  
  I have used the regex mode and the following patterns:
  
  * `-</p>\n<p[^>]*>` replaced with *nothing* to remove paragraph breaks within words. I hit *Replace all* here.
  * `\s</p>\n<p[^>]*>` replaced with a single space to remove paragraph breaks within sentences. This had to be done manually, unfortunately, because there were some spaces at the end of lines which should stay separated.
  * `\n<p[^>]*>\d+</p>` replaced with *nothing* to remove orphaned page numbers. *Replace all* again.
  
  I have also installed, but not yet tested, the plugin **[Modify ePub](http://www.mobileread.mobi/forums/showthread.php?t=154371)** by Grant Drake. It offers some automated tasks:
  
  ![enter image description here](https://i.sstatic.net/jHtQO.png)
  
  
  ---
  
  ### Answer by username_2 on 2019-01-16. Score: 3
  
  In Calibre you can play around Heuristic Processing option while converting your files.
  [![Calibre book converting options](https://i.sstatic.net/iJjmZ.png)](https://i.sstatic.net/iJjmZ.png)
  
  
  ---
  
  ### Answer by username_3 on 2014-08-06. Score: 2
  
  I have not found an elegant way to do this yet. However, the inelegant way works:
  1. Highlight on the epub to clean.
  2. Click on convert.
  3. Set the conversion settings to clean all the things you want (especially in the heuristics section to scan and fix things) and make sure that the output file is epub format.
  
  It will save the original messy file as "original\_epub" and create a second epub file.
  
  > **Comments:**
  > **username_4**: Is it Calibre that you're using for this suggestion?  
  > **username_5**: These instructions do apply to Calibre. The answer above this one (at present) by @username_2-username_2 has a more complete description.  
  
  ---
  
  ### Answer by username_6 on 2022-10-11. Score: 1
  
  Since Epubs are [just zip archives](https://www.w3.org/publishing/epub3/epub-spec.html#sec-intro-spec-org), you can unzip them and operate on the plain text files underneath. From there, you can use Python or just the find and replace function in a text editor to remove the offending characters.
  
  One thing to note is that when you rezip it, it is critical that the `mimetype` file is put in the archive first. Additionally, many readers require the zip file to have no compression, and all require the `mimetype` to be uncompressed. Check out [this answer](https://ebooks.stackexchange.com/a/447/16929) to make sure you put it back together correctly.
  
  
  ---
  
  ### Answer by username_7 on 2019-05-30. Score: 0
  
  I used "wondershare PDF converter" to convert my pdf to epub, then I opened the epub with Calibre and removed the line breaks with these regex :
  
  ```
  <span style="">([^.><]*)</span>\s*</p>\s*<p>
  
  ```
  
  replaced by
  
  ```
  <span style="">\1</span>
  
  ```
  
  Then:
  
  ```
  ¬</span>\s*</p>\s*<p>
  
  ```
  
  replaced by
  
  ```
  </span>
  
  ```
  
  
  ---
  
  