[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri May 14 08:58:16 UTC 2021


 sw/qa/extras/htmlexport/htmlexport.cxx |   30 ++++++++++++++++++++++++++++++
 sw/source/filter/html/htmlatr.cxx      |    6 ++++--
 2 files changed, 34 insertions(+), 2 deletions(-)

New commits:
commit 9837d3b51557955b2a2b7e66c2bdcdc706474704
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri May 14 09:49:17 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri May 14 10:57:39 2021 +0200

    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.
    
    Change-Id: I4008ee964d9a87a6cf409a63affce8e44d63b602
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115580
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 1d56b2b23d3c..b6ead94c80fe 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1417,6 +1417,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 94e41f538afa..a15cd96519cb 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(), OString(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 )


More information about the Libreoffice-commits mailing list