editeng/source/editeng/eehtml.cxx        |   30 ++++++++++++++++++++++++++++--
 editeng/source/editeng/eehtml.hxx        |    2 ++
 sw/source/uibase/docvw/AnnotationWin.cxx |    7 ++++++-
 3 files changed, 36 insertions(+), 3 deletions(-)

New commits:
commit 26e4f2fdca356fd060bcafa5216c1a5de488510a
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Oct 2 14:18:45 2024 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Oct 4 09:53:12 2024 +0200

    allow editeng html import to treat divs as inserting a newline
    
    optional, currently cowardly defaulted off, except for the specific
    use-case.
    
    Change-Id: I8a6176ee356fa4d2b665d5325d9b7aba2a6579f6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174387
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/editeng/source/editeng/eehtml.cxx 
b/editeng/source/editeng/eehtml.cxx
index 3db92d077694..046bab27fbee 100644
--- a/editeng/source/editeng/eehtml.cxx
+++ b/editeng/source/editeng/eehtml.cxx
@@ -41,6 +41,7 @@ EditHTMLParser::EditHTMLParser( SvStream& rIn, OUString 
_aBaseURL, SvKeyValueIte
     mpEditEngine(nullptr),
     bInPara(false),
     bWasInPara(false),
+    mbBreakForDivs(false),
     bFieldsInserted(false),
     bInTitle(false),
     nInTable(0),
@@ -57,7 +58,25 @@ EditHTMLParser::EditHTMLParser( SvStream& rIn, OUString 
_aBaseURL, SvKeyValueIte
     SetSwitchToUCS2( true );
 
     if ( pHTTPHeaderAttrs )
+    {
         SetEncodingByHTTPHeader( pHTTPHeaderAttrs );
+        SetBreakForDivs(*pHTTPHeaderAttrs);
+    }
+}
+
+void EditHTMLParser::SetBreakForDivs(SvKeyValueIterator& rHTTPHeader)
+{
+    SvKeyValue aKV;
+    bool bCont = rHTTPHeader.GetFirst(aKV);
+    while (bCont)
+    {
+        if (aKV.GetKey() == "newline-on-div")
+        {
+            mbBreakForDivs = aKV.GetValue() == "true";
+            break;
+        }
+        bCont = rHTTPHeader.GetNext(aKV);
+    }
 }
 
 EditHTMLParser::~EditHTMLParser()
@@ -290,6 +309,15 @@ void EditHTMLParser::NextToken( HtmlTokenId nToken )
         nInCell++;
         Newline();
     break;
+
+    case HtmlTokenId::DIVISION_ON:
+    case HtmlTokenId::DIVISION_OFF:
+    {
+        if (mbBreakForDivs)
+            Newline();
+        break;
+    }
+
     case HtmlTokenId::BLOCKQUOTE_ON:
     case HtmlTokenId::BLOCKQUOTE_OFF:
     case HtmlTokenId::BLOCKQUOTE30_ON:
@@ -356,8 +384,6 @@ void EditHTMLParser::NextToken( HtmlTokenId nToken )
     // HTML 3.0
     case HtmlTokenId::BANNER_ON:
     case HtmlTokenId::BANNER_OFF:
-    case HtmlTokenId::DIVISION_ON:
-    case HtmlTokenId::DIVISION_OFF:
 //  case HtmlTokenId::LISTHEADER_ON:        //! special handling
 //  case HtmlTokenId::LISTHEADER_OFF:
     case HtmlTokenId::NOTE_ON:
diff --git a/editeng/source/editeng/eehtml.hxx 
b/editeng/source/editeng/eehtml.hxx
index 9f8009c715c8..0cdb1c8553e8 100644
--- a/editeng/source/editeng/eehtml.hxx
+++ b/editeng/source/editeng/eehtml.hxx
@@ -45,6 +45,7 @@ private:
 
     bool                    bInPara:1;
     bool                    bWasInPara:1; // Remember bInPara before 
HeadingStart, because afterwards it will be gone.
+    bool                    mbBreakForDivs:1; // Create newlines on 
encountering divs
     bool                    bFieldsInserted:1;
     bool                    bInTitle:1;
 
@@ -68,6 +69,7 @@ private:
     void                    ImpSetAttribs( const SfxItemSet& rItems );
     void                    ImpSetStyleSheet( sal_uInt16 nHeadingLevel );
 
+    void                    SetBreakForDivs(SvKeyValueIterator& rHTTPHeader);
 protected:
     virtual void            NextToken( HtmlTokenId nToken ) override;
 
diff --git a/sw/source/uibase/docvw/AnnotationWin.cxx 
b/sw/source/uibase/docvw/AnnotationWin.cxx
index 41e5bac03dc5..3bb933f61fbd 100644
--- a/sw/source/uibase/docvw/AnnotationWin.cxx
+++ b/sw/source/uibase/docvw/AnnotationWin.cxx
@@ -32,6 +32,7 @@
 #include <vcl/uitest/eventdescription.hxx>
 
 #include <svl/undo.hxx>
+#include <svtools/svparser.hxx>
 #include <unotools/localedatawrapper.hxx>
 #include <unotools/syslocale.hxx>
 #include <svl/languageoptions.hxx>
@@ -490,7 +491,11 @@ void SwAnnotationWin::UpdateHTML(const OUString& rHtml)
     OString sHtmlContent(rHtml.toUtf8());
     SvMemoryStream aHTMLStream(const_cast<char*>(sHtmlContent.getStr()),
                                sHtmlContent.getLength(), StreamMode::READ);
-    GetOutlinerView()->Read(aHTMLStream, EETextFormat::Html, nullptr);
+    SvKeyValueIteratorRef xValues(new SvKeyValueIterator);
+    // Insert newlines for divs, not normally done, so to keep things simple
+    // only enable tthat for this case.
+    xValues->Append(SvKeyValue("newline-on-div", "true"));
+    GetOutlinerView()->Read(aHTMLStream, EETextFormat::Html, xValues.get());
     UpdateData();
 }
 

Reply via email to