Compile to FB2 - is it possible?

Hi all,

FB2 (Fiction Book 2, http://en.wikipedia.org/wiki/FictionBook) is a popular e-book format in Russia. Now I have to use three programs (Scrivener, e-book converter and Fiction Book Editor) in order to create normal (and full-featured) FB2 e-book. The main problem is: there is no direct way to convert ePub into fb2 one-to-one. After converting I have to manual edit FB2 file in order to fix section titles, fix footnotes etc.
So, the main question is: is it possible to add FB2 compiler into Scrivener?

Second Flex Ferrum on this, fb2 is a pretty consistent and convenient ‘literary format’ supported by a vast array of gadgets and software. Open-source, xml-based, and non-proprietary, too. By now, oodles of books in various languages circulate in fb2. Was slightly disappointed by not seeing this format among the Scrivener converters.

It hasn’t come up much - these are the only two requests I’ve ever seen for FB2 support, to be honest. I’d be willing to look at it, but with no promises as supporting more and more custom formats that have to be coded from scratch gets very difficult to support as the formats evolve and change. The main problem, however, is that I cannot find any good documentation on the Fiction Book format in English. There are some overview pages, such as at MobileRead, a sample document in Russian, and then the actual schema. If there’s a detailed explanation, description and tutorial for the FictionBook format in English, please let me know and I’ll be happy to have a look through it.

All the best,
Keith

Oddly enough, there’s indeed little can be found on fb2 workings in English queries. But, come to think of it, the format itself is not rocket science, so there’s nothing much to write to Moscow about. Just a straightforward xml scheme that can easily be implemented along with your html conversion procedures. An exhaustive FB2 specification (with a brief preamble on xml format) in Russian can be found here, and it is in plain technical Russian which can easily be google-translated (tags are self-explanatory anyways). As far as I see, it is not actually a compiled format (like .chm or .djvu), just a conventional text markup (that on top of it somehow chimes with Scrivener’s approach to organizing complex text structures). Hence this suggestion to consider it. :wink:

And, being as these are my first two posts at the forum, thank you and your team for developing this wonderful and inspiring product!

P.S. To whom it may concern:

Oh yeah there’s also a book on FB2 in Russian Кондратович Михаил - Создание электронных книг в формате FictionBook 2.1: практическое руководство (Mikhail Kondratovitch — Compilation of E-Books in FictionBook 2.1 format: A Practical Guide). It can be downloaded here, for free and in several available formats. It describes the markup language in every possible detail.

Thanks for the kind words. :slight_smile:

Actually, the HTML code is all Apple’s - Apple just provides a standard HTML exporter which we uses, so there’s no HTML code on my end that I can adopt for FB2, it would all need to be done from scratch. And it looks as though there is quite a lot to it. (By contrast, epub just requires a bunch of HTML files that I can generate using the Apple converters with some modifications, then a couple of structural XML files. The difficulty here is that the text itself needs converting to XML, not just the structure.) Thanks for the link, I’ve added it to my list of things to investigate. As I say, I can’t promise anything because this does look quite involved and the documentation isn’t ideal (reading XML schemas is not my forte), but I will definitely take a proper look at it.

All the best,
Keith

Hey Keith –

I worked for a company that does an XML IDE (Altova, XMLSpy) and I /can/ read XSD. I sort of do this stuff for a living, except when I’m not made redundant at Christmas. grimace.

I need something to do on the plane when I move back to the States in a couple weeks. Let me know if you want my professional opinion on the amount of work a process would take.

I know you have callouts to java in your code (I remember reading someplace that you can use an external jar file to do some of your compile steps, thought ‘hey that’s cool, could leverage that’…other than that I don’t know what your architecture is or even what language Scrivener is written in…).

In fact, Altova has a tool called MapForce that allows algorithmic XSD <-> XSD conversions, and will generate (license-free/royalty-free) source code in Java or VisualStudio C++/C#.NET. I have a MapForce license and mad skillz. I might be able to produce the conversion libraries for you, gratis. Let me know if you are interested.

As an initial take, from the ^^ discussion, the target format is an XSD, but the internal format is something other-than-XSD. But you /can/ target HTML, so the process would be (based on what you’ve already got):

RTF -> HTML 5.0/XHTML1.1, (either is acceptable)

and then a custom

[X]HTML -> FS2 XSD

mediation library. I’ve looked at both the fb2 XSD, and the html produced by an html compile under MacOS, there’s nothing in either of those that jumps out at me as problematic wrt generating an algorithmic binding conversion library.

Back of the envelope, and aside from the finicky styled-text tags (mixed=“true” is a pita but in this case would just be copy-all constructs), this should be relatively straightforward.

Here, this is me: linkedin.com/in/aentity

rip

Hi, rip,

I should notice what RTF to HTML to FB2 conversion is only one part of the task. Also there are some structure markup tags in FB2, such as sections, subsections, titles, footnotes, metainfo etc. Scrivener should produce this markup properly during the compilation process.

shirozaemon, thank you for support. )

Best regards,
Flex.

Absolutely. No disagreement. Direct to FB2 would be optimum.

On the other hand, the OP has a need now :slight_smile:

I don’t know if Scrivener is doing something DOM-like, or if the conversion process is stream-based, and in any case as I wasn’t around for the initial internal architecture discussion, showing up now, this late in the game and giving my input would be just. a. bit. rude.

I had a look while waiting for the phone to ring (had a job interview; needed the distraction). The problem turns out to be on Apple’s plate (Cocao HTML Writer, according to the meta information). It isn’t generating HTML5 or even XHTML, it generates non-XML compliant HTML4. For example, the meta tags are not closed, and the br tags are also never closed.

Step one: Is there a setting on Cocao HTML Writer, that will cause it to emit HTML5 or XHTML1.1
If no, then Step one: Generate HTML4, then text process to ‘up’ the HTML4 to valid XML.

I’m pretty sure the structure (sections/subsections/titles/etc) I need is available in the HTML. If there is something missing, then I can come up with a list of what might be added to the HTML as meta information, making it a target for algorithmic yada yada yada sorry. :slight_smile: Implementation details. waves hand, dismissively

we shall see.