sw/qa/extras/htmlexport/htmlexport.cxx  |   41 ++++++++++++++++++++++++++++++++
 sw/source/filter/html/htmlnumwriter.cxx |   13 +++++++++-
 2 files changed, 53 insertions(+), 1 deletion(-)

New commits:
commit f6db057a505bc2a9fab66004f35b48bc89c72340
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Oct 11 16:46:21 2021 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Oct 12 09:02:50 2021 +0200

    sw XHTML export: fix missing <li> around nested <ul>/<ol>
    
    This was fine in practice in the HTML case, so make it conditional on
    the XHTML flag for now.
    
    (cherry picked from commit 869e554a017d57da14b0c5b1e1f6ce742db316e0)
    
    Conflicts:
            sw/source/filter/html/htmlnumwriter.cxx
    
    Change-Id: Ie96357ba78f4a7fae125165c1c4e47c3f5686ddf

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index e5d9b4fdc8b9..f95884620b55 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1984,6 +1984,47 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testOleEmfPreviewToHtml)
     CPPUNIT_ASSERT(aPath.endsWith("gif"));
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testNestedBullets)
+{
+    // Given a documented with nested lists:
+    loadURL("private:factory/swriter", nullptr);
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Insert("first");
+    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.SetAttrListLevel(0);
+    }
+    pWrtShell->SplitNode();
+    pWrtShell->Insert("second");
+    {
+        SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode();
+        SwTextNode& rTextNode = *rNode.GetTextNode();
+        rTextNode.SetAttr(SwNumRuleItem(pNumRule->GetName()));
+        rTextNode.SetAttrListLevel(1);
+    }
+
+    // When exporting to xhtml:
+    ExportToReqif();
+
+    // Then make sure that there is a <li> between the outer and the inner 
<ol>:
+    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:
+    // - XPath 
'//reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p' 
not found
+    // i.e. the <li> inside the outer <ol> was missing.
+    assertXPathContent(
+        pXmlDoc, 
"//reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:ol/reqif-xhtml:li/reqif-xhtml:p",
+        "second");
+}
+
 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 5b9f484d9995..3360750ecfd9 100644
--- a/sw/source/filter/html/htmlnumwriter.cxx
+++ b/sw/source/filter/html/htmlnumwriter.cxx
@@ -211,11 +211,15 @@ Writer& OutHTML_NumberBulletListStart( SwHTMLWriter& rWrt,
 
         rWrt.m_aBulletGrfs[i].clear();
         OString sOut = "<" + rWrt.GetNamespace();
+        if (rWrt.mbXHTML && (nPrevDepth != 0 || i != 0))
+        {
+            sOut += OOO_STRING_SVTOOLS_HTML_li "><" + rWrt.GetNamespace();
+        }
         const SwNumFormat& rNumFormat = rInfo.GetNumRule()->Get( i );
         sal_Int16 eType = rNumFormat.GetNumberingType();
         if( SVX_NUM_CHAR_SPECIAL == eType )
         {
-            // ordered list: <OL>
+            // unordered list: <UL>
             sOut += OString(OOO_STRING_SVTOOLS_HTML_unorderlist);
 
             // determine the type by the bullet character
@@ -319,6 +323,7 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
 
     if (rWrt.mbXHTML)
     {
+        // XHTML </li> for the list item content.
         if ((bListEnd && rInfo.IsNumbered()) || (!bListEnd && 
rNextInfo.IsNumbered()))
         {
             HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(),
@@ -387,6 +392,12 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
         else
             aTag = OOO_STRING_SVTOOLS_HTML_orderlist;
         HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rWrt.GetNamespace() + aTag, 
false );
+        if (rWrt.mbXHTML && (nNextDepth != 0 || i != 1))
+        {
+            HTMLOutFuncs::Out_AsciiTag(
+                rWrt.Strm(), rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_li,
+                /*bOn=*/false);
+        }
         rWrt.m_bLFPossible = true;
     }
 

Reply via email to