johnfactotum / foliate

Read e-books in style
https://johnfactotum.github.io/foliate/
GNU General Public License v3.0
6.45k stars 298 forks source link

Tables not working in fb2 #1445

Closed luiswoo closed 1 day ago

luiswoo commented 2 days ago

Is your feature request related to a problem? Please describe. Apparently in Foliate the fb2 format does not support displaying tables.

Describe the solution you'd like Display tables in Foliate for fb2 format.

Describe alternatives you've considered As far as I know, tables in fb2 format are supported in Okular and CoolReader programs, as well as on flibusta.is website. (Some programs, sometimes, like FineReader, format an image and a caption for that image as a table.)

Additional context As I understand from the description (http://www.fictionbook.org/index.php/%D0%AD%D0%BB%D0%B5%D0%BC%D0%B5%D0%BD%D1%82_table), a table is denoted by: the table body by the tag (table); a row denoted by the tag (tr); a cell within a row denoted by the tag (th). Example structure: (table) (tr) (th)(/th) (/tr) (/table)

Example fb2 file with table:

<?xml version="1.0" encoding="utf-8"?> <FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink"> <description> <title-info> <genre>sf_cyberpunk</genre> <author> <first-name>your</first-name> <last-name>name</last-name> </author> <book-title>table</book-title> <annotation> <p>annotation</p> </annotation> <date></date> <lang>en</lang> </title-info> <document-info> <author> <first-name>Your</first-name> <last-name>Name</last-name> </author> <program-used>FictionBook Editor Release 2.6.7</program-used> <date value="2014-11-10">10 November 2014</date> <id>C0F9066B-EE5B-442B-B92F-202163D35E95</id> <version>1.0</version> <history> <p>1.0 — file creation</p> </history> </document-info> </description> <body> <section> <title> <p>Chapter 1. Table</p> </title> <p>text</p> <subtitle>table</subtitle> <empty-line/> <table> <tr align="center"> <th align="center" valign="middle"/> <th align="center" valign="middle">Number of small wooden animals</th> <th align="center" valign="middle">Cost $1.25 each</th> <th align="center" valign="middle">Resale price of $2.50</th> </tr> <tr align="center"> <th align="center" valign="middle">Order #1</th> <td align="center" valign="middle">100,000</td> <td align="center" valign="middle">$125,000</td> <td align="center" valign="middle">$250,000 (which Grimm then reinvested)</td> </tr> <tr align="center"> <th align="center" valign="middle">Order #2</th> <td align="center" valign="middle">200,000 (which burned in the fire)</td> <td align="center" valign="middle">$250,000 (which Grimm must pay for a shipment arriving on August 28)</td> <td align="center" valign="middle">$500,000</td> </tr> <tr align="center"> <th align="center" valign="middle">Order #3</th> <td align="center" valign="middle">400,000 (arriving August 28)</td> <td align="center" valign="middle">$500,000 (which Grimm won't have if insurers don't pay)</td> <td align="center" valign="middle">$1,000,000</td> </tr> </table> <empty-line/> </section> </body> </FictionBook>

Screenshot of what it looks like in CoolReader (this program does not correctly display alignment in cells): Снимок экрана от 2024-12-01 11-19-51

https://flibusta.is/b/807792/read - in the first chapter, almost at the beginning.

luiswoo commented 2 days ago

An excerpt of the FictionBook2.2 XML schema that is responsible for tables:

<xs:element name="table" type="tableType"/>
....
<xs:complexType name="tableType">
  <xs:annotation>
   <xs:documentation>Basic html-like tables</xs:documentation>
  </xs:annotation>
  <xs:sequence>
   <xs:element name="tr" maxOccurs="unbounded">
    <xs:complexType>
     <xs:choice maxOccurs="unbounded">
      <xs:element name="th" type="tdType"/>
      <xs:element name="td" type="tdType"/>
     </xs:choice>
     <xs:attribute name="align" type="alignType" use="optional" default="left"/>
    </xs:complexType>
   </xs:element>
  </xs:sequence>
  <xs:attribute name="style" type="xs:string" use="optional"/>
  <xs:attribute name="id" type="xs:ID" use="optional"/>
 </xs:complexType>

http://www.fictionbook.org/index.php/XML_%D1%81%D1%85%D0%B5%D0%BC%D0%B0_FictionBook2.2