Usually in the table of content of a book, each line is for a chapter or section and ends with its page number, for example:

1 first chapter 10
1.1 first section 11
1.1.1 first subsection 12
1.2 second section 13
2 second chapter 14 
2.1 first section 16
2.2 second section 13

The format of bookmarks in djvu files for the above example is:

 ("1 first chapter" "#10" 
 ("1.1 first section" "#11" 
 ("1.1.1 first subsection" "#12" ))
 ("1.2 second section" "#13" ))
 ("2 second chapter" "#14" 
 ("2.1 first section" "#16" )
 ("2.2 second section" "#13" ))

where the main points are the pairing of left and right parenthesis for tree-like organization of sections and chapters, double quotes for each bookmark item and each page number preceded by a #. The separation between lines and indention are just for convenience to manually view and edit the bookmark text file, and don't matter at all.

My questions are:

  1. Are there any convenient ways to convert a plain text file of table of contents into djvu bookmark format, which can reduce manual handling as much as possible? This may be achieved by text processing applications, or programming under some programming language, or a combination of both.

  2. As suggested in a related reply by Dennis Williamson,

    What you're doing is starting to look a little bit like XML. Perhaps you should use the real thing and use proper tools to manipulate it.

    a quick google turns up djvuxml. XML files can be easily manipulated using the appropriate Python or Perl module or shell utilities such as xmlstarlet.

    I wonder if djvu bookmark format is similar to XML format (I admit I am not familiar with XML yet, but willing to learn it if it can help here)? Can XML tools be used to convert a text file of table of contents into djvu bookmark format?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.