sw/qa/extras/htmlexport/data/NestingInA1.fodt | 47 ++++++++++++++++ sw/qa/extras/htmlexport/htmlexport.cxx | 72 ++++++++++++++++++++++++++ sw/source/filter/html/wrthtml.cxx | 17 +++--- 3 files changed, 129 insertions(+), 7 deletions(-)
New commits: commit 2d1c2f2f42270e1d5247441cb64bbb7c713c0246 Author: Mike Kaganski <[email protected]> AuthorDate: Fri Aug 4 07:46:12 2023 +0300 Commit: Mike Kaganski <[email protected]> CommitDate: Fri Aug 4 12:26:48 2023 +0300 tdf#156602: fix handling of nesting of tables in the document beginning The old code only accounted for a single table in the document start, finding the innermost table, and so ignoring any outer tables there. Do the same as for nesting sections: find the outermost one. Change-Id: Ide0e5bcf7c81e43fa5467da86e2e7e00a7076528 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155332 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/sw/qa/extras/htmlexport/data/NestingInA1.fodt b/sw/qa/extras/htmlexport/data/NestingInA1.fodt new file mode 100644 index 000000000000..439ef0a57d42 --- /dev/null +++ b/sw/qa/extras/htmlexport/data/NestingInA1.fodt @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <table:table table:name="Outer"> + <table:table-column table:number-columns-repeated="2"/> + <table:table-row> + <table:table-cell office:value-type="string"> + <table:table table:name="Inner"> + <table:table-column table:number-columns-repeated="2"/> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>Inner.A1</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>Inner.B1</text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>Inner.A2</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>Inner.B2</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p>Outer.A1</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>Outer.B1</text:p> + </table:table-cell> + </table:table-row> + <table:table-row> + <table:table-cell office:value-type="string"> + <text:p>Outer.A2</text:p> + </table:table-cell> + <table:table-cell office:value-type="string"> + <text:p>Outer.B2</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p>Following text</text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 59b98f44144d..e67452b83317 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -2643,6 +2643,78 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testSingleOleExport) CPPUNIT_ASSERT_EQUAL(tools::Long(450), xReader->GetObjh()); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_Tdf156602) +{ + createSwDoc("NestingInA1.fodt"); + ExportToReqif(); + + SvMemoryStream aStream; + WrapReqifFromTempFile(aStream); + xmlDocUniquePtr pDoc = parseXmlStream(&aStream); + CPPUNIT_ASSERT(pDoc); + + // The outer table must be kept in the document where the outer table is the first element, + // and its A1 starts with a nested table + + // Only two sub-elements must be inside the div: an outer table and a trailing paragraph + assertXPathChildren(pDoc, "/reqif-xhtml:html/reqif-xhtml:div", 2); + // The outer table must have exactly two rows + assertXPath(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr", 2); + // First outer table cell must have two sub-elements: an inner table and a trailing paragraph + assertXPathChildren( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]", + 2); + // The inner table must have exactly two rows + assertXPath( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr", + 2); + // Check all the elements' content + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/reqif-xhtml:p", + "Inner.A1"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[2]/reqif-xhtml:p", + "Inner.B1"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[1]/reqif-xhtml:p", + "Inner.A2"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[2]/reqif-xhtml:p", + "Inner.B2"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[1]/" + "reqif-xhtml:p", + "Outer.A1"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[1]/reqif-xhtml:td[2]/" + "reqif-xhtml:p", + "Outer.B1"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[1]/" + "reqif-xhtml:p", + "Outer.A2"); + assertXPathContent( + pDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:table/reqif-xhtml:tr[2]/reqif-xhtml:td[2]/" + "reqif-xhtml:p", + "Outer.B2"); + assertXPathContent(pDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "Following text"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx index e71459e42007..63ea138ecf08 100644 --- a/sw/source/filter/html/wrthtml.cxx +++ b/sw/source/filter/html/wrthtml.cxx @@ -485,17 +485,20 @@ ErrCode SwHTMLWriter::WriteStream() // respect table and section at document beginning { - SwTableNode * pTNd = m_pCurrentPam->GetPointNode().FindTableNode(); - if( pTNd && m_bWriteAll ) + if (m_bWriteAll) { - // start with table node !! - m_pCurrentPam->GetPoint()->Assign(*pTNd); + while (const SwStartNode* pTNd = m_pCurrentPam->GetPointNode().FindTableBoxStartNode()) + { + // start with table node !! + m_pCurrentPam->GetPoint()->Assign(*pTNd->FindTableNode()); - if( m_bWriteOnlyFirstTable ) - m_pCurrentPam->GetMark()->Assign(*pTNd->EndOfSectionNode()); + if (m_bWriteOnlyFirstTable) + m_pCurrentPam->GetMark()->Assign( + *m_pCurrentPam->GetPointNode().EndOfSectionNode()); + } } - // first node (with can contain a page break) + // first node (which can contain a page break) m_pStartNdIdx = new SwNodeIndex( m_pCurrentPam->GetPoint()->GetNode() ); SwSectionNode * pSNd = m_pCurrentPam->GetPointNode().FindSectionNode();
