diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-10-04 21:21:39 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-10-29 14:16:37 +0100 |
commit | 49fb356bac7459928a0c1688f35016efb74d9c1a (patch) | |
tree | de1d11580048c5d0503e31fcabcb559f4ba475dc /editeng | |
parent | bd1d232119dcff9ca0788554a8477d769964d5c6 (diff) |
treat divs as requiring a new block/para
but consider inserting a paragraph as fulfilling that requirement, and
only insert a new para if content shows up before a new para does.
Change-Id: I7455575a77a1f3b176ed8d5b16a7e5a688ba9dbc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174507
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit 0287036fa4ae6d709aedc6b721329251fa6f412f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175754
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/eehtml.cxx | 12 | ||||
-rw-r--r-- | editeng/source/editeng/eehtml.hxx | 1 | ||||
-rw-r--r-- | editeng/source/editeng/impedit4.cxx | 16 |
3 files changed, 22 insertions, 7 deletions
diff --git a/editeng/source/editeng/eehtml.cxx b/editeng/source/editeng/eehtml.cxx index 11cf8811bf9d..d7f7bda645f6 100644 --- a/editeng/source/editeng/eehtml.cxx +++ b/editeng/source/editeng/eehtml.cxx @@ -42,6 +42,7 @@ EditHTMLParser::EditHTMLParser( SvStream& rIn, OUString _aBaseURL, SvKeyValueIte bInPara(false), bWasInPara(false), mbBreakForDivs(false), + mbNewBlockNeeded(false), bFieldsInserted(false), bInTitle(false), nInTable(0), @@ -313,8 +314,7 @@ void EditHTMLParser::NextToken( HtmlTokenId nToken ) case HtmlTokenId::DIVISION_ON: case HtmlTokenId::DIVISION_OFF: { - if (mbBreakForDivs) - Newline(); + mbNewBlockNeeded = true; break; } @@ -531,6 +531,7 @@ void EditHTMLParser::ImpInsertParaBreak() mpEditEngine->CallHtmlImportHandler(aImportInfo); } aCurSel = mpEditEngine->InsertParaBreak(aCurSel); + mbNewBlockNeeded = false; } void EditHTMLParser::ImpSetAttribs( const SfxItemSet& rItems ) @@ -676,6 +677,13 @@ void EditHTMLParser::ImpSetStyleSheet( sal_uInt16 nHLevel ) void EditHTMLParser::ImpInsertText( const OUString& rText ) { + if (mbNewBlockNeeded) + { + if (mbBreakForDivs) + Newline(); + mbNewBlockNeeded = false; + } + if (mpEditEngine->IsHtmlImportHandlerSet()) { HtmlImportInfo aImportInfo(HtmlImportState::InsertText, this, mpEditEngine->CreateESelection(aCurSel)); diff --git a/editeng/source/editeng/eehtml.hxx b/editeng/source/editeng/eehtml.hxx index 7b6591e2ccf4..9d77ebdaf68c 100644 --- a/editeng/source/editeng/eehtml.hxx +++ b/editeng/source/editeng/eehtml.hxx @@ -46,6 +46,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 mbNewBlockNeeded:1; bool bFieldsInserted:1; bool bInTitle:1; diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx index 8ffb3faf47b8..22e99ccf894f 100644 --- a/editeng/source/editeng/impedit4.cxx +++ b/editeng/source/editeng/impedit4.cxx @@ -1087,7 +1087,7 @@ OString ImpEditEngine::GetSimpleHtml() const sal_Int32 nIndex = 0; sal_Int32 nEndPortion = pParaPortion->GetTextPortions().Count() - 1; - aOutput.append("<div>"); + OStringBuffer aPara; for (sal_Int32 n = 0; n <= nEndPortion; n++) { const TextPortion& rTextPortion = pParaPortion->GetTextPortions()[n]; @@ -1106,17 +1106,23 @@ OString ImpEditEngine::GetSimpleHtml() const OUString aRTFStr = EditDoc::GetParaAsString(pNode, nIndex, nIndex + rTextPortion.GetLen()); if (pURLField) - aOutput.append("<a href=\"" + HTMLOutFuncs::ConvertStringToHTML(pURLField->GetURL()) + "\">"); + aPara.append("<a href=\"" + HTMLOutFuncs::ConvertStringToHTML(pURLField->GetURL()) + "\">"); - aOutput.append(HTMLOutFuncs::ConvertStringToHTML(aRTFStr)); + aPara.append(HTMLOutFuncs::ConvertStringToHTML(aRTFStr)); if (pURLField) - aOutput.append("</a>"); + aPara.append("</a>"); nIndex = nIndex + rTextPortion.GetLen(); } - aOutput.append("</div>"); + if (aPara.isEmpty()) + { + if (nEndNode == 0) // only one empty blank line + break; + aPara.append("<br/>"); + } + aOutput.append("<div>" + aPara + "</div>"); } return aOutput.makeStringAndClear(); |