diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-05-21 11:05:30 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-05-21 13:08:11 +0200 |
commit | 119b6876c92e4cdae44583c4b1b1419d3533e3ee (patch) | |
tree | d16b8554120d8f325ae8c662be07bdabbf4d8a41 /sw/qa/extras/htmlexport | |
parent | 09c757cbdd3f973c97151203d8ff522141102da7 (diff) |
sw XHTML export: properly write <li>...</li> around multiple paragraphs
Writer just has a list of text nodes, but ODF and HTML can have multiple
paragraphs inside <li>, in case the non-first text nodes have their
RES_PARATR_LIST_ISCOUNTED set to false.
Improve b6f7a4908d1c3fc610440a1cbbbc1673a53da8b6 (sw XHTML export:
properly write <li>...</li> around paragraphs, 2018-04-11) to make the
decision around when to write </li> based on not only the current but
also the next text node. This way we omit </li> for non-first paragraphs
inside <li>, but keep writing it in other cases.
Change-Id: I994855961aeea92050268dba5f19f125c7ad2b7f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94622
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/qa/extras/htmlexport')
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 7ea6e300f603..512fd4c070cb 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -22,6 +22,9 @@ #include <swmodule.hxx> #include <swdll.hxx> #include <usrpref.hxx> +#include <wrtsh.hxx> +#include <ndtxt.hxx> +#include <paratr.hxx> #include <test/htmltesttools.hxx> #include <tools/urlobj.hxx> @@ -33,6 +36,7 @@ #include <svtools/rtftoken.h> #include <filter/msfilter/rtfutil.hxx> #include <sot/storage.hxx> +#include <svl/eitem.hxx> class HtmlExportTest : public SwModelTestBase, public HtmlTestTools { @@ -1053,6 +1057,55 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOle1PDF) CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(39409), pOleNative->GetSize()); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testMultiParaListItem) +{ + // Create a document with 3 list items: A, B&C and D. + loadURL("private:factory/swriter", nullptr); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell(); + pWrtShell->Insert("A"); + SwDoc* pDoc = pWrtShell->GetDoc(); + { + // Enable numbering. + 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->SplitNode(); + pWrtShell->Insert("B"); + pWrtShell->SplitNode(); + pWrtShell->Insert("C"); + { + // C is in the same list item as B. + SwNode& rNode = pWrtShell->GetCursor()->GetPoint()->nNode.GetNode(); + SwTextNode& rTextNode = *rNode.GetTextNode(); + rTextNode.SetCountedInList(false); + } + pWrtShell->SplitNode(); + pWrtShell->Insert("D"); + + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProperties = { + comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), + comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), + }; + xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + + SvMemoryStream aStream; + HtmlExportTest::wrapFragment(maTempFile, aStream); + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + CPPUNIT_ASSERT(pDoc); + assertXPathContent(pXmlDoc, "//reqif-xhtml:ol/reqif-xhtml:li[1]/reqif-xhtml:p", "A"); + assertXPathContent(pXmlDoc, "//reqif-xhtml:ol/reqif-xhtml:li[2]/reqif-xhtml:p[1]", "B"); + // Without the accompanying fix in place, this test would have failed with: + // XPath '//reqif-xhtml:ol/reqif-xhtml:li[2]/reqif-xhtml:p[2]' not found + // i.e. </li> was writen before "C", not after "C", so "C" was not in the 2nd list item. + assertXPathContent(pXmlDoc, "//reqif-xhtml:ol/reqif-xhtml:li[2]/reqif-xhtml:p[2]", "C"); + assertXPathContent(pXmlDoc, "//reqif-xhtml:ol/reqif-xhtml:li[3]/reqif-xhtml:p", "D"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |