summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-10-11 16:46:21 +0200
committerMiklos Vajna <vmiklos@collabora.com>2022-07-01 09:59:35 +0200
commit3dc5b937736d4dedb2e02120df12b75740460e8e (patch)
tree946e35dd91d4cd9fc87288ad7b594bcde7a7553a
parent5dbdd9624f6988380638d47b0b416833e38bf890 (diff)
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 (cherry picked from commit f6db057a505bc2a9fab66004f35b48bc89c72340) Conflicts: sw/qa/extras/htmlexport/htmlexport.cxx sw/source/filter/html/htmlnumwriter.cxx Change-Id: Ie96357ba78f4a7fae125165c1c4e47c3f5686ddf
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx41
-rw-r--r--sw/source/filter/html/htmlnumwriter.cxx12
2 files changed, 52 insertions, 1 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index cf64738d0e40..ca66e36fff8e 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1582,6 +1582,47 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOleBmpTransparent)
CPPUNIT_ASSERT_EQUAL(COL_WHITE, nActualColor);
}
+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 7e2583a48583..965f7ccbfd70 100644
--- a/sw/source/filter/html/htmlnumwriter.cxx
+++ b/sw/source/filter/html/htmlnumwriter.cxx
@@ -208,11 +208,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
@@ -390,6 +394,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;
}