Open HT2313 opened 7 years ago
So this is a bug in the ODT writer? (to test: e.g. the HTML output is correct for the posted docbook input, right?)
Yes. For the DocBook file with single level list with table:
<?xml version="1.0" encoding="UTF-8"?>
<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<orderedlist numeration="arabic">
<listitem>
<simpara>Element 1</simpara>
</listitem>
<listitem>
<simpara>Element 2<?asciidoc-br?>
Table:</simpara>
<informaltable frame="all" rowsep="1" colsep="1">
<tgroup cols="2">
<colspec colname="col_1" colwidth="50*"/>
<colspec colname="col_2" colwidth="50*"/>
<tbody>
<row>
<entry align="left" valign="top">
<simpara>1</simpara>
</entry>
<entry align="left" valign="top">
<simpara>2</simpara>
</entry>
</row>
<row>
<entry align="left" valign="top">
<simpara>3</simpara>
</entry>
<entry align="left" valign="top">
<simpara>4</simpara>
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
<simpara>More text for element 2</simpara>
</listitem>
<listitem>
<simpara>Element 3</simpara>
</listitem>
</orderedlist>
</article>
The HTML output is fine:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title></title>
<style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<ol style="list-style-type: decimal">
<li><p>Element 1</p></li>
<li><p>Element 2<br />
Table:</p>
<table>
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<tbody>
<tr class="odd">
<td><p>1</p></td>
<td><p>2</p></td>
</tr>
<tr class="even">
<td><p>3</p></td>
<td><p>4</p></td>
</tr>
</tbody>
</table>
<p>More text for element 2</p></li>
<li><p>Element 3</p></li>
</ol>
</body>
</html>
And for the table in nested list:
<?xml version="1.0" encoding="UTF-8"?>
<article xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en">
<orderedlist numeration="arabic">
<listitem>
<simpara>Element 1</simpara>
</listitem>
<listitem>
<simpara>Element 2</simpara>
<orderedlist numeration="loweralpha">
<listitem>
<simpara>Element 2.1</simpara>
</listitem>
<listitem>
<simpara>Element 2.1</simpara>
<simpara>Table:</simpara>
<informaltable frame="all" rowsep="1" colsep="1">
<tgroup cols="2">
<colspec colname="col_1" colwidth="50*"/>
<colspec colname="col_2" colwidth="50*"/>
<tbody>
<row>
<entry align="left" valign="top"><simpara>1</simpara></entry>
<entry align="left" valign="top"><simpara>2</simpara></entry>
</row>
<row>
<entry align="left" valign="top"><simpara>3</simpara></entry>
<entry align="left" valign="top"><simpara>4</simpara></entry>
</row>
</tbody>
</tgroup>
</informaltable>
</listitem>
<listitem>
<simpara>Element 2.3</simpara>
</listitem>
</orderedlist>
</listitem>
<listitem>
<simpara>Element 3</simpara>
</listitem>
</orderedlist>
</article>
The output HTML file is also correct:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="generator" content="pandoc" />
<title></title>
<style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<ol style="list-style-type: decimal">
<li><p>Element 1</p></li>
<li><p>Element 2</p>
<ol style="list-style-type: lower-alpha">
<li><p>Element 2.1</p></li>
<li><p>Element 2.1</p>
<p>Table:</p>
<table>
<colgroup>
<col width="50%" />
<col width="50%" />
</colgroup>
<tbody>
<tr class="odd">
<td><p>1</p></td>
<td><p>2</p></td>
</tr>
<tr class="even">
<td><p>3</p></td>
<td><p>4</p></td>
</tr>
</tbody>
</table></li>
<li><p>Element 2.3</p></li>
</ol></li>
<li><p>Element 3</p></li>
</ol>
</body>
</html>
When converting to ODT the table is created but it is placed in <list-item>
element, which is not allowed by the the spec. To get around of this problem, when you found table inside of the list you have to close that list , put table and then continue with the list. (At least LibreOffice work in this way).
So this issue seems pretty much a duplicate of #2027 then: the ODT writer should handle tables in lists differently.
I have the same issue with nested tables in LaTeX.
I'm trying to fix this, but I need some help. Here is a diff for transforming the document:
diff --git a/src/Text/Pandoc/Writers/ODT.hs b/src/Text/Pandoc/Writers/ODT.hs
index 395ef0a9..b880525d 100644
--- a/src/Text/Pandoc/Writers/ODT.hs
+++ b/src/Text/Pandoc/Writers/ODT.hs
@@ -86,7 +86,8 @@ pandocToODT opts doc@(Pandoc meta _) = do
-- handle formulas and pictures
-- picEntriesRef <- P.newIORef ([] :: [Entry])
doc' <- walkM (transformPicMath opts) $ walk fixDisplayMath doc
- newContents <- lift $ writeOpenDocument opts{writerWrapText = WrapNone} doc'
+ doc'' <- walkM (transformLists opts) doc'
+ newContents <- lift $ writeOpenDocument opts{writerWrapText = WrapNone} doc''
epochtime <- floor `fmap` (lift P.getPOSIXTime)
let contentEntry = toEntry "content.xml" epochtime
$ fromStringLazy newContents
@@ -210,3 +211,9 @@ transformPicMath _ (Math t math) = do
, ("xlink:actuate", "onLoad")]
transformPicMath _ x = return x
+
+-- | transform list elements: moving tables to the outside
+transformLists :: PandocMonad m => WriterOptions -> Block -> O m Block
+transformLists opts (BulletList list) = return list
+
+transformLists _ x = return x
With this changes I get an compiler error:
src/Text/Pandoc/Writers/ODT.hs:217:41: error:
• Couldn't match type ‘[[Block]]’ with ‘Block’
Expected type: O m Block
Actual type: StateT ODTState m [[Block]]
• In the expression: return list
In an equation for ‘transformLists’:
transformLists opts (BulletList list) = return list
@jgm, do have any suggestions?
@HT2313 so ODT has no way to have a table inside a list item? So what would be the expected ODT output XML for this markdown input?
1) Lorem ipsum
| Name | Description |
| -------------------|--------------------|
| `param_1` | Lorem ipsum |
| `param_2` | Lorem ipsum |
2) Dolor sit amet
Actually, the output of pandoc 2.9 is pretty good? (rename .zip to .odt) output.zip
At least when I view it in calibre's ebook-viewer:
maybe it's different in LibreOffice and/or OpenOffice?
In Apple's TextEdit it's somewhat funny as well:
no table in libreoffice 6.0 (linux mint)
So what would be the expected XML? or can you post the expected file? is there really no way to have a table inside the list in libreoffice?
It seems that libreoffice makes it hard to create a table within a list. The table gets always created "full width", but the numbered list continues around/after the table - see example (.odt renamed to .zip) libre.zip
Any updates on this?
Hi, I'm using Pandoc 1.19.2.1, to create the ODT files from DocBook with the command that follows:
pandoc -S -s -f docbook -t odt simple.xml -o simple.odt --file-scope
When DocBook file contains table defined within the list, in generated ODT file table is not visible.
Following is the DocBook file with table defined within the list item:
Generated ODT file has following content:
The table is not visible in because it is defined within the
<text:list-item>
element.Following is the algorithm for processing lists with tables:
<text:list>
element<text:list-item>
element<text:list-item>
<text:list-item>
and<text:list>
elements<text:list>
element withtext:continue-numbering="true"
attribute<text:list-header>
element and in that element place the rest of the list item elementsHere is the expected ODT file content:
Table in nested list
Here is the DocBook file content that contains table in nested list:
Expected ODT content is:
Note that in this case when table element is found all opened
<text:list-item>
and<text:list>
elements have to be closed. After table is added reopen appropriate number of<text:list>
and<text:list-item>
elements and continue with list processing. Only the first reopened<text:list>
element should havetext:continue-numbering="true"
attribute.This issue is related to #2027.