sw/qa/extras/htmlexport/htmlexport.cxx  |   53 ++++++++++++++++++++++++++++++++
 sw/qa/inc/swmodeltestbase.hxx           |    2 +
 sw/qa/unit/swmodeltestbase.cxx          |    7 ++++
 sw/source/filter/html/htmlnumwriter.cxx |   21 +++++-------
 4 files changed, 71 insertions(+), 12 deletions(-)

New commits:
commit 54298f7f23e699e99e979bdf945c6ae2bee1a12f
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Thu Dec 1 11:39:05 2022 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Wed Feb 8 11:09:46 2023 +0000

    htmlexport: close li mark not only in xhtml
    
    As commented in sw/source/filter/html/htmlatr.cxx:766
    "// OutHTML_NumberBulletListEnd() will end a list item"
    
    We have to do it also in HTML not only XHTML so node will be
    closed and we get correct structure.
    
    This is followup for:
    commit 2466b9fcf20ee61f6fc621298011c0efaa55e7c6
    Author: Miklos Vajna <vmik...@collabora.com>
    Date:   Mon Feb 21 16:38:51 2022 +0100
    
        sw HTML export, XHTML mode: fix lost </li> when last list item is not 
numbered
    
    Change-Id: I99baa59b437572b157df8057445cf6c741f936b4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143508
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146651
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 11ab26d56185..670feca6b4c1 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -272,6 +272,8 @@ public:
     void ExportToReqif();
     /// Import using the C++ HTML import filter, with xhtmlns=reqif-xhtml.
     void ImportFromReqif(const OUString& rUrl);
+    /// Export using the C++ HTML export filter
+    void ExportToHTML();
 };
 
 OUString SwHtmlDomExportTest::GetOlePath()
@@ -322,6 +324,15 @@ void SwHtmlDomExportTest::ExportToReqif()
     save("HTML (StarWriter)");
 }
 
+void SwHtmlDomExportTest::ExportToHTML()
+{
+    uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+    uno::Sequence<beans::PropertyValue> aStoreProperties = {
+        comphelper::makePropertyValue("FilterName", OUString("HTML 
(StarWriter)")),
+    };
+    xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+}
+
 void SwHtmlDomExportTest::ImportFromReqif(const OUString& rUrl)
 {
     uno::Sequence<beans::PropertyValue> aLoadProperties = {
@@ -1520,6 +1531,48 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testPartiallyNumberedList)
                 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
 2);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testPartiallyNumberedListHTML)
+{
+    // Given a document with a list, first para is numbered, second is not:
+    createSwDoc();
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Insert("list header");
+    SwDoc* pDoc = pWrtShell->GetDoc();
+    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->Insert2("numbered");
+    pWrtShell->SplitNode();
+    pWrtShell->Insert2("not numbered");
+    {
+        SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+        SwTextNode& rTextNode = *rNode.GetTextNode();
+        rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+        rTextNode.SetCountedInList(false);
+    }
+
+    // When exporting to HTML:
+    ExportToHTML();
+
+    SvMemoryStream aStream;
+    WrapFromTempFile(aStream);
+    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
+    CPPUNIT_ASSERT(pXmlDoc); // if we have missing closing marks - parse error
+
+    // Without the accompanying fix in place, this test would have failed:
+    // - expected: <li><p>...</p><p>...</p></li>
+    // - actual  : <li><p>...</p><p>...</p>
+    // because a <li> without a matching </li> is not well-formed, and the 
</li> was omitted because
+    // the second para was not numbered.
+
+    assertXPath(pXmlDoc, "/html/body/ol/li/p", 2);
+}
+
 CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListHeaderAndItem)
 {
     // Given a document with a list, first para is not numbered, but the 
second is:
diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx
index dda083f76539..4c5ba58103d5 100644
--- a/sw/qa/inc/swmodeltestbase.hxx
+++ b/sw/qa/inc/swmodeltestbase.hxx
@@ -341,6 +341,8 @@ protected:
      */
     void WrapReqifFromTempFile(SvMemoryStream& rStream);
 
+    void WrapFromTempFile(SvMemoryStream& rStream);
+
     bool isExported(){ return mbExported; }
 
 private:
diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx
index 05918c52397a..1163ace48efa 100644
--- a/sw/qa/unit/swmodeltestbase.cxx
+++ b/sw/qa/unit/swmodeltestbase.cxx
@@ -603,4 +603,11 @@ void 
SwModelTestBase::WrapReqifFromTempFile(SvMemoryStream& rStream)
     rStream.Seek(0);
 }
 
+void SwModelTestBase::WrapFromTempFile(SvMemoryStream& rStream)
+{
+    SvFileStream aFileStream(maTempFile.GetURL(), StreamMode::READ);
+    rStream.WriteStream(aFileStream);
+    rStream.Seek(0);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlnumwriter.cxx 
b/sw/source/filter/html/htmlnumwriter.cxx
index 19483e518b9e..2244cf00d1ac 100644
--- a/sw/source/filter/html/htmlnumwriter.cxx
+++ b/sw/source/filter/html/htmlnumwriter.cxx
@@ -324,7 +324,7 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
     bool bListEnd = !bSameRule || rNextInfo.GetDepth() < rInfo.GetDepth() || 
rNextInfo.IsRestart();
 
     std::optional<bool> oAtLeastOneNumbered;
-    if (rWrt.mbXHTML && !rInfo.IsNumbered())
+    if (!rInfo.IsNumbered())
     {
         oAtLeastOneNumbered = false;
         SwNodeOffset nPos = rWrt.m_pCurrentPam->GetPoint()->GetNodeIndex() - 1;
@@ -354,18 +354,15 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
         }
     }
 
-    if (rWrt.mbXHTML)
+    // The list is numbered if the previous text node is numbered or any other 
previous text
+    // node is numbered.
+    bool bPrevIsNumbered = rInfo.IsNumbered() || *oAtLeastOneNumbered;
+    // XHTML </li> for the list item content, if there is an open <li>.
+    if ((bListEnd && bPrevIsNumbered) || (!bListEnd && rNextInfo.IsNumbered()))
     {
-        // The list is numbered if the previous text node is numbered or any 
other previous text
-        // node is numbered.
-        bool bPrevIsNumbered = rInfo.IsNumbered() || *oAtLeastOneNumbered;
-        // XHTML </li> for the list item content, if there is an open <li>.
-        if ((bListEnd && bPrevIsNumbered) || (!bListEnd && 
rNextInfo.IsNumbered()))
-        {
-            HTMLOutFuncs::Out_AsciiTag(
-                rWrt.Strm(), Concat2View(rWrt.GetNamespace() + 
OOO_STRING_SVTOOLS_HTML_li),
-                false);
-        }
+        HTMLOutFuncs::Out_AsciiTag(
+            rWrt.Strm(), Concat2View(rWrt.GetNamespace() + 
OOO_STRING_SVTOOLS_HTML_li),
+            false);
     }
 
     if (!bListEnd)

Reply via email to