]> git.lyx.org Git - lyx.git/commitdiff
DocBook: merge code duplicates for HTML and CALS tables.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Fri, 1 Apr 2022 02:12:14 +0000 (04:12 +0200)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Fri, 1 Apr 2022 02:21:31 +0000 (04:21 +0200)
autotests/export/docbook/table_nested.xml
src/insets/InsetTabular.cpp
src/insets/InsetTabular.h

index d61f482a2061d53477fba7d32ccddad46f941f38..ffbb32035c218319934a9bc853167a23588dbd12 100644 (file)
 <informaltable>
 <tbody>
 <tr>
-<td style="width: 110mm;" align='left' valign='top'>
-<para><emphasis role='size_small'>Dict{Any,Any} with 9 entries<!-- \string: --></emphasis></para>
+<td style='width: 110mm;' align='left' valign='top'>
+<para><emphasis role='size_small'>Dict{Any,Any} with 9 entries:</emphasis></para>
 <informaltable>
 <tbody>
 <tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> n<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>1</emphasis> </para>
 </td>
 </tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> s<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>1</emphasis> </para>
 </td>
 </tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> a<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>1</emphasis> </para>
 </td>
 </tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> r<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>2</emphasis> </para>
 </td>
 </tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> t<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>1</emphasis> </para>
 </td>
 </tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> o<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>2</emphasis> </para>
 </td>
 </tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> u<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>1</emphasis> </para>
 </td>
 </tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> e<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>1</emphasis> </para>
 </td>
 </tr>
 <td align='center' valign='top'>
 <para><!-- \textquotesingle --> b<!-- \textquotesingle --></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>=&gt;</emphasis></para>
 </td>
-<td style="width: 3mm;" align='center' valign='top'>
+<td style='width: 3mm;' align='center' valign='top'>
 <para><emphasis role='size_small'>1</emphasis> </para>
 </td>
 </tr>
index 761cb4c6ebe3695ff3d6c81b64aa57be0d34b73a..0d45855f916af6ff731028b7e2b852a66f513528 100644 (file)
@@ -3615,14 +3615,7 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const
 void Tabular::docbookRow(XMLStream & xs, row_type row,
                   OutputParams const & runparams, bool header) const
 {
-       switch (buffer().params().docbook_table_output) {
-       case BufferParams::HTMLTable:
-               docbookRowAsHTML(xs, row, runparams, header);
-               break;
-       case BufferParams::CALSTable:
-               docbookRowAsCALS(xs, row, runparams);
-               break;
-       }
+       docbookRow(xs, row, runparams, header, buffer().params().docbook_table_output);
 }
 
 
@@ -3635,6 +3628,9 @@ std::string Tabular::getVAlignAsXmlAttribute(idx_type cell) const
                return "valign='bottom'";
        case LYX_VALIGN_MIDDLE:
                return "valign='middle'";
+       default:
+               // This case only silences a compiler warning, as all the cases are covered above.
+               return "";
        }
 }
 
@@ -3666,13 +3662,13 @@ std::string Tabular::getHAlignAsXmlAttribute(idx_type cell, bool is_xhtml) const
 }
 
 
