DocBook: merge code duplicates for HTML and CALS tables.

This commit is contained in:
Thibaut Cuvelier 2022-04-01 04:12:14 +02:00
parent ec01616247
commit 0ba1b68f69
3 changed files with 46 additions and 81 deletions

View File

@ -25,18 +25,18 @@
<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>
@ -44,10 +44,10 @@
<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>
@ -55,10 +55,10 @@
<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>
@ -66,10 +66,10 @@
<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>
@ -77,10 +77,10 @@
<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>
@ -88,10 +88,10 @@
<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>
@ -99,10 +99,10 @@
<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>
@ -110,10 +110,10 @@
<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>
@ -121,10 +121,10 @@
<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>

View 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;
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 << "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::EndTag(cell_tag);
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::CR();
++cell;
}
xs << xml::EndTag("row");
xs << xml::EndTag(row_tag);
xs << xml::CR();
}

View 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;