diff options
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 87 | ||||
-rw-r--r-- | sw/source/filter/html/htmlnumwriter.cxx | 10 |
2 files changed, 95 insertions, 2 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 5d9232c8b286..044a6ad29e72 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -1847,6 +1847,93 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOleBmpTransparent) CPPUNIT_ASSERT_EQUAL(COL_WHITE, nActualColor); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListsHeading) +{ + // Given a document with lh, lh, li, li, lh and lh nodes: + loadURL("private:factory/swriter", nullptr); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Insert("list 1, header 1"); + pWrtShell->SplitNode(); + pWrtShell->Insert("list 1, header 2"); + pWrtShell->SplitNode(); + pWrtShell->Insert("list 2, item 1"); + pWrtShell->SplitNode(); + pWrtShell->Insert("list 2, item 2"); + pWrtShell->SplitNode(); + pWrtShell->Insert("list 3, header 1"); + pWrtShell->SplitNode(); + pWrtShell->Insert("list 3, header 2"); + SwDoc* pDoc = pWrtShell->GetDoc(); + pWrtShell->Up(false, 5); + { + sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName()); + SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos]; + { + SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode(); + SwTextNode& rTextNode = *rNode.GetTextNode(); + rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName())); + rTextNode.SetCountedInList(false); + } + pWrtShell->Down(false, 1); + { + SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode(); + SwTextNode& rTextNode = *rNode.GetTextNode(); + rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName())); + rTextNode.SetCountedInList(false); + } + } + pWrtShell->Down(false, 1); + { + sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName()); + SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos]; + { + SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode(); + SwTextNode& rTextNode = *rNode.GetTextNode(); + rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName())); + } + pWrtShell->Down(false, 1); + { + SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode(); + SwTextNode& rTextNode = *rNode.GetTextNode(); + rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName())); + } + } + pWrtShell->Down(false, 1); + { + sal_uInt16 nPos = pDoc->MakeNumRule(pDoc->GetUniqueNumRuleName()); + SwNumRule* pNumRule = pDoc->GetNumRuleTable()[nPos]; + { + SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode(); + SwTextNode& rTextNode = *rNode.GetTextNode(); + rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName())); + rTextNode.SetCountedInList(false); + } + pWrtShell->Down(false, 1); + { + SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode(); + SwTextNode& rTextNode = *rNode.GetTextNode(); + rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName())); + rTextNode.SetCountedInList(false); + } + } + + // When exporting to ReqIF: + ExportToReqif(); + + // Then make sure the output is valid xhtml: + SvMemoryStream aStream; + HtmlExportTest::wrapFragment(maTempFile, aStream); + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + CPPUNIT_ASSERT(pDoc); + + // Without the accompanying fix in place, this test would have failed with: + // - In <>, XPath '/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p' not found + // Because the headers of list 1 were inside <div><ol>, not directly under <div>. + assertXPathContent(pXmlDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", + "list 1, header 1"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlnumwriter.cxx b/sw/source/filter/html/htmlnumwriter.cxx index 2fa1e6aa3f6b..cfbf024c6acf 100644 --- a/sw/source/filter/html/htmlnumwriter.cxx +++ b/sw/source/filter/html/htmlnumwriter.cxx @@ -99,6 +99,7 @@ Writer& OutHTML_NumberBulletListStart( SwHTMLWriter& rWrt, // If the list only consists of non-numbered text nodes, then don't start the list. bool bAtLeastOneNumbered = false; sal_uLong nPos = rWrt.m_pCurrentPam->GetPoint()->nNode.GetIndex() + 1; + SwNumRule* pNumRule = nullptr; while (true) { const SwNode* pNode = rWrt.m_pDoc->GetNodes()[nPos]; @@ -108,11 +109,13 @@ Writer& OutHTML_NumberBulletListStart( SwHTMLWriter& rWrt, } const SwTextNode* pTextNode = pNode->GetTextNode(); - if (!pTextNode->GetNumRule()) + if (!pTextNode->GetNumRule() || (pNumRule && pTextNode->GetNumRule() != pNumRule)) { + // Node is not in the same numbering as the previous one. break; } + pNumRule = pTextNode->GetNumRule(); if (pTextNode->IsNumbered()) { bAtLeastOneNumbered = true; @@ -333,6 +336,7 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt, // If the list only consisted of non-numbered text nodes, then don't end the list. bool bAtLeastOneNumbered = false; sal_uLong nPos = rWrt.m_pCurrentPam->GetPoint()->nNode.GetIndex() - 1; + SwNumRule* pNumRule = nullptr; while (true) { const SwNode* pNode = rWrt.m_pDoc->GetNodes()[nPos]; @@ -342,11 +346,13 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt, } const SwTextNode* pTextNode = pNode->GetTextNode(); - if (!pTextNode->GetNumRule()) + if (!pTextNode->GetNumRule() || (pNumRule && pTextNode->GetNumRule() != pNumRule)) { + // Node is not in the same numbering as the next one. break; } + pNumRule = pTextNode->GetNumRule(); if (pTextNode->IsNumbered()) { bAtLeastOneNumbered = true; |