Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 04-20-2011, 11:47 PM   #1
valex
Enthusiast
valex began at the beginning.
 
Posts: 25
Karma: 26
Join Date: Oct 2010
Location: IL, USA
Device: kindle 3
Question FB2 output and footnotes

FB2 output doesn't support footnotes properly, it just puts e.g. [1] in the text and lists the footnotes themselves at the end of the file. So they need to be corrected manually (the [1] is replaced by proper link etc.) after the conversion. Is it planned to fix the problem?

Thanks.
valex is offline   Reply With Quote
Old 04-21-2011, 03:27 AM   #2
Manichean
Wizard
Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.Manichean is the 'tall, dark, handsome stranger' all the fortune-tellers are referring to.
 
Manichean's Avatar
 
Posts: 3,130
Karma: 91256
Join Date: Feb 2008
Location: Germany
Device: Cybook Gen3
The second use case may be of interest to you.
Manichean is offline   Reply With Quote
Advert
Old 04-21-2011, 06:58 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,487
Karma: 1063785
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
Quote:
Originally Posted by valex View Post
FB2 output doesn't support footnotes properly, it just puts e.g. [1] in the text and lists the footnotes themselves at the end of the file. So they need to be corrected manually (the [1] is replaced by proper link etc.) after the conversion. Is it planned to fix the problem?
No. The input (OEB, the inside of EPUB) to FB2 does not support denoting a footnote (Okay it does but no one uses it). 99.999% of footnotes are interspersed in the document as a normal link. So there is no way for FB2 output to know if the link is a footnote or just a link. The [1] isn't added by the FB2 output as it just translates the OEB it's given into the FB2 format.

It would be possible to use a heuristic to detect [number] is a footnote but I have no plans to do this.
user_none is offline   Reply With Quote
Old 04-25-2011, 09:47 AM   #4
valex
Enthusiast
valex began at the beginning.
 
Posts: 25
Karma: 26
Join Date: Oct 2010
Location: IL, USA
Device: kindle 3
Quote:
Originally Posted by user_none View Post
It would be possible to use a heuristic to detect [number] is a footnote but I have no plans to do this.
I ended up doing exactly that. I use the following script to post-process fb2 file created by Calibre. It converts the [number]s to correct links and creates <body name="notes"> section with the footnotes' texts by applying three regular expressions to the file sequentially. The limitation is it does not support multi-paragraph footnotes and footnotes within footnotes but those are rare. My knowledge of Python is rather rudimentary. Is it possible to configure Calibre to call the script automatically after the conversion to fb2 is done? Is the Calibre's functionality allowing application of regexes limited to internal xhtml representation?

Code:
#!/usr/bin/python

import os
import re
import sys

def file_replace(fname, out_fname, regex, repl):
    tmp_fname = fname + ".tmp"
    out = open(tmp_fname, "w")

    for line in open(fname):
        out.write(re.sub(regex, repl, line))

    out.close()
    if os.path.exists(out_fname):
        os.remove(out_fname)    
    os.rename(tmp_fname, out_fname)


if len(sys.argv) != 3:
    u = "Usage: file_replace <file_name.fb2> <file_name_fixed.fb2>\n"
    sys.stderr.write(u)
    sys.exit(1)

file_replace(sys.argv[1], sys.argv[2], r'<p>\[1\]', r'</section></body><body name="notes"><section><p>[1]')
file_replace(sys.argv[2], sys.argv[2], r'<p>\[(\d+)\](.+)</p>', r'</section><section id="n_\1"><title><p>\1</p></title><p>\2</p>')
file_replace(sys.argv[2], sys.argv[2], r'\[(\d+)\]', r'<a xlink:href="#n_\1" type="note">[\1]</a>')
valex is offline   Reply With Quote
Old 04-25-2011, 10:17 AM   #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,487
Karma: 1063785
Join Date: Jan 2009
Location: Florida, USA
Device: Nook STR
Quote:
Originally Posted by valex View Post
Is it possible to configure Calibre to call the script automatically after the conversion to fb2 is done?
No. However since you've done the hard part I will look at integrating these regexes as an option.
user_none is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
FB2 Output changes user_none Calibre 4 01-10-2011 09:32 AM
FB2 output KarateMonkey Calibre 0 03-14-2010 07:47 PM
FB2 output Solicitous Calibre 1 02-10-2010 11:20 PM
FB2 Output error stahanovez Calibre 2 08-02-2009 03:33 PM
Do footnotes/endnotes work in FB2? rfog HanLin eBook 3 12-05-2008 10:22 PM


All times are GMT -4. The time now is 10:13 AM.


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