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

New commits:
commit 0762645519eafe55810adf9e62643e478fa6887c
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 09:58:53 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.
    
    Change-Id: I131402cb577bd16814f56a5bd6bcad7c99947dbd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117246
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit fdf1db0010104294c01c7780d9daba5adf38450b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117226

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;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to