-void Tabular::docbookRowAsHTML(XMLStream & xs, row_type row,
-                  OutputParams const & runparams, bool header) const
+void Tabular::docbookRow(XMLStream & xs, row_type row, OutputParams const & runparams, bool header, BufferParams::TableOutput docbook_table_output) const
 {
-       string const celltag = header ? "th" : "td";
+       std::string const row_tag = (docbook_table_output == BufferParams::TableOutput::HTMLTable) ? "tr" : "row";
+       std::string const cell_tag = (docbook_table_output == BufferParams::TableOutput::HTMLTable) ? (header ? "th" : "td") : "entry";
        idx_type cell = getFirstCellInRow(row);
 
-       xs << xml::StartTag("tr");
+       xs << xml::StartTag(row_tag);
        xs << xml::CR();
        for (col_type c = 0; c < ncols(); ++c) {
                if (isPartOfMultiColumn(row, c) || isPartOfMultiRow(row, c))
@@ -3680,10 +3676,12 @@ void Tabular::docbookRowAsHTML(XMLStream & xs, row_type row,
 
                stringstream attr;
 
-               Length const cwidth = column_info[c].p_width;
-               if (!cwidth.zero()) {
-                       string const hwidth = cwidth.asHTMLString();
-                       attr << "style=\"width: " << hwidth << ";\" ";
+               if (docbook_table_output == BufferParams::TableOutput::HTMLTable) {
+                       Length const cwidth = column_info[c].p_width;
+                       if (!cwidth.zero()) {
+                               string const hwidth = cwidth.asHTMLString();
+                               attr << "style='width: " << hwidth << ";' ";
+                       }
                }
 
                attr << getHAlignAsXmlAttribute(cell, false) << " " << getVAlignAsXmlAttribute(cell);
@@ -3692,54 +3690,23 @@ void Tabular::docbookRowAsHTML(XMLStream & xs, row_type row,
                        attr << " colspan='" << columnSpan(cell) << "'";
                else if (isMultiRow(cell))
                        attr << " rowspan='" << rowSpan(cell) << "'";
+               else if (docbook_table_output == BufferParams::TableOutput::CALSTable)
+                       attr << " colname='c" << (c + 1) << "'"; // CALS column numbering starts at 1.
+
+               // All cases where there should be a line *below* this row.
+               if (docbook_table_output == BufferParams::TableOutput::CALSTable && row_info[row].bottom_space_default)
+                       attr << " rowsep='1'";
 
                OutputParams rp = runparams;
                rp.docbook_in_par = false;
                rp.docbook_force_pars = true;
-               xs << xml::StartTag(celltag, attr.str(), true);
+               xs << xml::StartTag(cell_tag, attr.str(), true);
                cellInset(cell)->docbook(xs, rp);
-               xs << xml::EndTag(celltag);
-               xs << xml::CR();
-               ++cell;
-       }
-       xs << xml::EndTag("tr");
-       xs << xml::CR();
-}
-
-
-void Tabular::docbookRowAsCALS(XMLStream & xs, row_type row,
-                                OutputParams const & runparams) const
-{
-       idx_type cell = getFirstCellInRow(row);
-
-       xs << xml::StartTag("row");
-       xs << xml::CR();
-       for (col_type c = 0; c < ncols(); ++c) {
-               if (isPartOfMultiColumn(row, c) || isPartOfMultiRow(row, c))
-                       continue;
-
-               stringstream attr;
-
-               attr << getHAlignAsXmlAttribute(cell, false) << " " << getVAlignAsXmlAttribute(cell);
-
-               if (isMultiColumn(cell))
-                       attr << " colspan='" << columnSpan(cell) << "'";
-               else if (isMultiRow(cell))
-                       attr << " rowspan='" << rowSpan(cell) << "'";
-               else
-                       attr << " colname='c" << (c + 1) << "'"; // Column numbering starts at 1.
-
-               // All cases where there should be a line *below* this row.
-               if (row_info[row].bottom_space_default)
-                       attr << " rowsep='1'";
-
-               xs << xml::StartTag("entry", attr.str(), true);
-               cellInset(cell)->docbook(xs, runparams);
-               xs << xml::EndTag("entry");
+               xs << xml::EndTag(cell_tag);
                xs << xml::CR();
                ++cell;
        }
-       xs << xml::EndTag("row");
+       xs << xml::EndTag(row_tag);
        xs << xml::CR();
 }
 
index f42f5bc77bd4bbf07c9c6a5b68fccd3a4443f42b..217aaa57ed26309af7a7dcf1733f2c40c10ef6e6 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef INSET_TABULAR_H
 #define INSET_TABULAR_H
 
+#include "BufferParams.h"
 #include "Changes.h"
 #include "InsetText.h"
 
@@ -937,11 +938,8 @@ public:
        /// auxiliary function for DocBook
        void docbookRow(XMLStream &, row_type, OutputParams const &,
                                        bool header = false) const;
-       /// auxiliary function for DocBook: export this row as HTML
-       void docbookRowAsHTML(XMLStream &, row_type, OutputParams const &,
-                                       bool header) const;
-       /// auxiliary function for DocBook: export this row as CALS
-       void docbookRowAsCALS(XMLStream &, row_type, OutputParams const &) const;
+       void docbookRow(XMLStream &, row_type, OutputParams const &,
+                                       bool header, BufferParams::TableOutput docbook_table_output) const;
        ///
        docstring xhtmlRow(XMLStream & xs, row_type, OutputParams const &,
                           bool header = false) const;