From: Thibaut Cuvelier Date: Fri, 1 Apr 2022 02:12:14 +0000 (+0200) Subject: DocBook: merge code duplicates for HTML and CALS tables. X-Git-Tag: 2.4-beta2~753 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=0ba1b68f6974e61d89243e24257311081fa9d7a1;p=lyx.git DocBook: merge code duplicates for HTML and CALS tables. --- diff --git a/autotests/export/docbook/table_nested.xml b/autotests/export/docbook/table_nested.xml index d61f482a20..ffbb32035c 100644 --- a/autotests/export/docbook/table_nested.xml +++ b/autotests/export/docbook/table_nested.xml @@ -25,18 +25,18 @@ - -Dict{Any,Any} with 9 entries + +Dict{Any,Any} with 9 entries: n - + => - + 1 @@ -44,10 +44,10 @@ s - + => - + 1 @@ -55,10 +55,10 @@ a - + => - + 1 @@ -66,10 +66,10 @@ r - + => - + 2 @@ -77,10 +77,10 @@ t - + => - + 1 @@ -88,10 +88,10 @@ o - + => - + 2 @@ -99,10 +99,10 @@ u - + => - + 1 @@ -110,10 +110,10 @@ e - + => - + 1 @@ -121,10 +121,10 @@ b - + => - + 1 diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index 761cb4c6eb..0d45855f91 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -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(); } diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h index f42f5bc77b..217aaa57ed 100644 --- a/src/insets/InsetTabular.h +++ b/src/insets/InsetTabular.h @@ -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;