Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 03-28-2017, 09:48 PM   #1
anleva
Enthusiast
anleva began at the beginning.
 
Posts: 39
Karma: 10
Join Date: Nov 2011
Device: Kindle Paperwhite
Convert hyperlinks to plain text

What's the best way to convert hyperlinks to plain text in my recipes? I often accidentally touch a hyperlink in my Kindle when turning pages and it tries to then bring up a browser to the link. I'd rather just remove all the hyperlinks if possible.
anleva is offline   Reply With Quote
Old 03-28-2017, 09:50 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: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Use postprocess_html and simply remove the href attribute from all <a> tags.
kovidgoyal is offline   Reply With Quote
Old 03-28-2017, 10:36 PM   #3
anleva
Enthusiast
anleva began at the beginning.
 
Posts: 39
Karma: 10
Join Date: Nov 2011
Device: Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
Use postprocess_html and simply remove the href attribute from all <a> tags.
This is definitely a bit beyond me as I am not very knowledgeable about python or HTML. Here is what I came up with, but it doesn't seem to do it. What's missing?

def postprocess_html(self, soup):
for a in soup.findAll('a', href=True):
del a['href']
return soup

Last edited by anleva; 03-28-2017 at 11:50 PM.
anleva is offline   Reply With Quote
Old 03-29-2017, 03:49 AM   #4
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: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
postprocess_html takes two arguments, otherwise it looks fine.
kovidgoyal is offline   Reply With Quote
Old 03-29-2017, 09:27 AM   #5
anleva
Enthusiast
anleva began at the beginning.
 
Posts: 39
Karma: 10
Join Date: Nov 2011
Device: Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
postprocess_html takes two arguments, otherwise it looks fine.
I changed it to the following and added it to my recipe, no hyperlinks were removed. They were not removed in the previous version either. What's wrong with the code?

def postprocess_html(self, soup, first_fetch):
for a in soup.findAll('a', href=True):
del a['href']
return soup
anleva is offline   Reply With Quote
Old 03-29-2017, 10:51 AM   #6
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: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You probably got the indentation level wrong.
kovidgoyal is offline   Reply With Quote
Old 03-29-2017, 12:37 PM   #7
anleva
Enthusiast
anleva began at the beginning.
 
Posts: 39
Karma: 10
Join Date: Nov 2011
Device: Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
You probably got the indentation level wrong.
Is this right?

anleva is offline   Reply With Quote
Old 03-29-2017, 07:45 PM   #8
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: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No, the indentation of the entire postprocess_html method needs to be increased by one level so that it belongs to the class
kovidgoyal is offline   Reply With Quote
Old 03-29-2017, 08:16 PM   #9
anleva
Enthusiast
anleva began at the beginning.
 
Posts: 39
Karma: 10
Join Date: Nov 2011
Device: Kindle Paperwhite
kovidgoyal, you are the man! That worked. Thanks for your patience, I am learning much along the way.

anleva
anleva is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to paste as plain-text in Sigil? elenderg Sigil 4 09-28-2016 05:27 PM
How does ebook-convert react to plain text input porphyry5 Conversion 7 11-06-2015 07:27 PM
New Software: convert plain text files to epub/mobi format MobiEpubMaker Workshop 38 04-27-2015 05:52 AM
convert plain text to other formats ? Joebill Other formats 6 05-10-2010 11:10 PM
A java/Groovy program to convert plain text into pdf for eslick dracodoc PDF 1 04-12-2009 09:29 AM


All times are GMT -4. The time now is 04:25 AM.


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