Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 05-28-2010, 03:34 AM   #1
ctop
Member
ctop is on a distinguished road
 
Posts: 15
Karma: 60
Join Date: Jun 2008
Device: zaurus->palm->iPad->Sony PRS-T1
modifying the TXT output format

Hi there,

I would like to slightly modify the TXT output format in the following way: I want to have '*' characters in front of each headline (that is H1 .. H6 in HTML) so that the number of star characters reflects the depth of the headline; e.g. H3 would turn into *** . I wonder how such a change could be made.

Any help welcome!

Ctop
ctop is offline   Reply With Quote
Old 05-28-2010, 04:57 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: 26,122
Karma: 5101571
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Look at the file txtml.py in the source code and change it to do what you need.
kovidgoyal is offline   Reply With Quote
Old 05-29-2010, 07:26 AM   #3
user_none
Sigil & calibre developer
user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.
 
user_none's Avatar
 
Posts: 2,460
Karma: 986493
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
In the txtml.py file look at line 170, # Are we in a paragraph block?. At the end of this block just check for the h tags and append the correct number of *s.

Though instead of making this very specific why not create a new txt output generator that produces markdown text?
user_none is offline   Reply With Quote
Old 06-01-2010, 07:09 AM   #4
ctop
Member
ctop is on a distinguished road
 
Posts: 15
Karma: 60
Join Date: Jun 2008
Device: zaurus->palm->iPad->Sony PRS-T1
Quote:
Originally Posted by user_none View Post
In the txtml.py file look at line 170, # Are we in a paragraph block?. At the end of this block just check for the h tags and append the correct number of *s.
Thanks, I figured that out and it works.

Quote:
Originally Posted by user_none View Post
Though instead of making this very specific why not create a new txt output generator that produces markdown text?
This is an excellent idea. How would I go about that?

Another question: I tried to add more markup, for example italic or bold. I see the settings in the CSS file and even in the intermediate versions I get with debug output, but when I try to work with the styles (for example 'font-style; italic;'), they seem at some point to be changed to 'font-style: normal;' and do not arrive at txtml.py.

Could this be a bug?

I looked around a bit, but could not find where this replacing happens. Just to check I looked at the RTF output, and there seems to be the italic missing as well.

Any help appreciated,

Ctop
ctop is offline   Reply With Quote
Old 06-01-2010, 07:04 PM   #5
user_none
Sigil & calibre developer
user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.user_none ought to be getting tired of karma fortunes by now.
 
user_none's Avatar
 
Posts: 2,460
Karma: 986493
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
Quote:
Originally Posted by ctop
This is an excellent idea. How would I go about that?
Copy txtmlizer.py and name it something like markdownmlizer.py. Then make the changes to markdownmlizer.py like you were doing previously to have it write markdown formatting in the appropriate places.

Supporting the MarkdownMLizer would be the easiest part. In the txt output.py file all you would need to do is add an option (--markdown-output for example) and in the convert function assign the writer variable to the MarkdownMLizer object. For example:

Code:
def convert(self, oeb_book, output_path, input_plugin, opts, log):
    if opts.markdown-output:
        writer = MarkdownMLizer(log)
    else:
        writer = TXTMLizer(log)
    txt = writer.extract_content(oeb_book, opts)
Quote:
Originally Posted by ctop
Could this be a bug?
Most likely yes. Open a ticket so it can be looked into.
user_none is offline   Reply With Quote
Old 06-01-2010, 09:08 PM   #6
ctop
Member
ctop is on a distinguished road
 
Posts: 15
Karma: 60
Join Date: Jun 2008
Device: zaurus->palm->iPad->Sony PRS-T1
Quote:
Originally Posted by user_none View Post
Copy txtmlizer.py and name it something like markdownmlizer.py. Then make the changes to markdownmlizer.py like you were doing previously to have it write markdown formatting in the appropriate places.
I will give this a try. Thanks for the hint!

Quote:
Originally Posted by user_none View Post

Most likely yes. Open a ticket so it can be looked into.
Upon further inspection, it looks more like I am misunderstanding how this works. Investigating further now (or better: as soon as I have time for it).

best,

Ctop
ctop is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I want to change output pdf format miguel.ossa Calibre 7 09-06-2010 01:33 PM
Output Format Query Splashfart Calibre 5 08-23-2010 11:32 PM
Multiple Format Output jim6064 Calibre 4 03-10-2010 01:01 PM
Is it possible to specify output format in recipe file madcow_x2 Calibre 3 01-07-2010 04:10 PM
output filename format jdh Calibre 6 08-12-2009 09:35 PM


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


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