summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-10-11 16:46:21 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-10-11 18:44:06 +0200
commit869e554a017d57da14b0c5b1e1f6ce742db316e0 (patch)
tree2ed6418b8e341ce26660b4a3540b6f76f907f2da
parent3739253b35212f45dd1654286db5e97b70589a57 (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. Change-Id: Ie96357ba78f4a7fae125165c1c4e47c3f5686ddf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123421 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx39
-rw-r--r--sw/source/filter/html/htmlnumwriter.cxx13
2 files changed, 51 insertions, 1 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 5a2ea84292ac..d16c60735ace 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2005,6 +2005,45 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testOleEmfPreviewToHtml)
CPPUNIT_ASSERT(aPath.endsWith("gif"));
}
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testNestedBullets)
+{
+ // Given a documented with nested lists:
+ SwDoc* pDoc = createSwDoc();
+ SwWrtShell* pWrtShell = pDoc->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 f57e57d19be3..7fe8ec110661 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 += 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(), OStringConcatenation(rWrt.GetNamespace() + aTag), false );
+ if (rWrt.mbXHTML && (nNextDepth != 0 || i != 1))
+ {
+ HTMLOutFuncs::Out_AsciiTag(
+ rWrt.Strm(), OStringConcatenation(rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_li),
+ /*bOn=*/false);
+ }
rWrt.m_bLFPossible = true;
}