sw/qa/extras/htmlexport/htmlexport.cxx  |   87 ++++++++++++++++++++++++++++++++
 sw/source/filter/html/htmlnumwriter.cxx |   10 ++-
 2 files changed, 95 insertions(+), 2 deletions(-)

New commits:
commit 9b4bd79a84353b2630717014d346982c968cc46f
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Jun 15 14:04:57 2021 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Jun 16 10:24:52 2021 +0200

    sw XHTML / reqif export: handle multiple lists when detecting header-only 
lists
    
    The case when the list was at the end of the text node section (body
    text, table cell, etc) was already handled, this handles when the list
    is followed by a different list.
    
    (cherry picked from commit fdf1db0010104294c01c7780d9daba5adf38450b)
    
    Change-Id: I131402cb577bd16814f56a5bd6bcad7c99947dbd

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 750e97594a7d..1fd48f104ed6 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1849,6 +1849,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 84ed431699d8..5b9f484d9995 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;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to