sw/qa/extras/htmlexport/htmlexport.cxx  |   61 ++++++++++++++++++++++++++++
 sw/source/filter/html/htmlatr.cxx       |    6 +-
 sw/source/filter/html/htmlnumwriter.cxx |   68 +++++++++++++++++++++++++++++++-
 3 files changed, 132 insertions(+), 3 deletions(-)

New commits:
commit f6a92e61558ee9134d20da5dce96e5e3b11702a8
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri May 14 09:49:17 2021 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri May 14 17:43:15 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.
    
    (cherry picked from commit 9837d3b51557955b2a2b7e66c2bdcdc706474704)
    
    Change-Id: I4008ee964d9a87a6cf409a63affce8e44d63b602

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 )
commit 7896f845faeb561d79ee43c9b5190a08a1a1dccf
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu May 13 11:45:37 2021 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri May 14 14:12:06 2021 +0200

    sw XHTML export: fix handling of list labels
    
    This is building on top of commit
    119b6876c92e4cdae44583c4b1b1419d3533e3ee (sw XHTML export: properly
    write <li>...</li> around multiple paragraphs, 2020-05-21), but the
    use-case here is a numbering with list labels only.
    
    The first problem was that the list label had its <li> suppressed, but
    not its </li>.
    
    The other problem is that <ul> can only have <li> child elements, so at
    least fix the case where the list only has list labels, in which case
    even <ul> and </ul> should be omitted.
    
    (cherry picked from commit 013a4f1f5c9ea5fb511568c53a7e76d1b365a65d)
    
    Change-Id: Id38978a40d8618f483e3e9d499f75838d5b2adb0

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 3746c3e7e786..b19ab0d655f2 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -1389,6 +1389,37 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testReqifObjdataPresentationDataSize)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(565994), 
aOle1Reader.m_nPresentationDataSize);
 }
 
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testListHeading)
+{
+    // Given a document with a list heading:
+    loadURL("private:factory/swriter", nullptr);
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Insert("list header");
+    SwDoc* pDoc = pWrtShell->GetDoc();
+    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.SetCountedInList(false);
+
+    // When exporting to ReqIF:
+    ExportToReqif();
+
+    // Then make sure the output is valid xhtml:
+    SvMemoryStream aStream;
+    HtmlExportTest::wrapFragment(maTempFile, aStream);
+    xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
+    CPPUNIT_ASSERT(pDoc);
+
+    // Without the accompanying fix in place, this test would have failed:
+    // - expected: <div><p>...</p></div>
+    // - actual  : <div><ol><p>...</p></li></ol></div>
+    // because a </li> but no <li> is not well-formed and <ol> with a non-li 
children is invalid.
+    assertXPathContent(pXmlDoc, 
"/reqif-xhtml:html/reqif-xhtml:div/reqif-xhtml:p", "list header");
+}
+
 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 ea3c949c3801..84ed431699d8 100644
--- a/sw/source/filter/html/htmlnumwriter.cxx
+++ b/sw/source/filter/html/htmlnumwriter.cxx
@@ -94,6 +94,39 @@ Writer& OutHTML_NumberBulletListStart( SwHTMLWriter& rWrt,
         return rWrt;
     }
 
+    if (rWrt.mbXHTML && !rInfo.IsNumbered())
+    {
+        // If the list only consists of non-numbered text nodes, then don't 
start the list.
+        bool bAtLeastOneNumbered = false;
+        sal_uLong nPos = rWrt.m_pCurrentPam->GetPoint()->nNode.GetIndex() + 1;
+        while (true)
+        {
+            const SwNode* pNode = rWrt.m_pDoc->GetNodes()[nPos];
+            if (!pNode->IsTextNode())
+            {
+                break;
+            }
+
+            const SwTextNode* pTextNode = pNode->GetTextNode();
+            if (!pTextNode->GetNumRule())
+            {
+                break;
+            }
+
+            if (pTextNode->IsNumbered())
+            {
+                bAtLeastOneNumbered = true;
+                break;
+            }
+            ++nPos;
+        }
+
+        if (!bAtLeastOneNumbered)
+        {
+            return rWrt;
+        }
+    }
+
     bool bStartValue = false;
     if( !bSameRule && rInfo.GetDepth() )
     {
@@ -283,7 +316,7 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
 
     if (rWrt.mbXHTML)
     {
-        if (bListEnd || (!bListEnd && rNextInfo.IsNumbered()))
+        if ((bListEnd && rInfo.IsNumbered()) || (!bListEnd && 
rNextInfo.IsNumbered()))
         {
             HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(),
                                        rWrt.GetNamespace() + 
OOO_STRING_SVTOOLS_HTML_li, false);
@@ -295,6 +328,39 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt,
         return rWrt;
     }
 
+    if (rWrt.mbXHTML && !rInfo.IsNumbered())
+    {
+        // If the list only consisted of non-numbered text nodes, then don't 
end the list.
+        bool bAtLeastOneNumbered = false;
+        sal_uLong nPos = rWrt.m_pCurrentPam->GetPoint()->nNode.GetIndex() - 1;
+        while (true)
+        {
+            const SwNode* pNode = rWrt.m_pDoc->GetNodes()[nPos];
+            if (!pNode->IsTextNode())
+            {
+                break;
+            }
+
+            const SwTextNode* pTextNode = pNode->GetTextNode();
+            if (!pTextNode->GetNumRule())
+            {
+                break;
+            }
+
+            if (pTextNode->IsNumbered())
+            {
+                bAtLeastOneNumbered = true;
+                break;
+            }
+            --nPos;
+        }
+
+        if (!bAtLeastOneNumbered)
+        {
+            return rWrt;
+        }
+    }
+
     OSL_ENSURE( rWrt.m_nLastParaToken == HtmlTokenId::NONE,
                 "<PRE> was not closed before </OL>." );
     sal_uInt16 nNextDepth =
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to