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 07-20-2011, 02:24 PM   #1
khromov
Connoisseur
khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.
 
Posts: 83
Karma: 499304
Join Date: Jul 2011
Device: Kindle
Easiest way to add arbitrary HTML to every article?

Hello! I am working on a recipe and need to prepend a title (<h1> tags in html) before every article, but I have found this is not as common of a problem as I anticipated.

What is the easiest way to prepend arbitrary HTML to a finished article? I need to be able to inject it before a certain div inside the processed HTML.
khromov is offline   Reply With Quote
Old 07-20-2011, 02:42 PM   #2
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by zapt0 View Post
What is the easiest way to prepend arbitrary HTML to a finished article? I need to be able to inject it before a certain div inside the processed HTML.
You can use postprocess_html and BeautifulSoup. Find the tag and use insert.
http://www.crummy.com/software/Beaut...mentation.html
Starson17 is offline   Reply With Quote
Advert
Old 07-20-2011, 02:44 PM   #3
khromov
Connoisseur
khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.
 
Posts: 83
Karma: 499304
Join Date: Jul 2011
Device: Kindle
I did figure this one out myself, sort of. I settled with adding the title into the content container (it makes no difference when viewed anyway.)

It's done by using postprocess_html(), which gives you the HTML of each article just before heading to the finished paper.
Code:
 def postprocess_html(self, soup, first_fetch):
        #find container, in my case it's a div with the id attribute set to "story" and insert the HTML you wish, in my case the string '<h1>testing</h1>'
        for link_tag in soup.findAll(attrs={"id" : "story"}):
            link_tag.insert(0,'<h1>testing</h1>')
khromov is offline   Reply With Quote
Old 07-20-2011, 02:49 PM   #4
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 73,897
Karma: 128597114
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by zapt0 View Post
Hello! I am working on a recipe and need to prepend a title (<h1> tags in html) before every article, but I have found this is not as common of a problem as I anticipated.

What is the easiest way to prepend arbitrary HTML to a finished article? I need to be able to inject it before a certain div inside the processed HTML.
If this is because you've defined h1 to be a pagebreak, then that's just really poor code.
JSWolf is offline   Reply With Quote
Old 07-20-2011, 04:20 PM   #5
khromov
Connoisseur
khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.khromov ought to be getting tired of karma fortunes by now.
 
Posts: 83
Karma: 499304
Join Date: Jul 2011
Device: Kindle
Quote:
Originally Posted by JSWolf View Post
If this is because you've defined h1 to be a pagebreak, then that's just really poor code.
Perhaps you didn't understand.

The articles I'm getting do not have any heading, the heading is only existent in the <title> tag of the document, so articles are displayed without a heading. Here's an example:


With my fix, I can add a big text to all the articles with the help of the h1 tag.

Last edited by khromov; 07-20-2011 at 04:23 PM.
khromov is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easiest way to start creating .mobi from HTML using C#? jonj Kindle Formats 9 12-10-2011 11:30 AM
How to add my own html page to recipe naisren Recipes 3 11-17-2010 04:37 PM
Add book as HTML file Mister_R Calibre 5 10-19-2010 10:43 AM
Unable to add HTML files in 0.6.10 nekokami Calibre 2 09-06-2009 11:17 AM
What's the easiest way to get a book on the kindle from TXT or HTML? QU2C371FcY Amazon Kindle 7 05-27-2009 08:55 AM


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


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