diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-05-14 09:49:17 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-05-14 17:43:15 +0200 |
commit | f6a92e61558ee9134d20da5dce96e5e3b11702a8 (patch) | |
tree | 52428104b6c05af9413c6de4d91da32dd4a666fc | |
parent | 7896f845faeb561d79ee43c9b5190a08a1a1dccf (diff) |
sw XHTML export: fix <blockquote> with no-margin to not have character children
This is building on top of commit
f2eae41e9a85cd1df4190160b7453d3e12b8ccbd (sw XHTML export: <blockquote>
can't have character children, 2019-11-07), which handled this in
general, but only worked in case the Quotation style had a non-zero
bottom margin.
(cherry picked from commit 9837d3b51557955b2a2b7e66c2bdcdc706474704)
Change-Id: I4008ee964d9a87a6cf409a63affce8e44d63b602
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 30 | ||||
-rw-r--r-- | sw/source/filter/html/htmlatr.cxx | 6 |
2 files changed, 34 insertions, 2 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index b19ab0d655f2..ad64b6404007 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -1420,6 +1420,36 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListHeading) assertXPathContent(pXmlDoc, "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "list header"); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteNoMargin) +{ + // Given a document with some text, para style set to Quotations, no bottom margin: + loadURL("private:factory/swriter", nullptr); + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XText> xText = xTextDocument->getText(); + xText->insertString(xText->getEnd(), "string", /*bAbsorb=*/false); + uno::Reference<beans::XPropertySet> xQuotations( + getStyles("ParagraphStyles")->getByName("Quotations"), uno::UNO_QUERY); + xQuotations->setPropertyValue("ParaBottomMargin", uno::makeAny(static_cast<sal_Int32>(0))); + uno::Reference<beans::XPropertySet> xParagraph(getParagraph(1), uno::UNO_QUERY); + xParagraph->setPropertyValue("ParaStyleName", uno::makeAny(OUString("Quotations"))); + + // When exporting to XHTML: + ExportToReqif(); + + // Then make sure the output is valid xhtml: + SvMemoryStream aStream; + HtmlExportTest::wrapFragment(maTempFile, aStream); + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream); + CPPUNIT_ASSERT(pXmlDoc); + // Without the accompanying fix in place, this test would have failed: + // - expected: <blockquote><p>...</p></blockquote> + // - actual : <blockquote>...</blockquote> + // i.e. <blockquote> is can't have character children, but it had. + assertXPathContent(pXmlDoc, + "/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:blockquote/reqif-xhtml:p", + "string"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index e7997b56f5e5..46abffd664a9 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -755,6 +755,8 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, rHWrt.ChangeParaToken( nToken ); bool bHasParSpace = bUseParSpace && rULSpace.GetLower() > 0; + // XHTML doesn't allow character children for <blockquote>. + bool bXhtmlBlockQuote = rHWrt.mbXHTML && rInfo.aToken == OOO_STRING_SVTOOLS_HTML_blockquote; // if necessary, start a new list item if( rInfo.bInNumberBulletList && bNumbered ) @@ -801,7 +803,7 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, // Also, XHTML does not allow character children in this context. OString aToken = rInfo.aToken; if( (!rHWrt.m_bCfgOutStyles || rHWrt.mbXHTML) && rInfo.bParaPossible && !bPara && - (bHasParSpace || pAdjItem) ) + (bHasParSpace || bXhtmlBlockQuote || pAdjItem) ) { HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHWrt.GetNamespace() + rInfo.aToken ); aToken = OOO_STRING_SVTOOLS_HTML_parabreak; @@ -849,7 +851,7 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, (!rInfo.bInNumberBulletList && !rHWrt.m_nDefListLvl) || (rInfo.bInNumberBulletList && !bNumbered) || (!rHWrt.m_bCfgOutStyles && - (bHasParSpace || pAdjItem || + (bHasParSpace || bXhtmlBlockQuote || pAdjItem || (eLang != LANGUAGE_DONTKNOW && eLang != rHWrt.m_eLang))) || nDir != rHWrt.m_nDirection || rHWrt.m_bCfgOutStyles ) |