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 01-05-2019, 08:03 AM   #1
jma1
Connoisseur
jma1 began at the beginning.
 
Posts: 82
Karma: 10
Join Date: Dec 2015
Device: Kindle
Convert links to text in downloaded news

Downloaded news feeds can contain many hyperlinks to web pages which exist in the RSS articles. Using my kindle I can't stop inadvertently pressing text with embedded links and jumping to web pages when I only want to page forward in the document.

Is there a recipe command that would convert all the web hyperlinks to 'flat' text, i.e. the text with underscoring still appears with the article but there is no underlying link to a web page.

I did try this code found in a sticky recipe post but it does not kill the links.

Spoiler:
def preprocess_html(self, soup):
for alink in soup.findAll('a'):
if alink.string is not None:
tstr = alink.string
alink.replaceWith(tstr)
return soup

Thanks in advance.
jma1 is offline   Reply With Quote
Old 01-05-2019, 10:32 AM   #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,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
That code wil lwork fine as long as you insert it with the correct indentation in the recipe and then run the customized recipe not th ebuiltin one.
kovidgoyal is offline   Reply With Quote
Advert
Old 01-05-2019, 12:49 PM   #3
jma1
Connoisseur
jma1 began at the beginning.
 
Posts: 82
Karma: 10
Join Date: Dec 2015
Device: Kindle
Kovid,
I checked indentation on the code and believe it is correct but am not an expert. The hyperlinks are all still active.

I am testing with a copy of the latest Fox News recipe that you loaded as built-in some time ago. Is there some other code to be added to reflect 'customized recipe'?

Copy of test recipe attached. Thanks in advance.
Attached Files
File Type: recipe test nws_1061.recipe (2.2 KB, 122 views)
jma1 is offline   Reply With Quote
Old 01-05-2019, 10:31 PM   #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,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
preprocess_html has to a be memeber of the recipe class, which means it has to be inside the class definition indented by four spaces.
kovidgoyal is offline   Reply With Quote
Old 01-06-2019, 10:20 AM   #5
jma1
Connoisseur
jma1 began at the beginning.
 
Posts: 82
Karma: 10
Join Date: Dec 2015
Device: Kindle
I moved the code inside the "class testnewssource(BasicNewsRecipe):" statement, so at the very bottom of the recipe, with same indent of 4 as the feeds, but the links are all still active.
jma1 is offline   Reply With Quote
Advert
Old 01-06-2019, 11:02 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,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
here you go
Attached Files
File Type: recipe test nws_1061.recipe (2.3 KB, 124 views)
kovidgoyal is offline   Reply With Quote
Old 01-06-2019, 12:02 PM   #7
jma1
Connoisseur
jma1 began at the beginning.
 
Posts: 82
Karma: 10
Join Date: Dec 2015
Device: Kindle
Great - that works.

Is there any easy way to retain the blue text formatting for the linked-text, as a visible indicator that the original article has a link embedded below that text? Thanks.
jma1 is offline   Reply With Quote
Old 01-06-2019, 08:07 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,843
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
a['style'] = 'color: blue'
kovidgoyal is offline   Reply With Quote
Old 01-06-2019, 10:27 PM   #9
jma1
Connoisseur
jma1 began at the beginning.
 
Posts: 82
Karma: 10
Join Date: Dec 2015
Device: Kindle
Great - thanks again.
jma1 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert external links to internal links sup Recipes 2 11-28-2013 09:39 AM
news paper not getting downloaded gp_mbe Recipes 2 11-15-2012 06:32 AM
Kindle 3: Downloaded news has [?] in some of the articals? CalgaryToad Devices 5 02-01-2011 10:18 AM
different "delete downloaded news" values per news source? scottfree Calibre 1 01-19-2011 11:15 AM
Add only news tag to downloaded news? eric11210 Calibre 2 08-06-2010 05:51 AM


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


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