diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-05-25 19:41:32 +0300 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-05-28 21:00:25 +0200 |
commit | 6e8ebd58cc13e3b551604aa96ca3b51cdc9793d2 (patch) | |
tree | 72bcd168a766e9bde820ad39dedd5bfe5767f5da /sw/source/filter | |
parent | 60d2ef2a1c387885da95dfae1e93775555c844b0 (diff) |
tdf#155496: Export list header to (X)HTML using 'display: block' style
This re-implements commit 013a4f1f5c9ea5fb511568c53a7e76d1b365a65d
(sw XHTML export: fix handling of list labels, 2021-05-13), and
instead of not putting headers (ODF 'text:list-header' elements)
into lists, this adds 'style="display: block"' attribute to the
respective list items. This makes sure that the items use proper
list indentation, and produces correct markup.
Change-Id: I900e4aebbe562830dc2ce5400e3e33b38c2f2faa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152280
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152298
Diffstat (limited to 'sw/source/filter')
-rw-r--r-- | sw/source/filter/html/htmlatr.cxx | 21 | ||||
-rw-r--r-- | sw/source/filter/html/htmlnumwriter.cxx | 85 | ||||
-rw-r--r-- | sw/source/filter/html/wrthtml.hxx | 3 |
3 files changed, 17 insertions, 92 deletions
diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index 87b38fc0165f..79c00be34fad 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -683,12 +683,11 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, if( nNewDefListLvl != rHWrt.m_nDefListLvl ) rHWrt.OutAndSetDefList( nNewDefListLvl ); - bool bAtLeastOneNumbered = false; // if necessary, start a bulleted or numbered list if( rInfo.bInNumberBulletList ) { OSL_ENSURE( !rHWrt.m_nDefListLvl, "DL cannot be inside OL!" ); - OutHTML_NumberBulletListStart( rHWrt, aNumInfo, bAtLeastOneNumbered ); + OutHTML_NumberBulletListStart( rHWrt, aNumInfo ); if( bNumbered ) { @@ -758,18 +757,26 @@ static void OutHTML_SwFormat( Writer& rWrt, const SwFormat& rFormat, // if necessary, start a new list item bool bNumberedForListItem = bNumbered; - if (!bNumberedForListItem && rHWrt.mbXHTML && bAtLeastOneNumbered) + if (!bNumberedForListItem) { - // OutHTML_NumberBulletListEnd() will end a list item if at least one text node is numbered - // in the list, so open the list item with the same condition here. - bNumberedForListItem = true; + // Open a list also for the leading unnumbered nodes (= list headers in ODF terminology); + // to do that, detect if this unnumbered node is the first in this list + const auto& rPrevListInfo = rHWrt.GetNumInfo(); + if (rPrevListInfo.GetNumRule() != aNumInfo.GetNumRule() || aNumInfo.IsRestart(rPrevListInfo) + || rPrevListInfo.GetDepth() < aNumInfo.GetDepth()) + bNumberedForListItem = true; } if( rInfo.bInNumberBulletList && bNumberedForListItem ) { HtmlWriter html(rWrt.Strm(), rHWrt.maNamespace); html.prettyPrint(rHWrt.m_bPrettyPrint); html.start(OOO_STRING_SVTOOLS_HTML_li); - if( USHRT_MAX != nNumStart ) + if (!bNumbered) + { + // Handles list headers (<text:list-header> ODF element) + html.attribute(OOO_STRING_SVTOOLS_HTML_O_style, "display: block"); + } + else if (USHRT_MAX != nNumStart) html.attribute(OOO_STRING_SVTOOLS_HTML_O_value, OString::number(nNumStart)); // Finish the opening element, but don't close it. html.characters(""); diff --git a/sw/source/filter/html/htmlnumwriter.cxx b/sw/source/filter/html/htmlnumwriter.cxx index 365864810551..a3bc30891f76 100644 --- a/sw/source/filter/html/htmlnumwriter.cxx +++ b/sw/source/filter/html/htmlnumwriter.cxx @@ -84,8 +84,7 @@ void SwHTMLWriter::SetNextNumInfo( std::unique_ptr<SwHTMLNumRuleInfo> pNxt ) } Writer& OutHTML_NumberBulletListStart( SwHTMLWriter& rWrt, - const SwHTMLNumRuleInfo& rInfo, - bool& rAtLeastOneNumbered ) + const SwHTMLNumRuleInfo& rInfo ) { SwHTMLNumRuleInfo& rPrevInfo = rWrt.GetNumInfo(); bool bSameRule = rPrevInfo.GetNumRule() == rInfo.GetNumRule(); @@ -95,43 +94,6 @@ 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; - SwNodeOffset nPos = rWrt.m_pCurrentPam->GetPoint()->GetNodeIndex() + 1; - SwNumRule* pNumRule = nullptr; - while (true) - { - const SwNode* pNode = rWrt.m_pDoc->GetNodes()[nPos]; - if (!pNode->IsTextNode()) - { - break; - } - - const SwTextNode* pTextNode = pNode->GetTextNode(); - if (!pTextNode->GetNumRule() || (pNumRule && pTextNode->GetNumRule() != pNumRule)) - { - // Node is not in the same numbering as the previous one. - break; - } - - pNumRule = pTextNode->GetNumRule(); - if (pTextNode->IsNumbered()) - { - bAtLeastOneNumbered = true; - break; - } - ++nPos; - } - - rAtLeastOneNumbered = bAtLeastOneNumbered; - if (!bAtLeastOneNumbered) - { - return rWrt; - } - } - bool bStartValue = false; if( !bSameRule && rInfo.GetDepth() ) { @@ -325,44 +287,10 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt, bool bListEnd = !bSameRule || rNextInfo.GetDepth() < rInfo.GetDepth() || rNextInfo.IsRestart(rInfo); bool bNextIsSubitem = !bListEnd && rNextInfo.GetDepth() > rInfo.GetDepth(); - std::optional<bool> oAtLeastOneNumbered; - if (!rInfo.IsNumbered()) - { - oAtLeastOneNumbered = false; - SwNodeOffset nPos = rWrt.m_pCurrentPam->GetPoint()->GetNodeIndex() - 1; - SwNumRule* pNumRule = nullptr; - while (true) - { - const SwNode* pNode = rWrt.m_pDoc->GetNodes()[nPos]; - if (!pNode->IsTextNode()) - { - break; - } - - const SwTextNode* pTextNode = pNode->GetTextNode(); - if (!pTextNode->GetNumRule() || (pNumRule && pTextNode->GetNumRule() != pNumRule)) - { - // Node is not in the same numbering as the next one. - break; - } - - pNumRule = pTextNode->GetNumRule(); - if (pTextNode->IsNumbered()) - { - oAtLeastOneNumbered = true; - break; - } - --nPos; - } - } - if (rWrt.mbXHTML) { - // The list is numbered if the previous text node is numbered or any other previous text - // node is numbered. - bool bPrevIsNumbered = rInfo.IsNumbered() || *oAtLeastOneNumbered; // XHTML </li> for the list item content, if there is an open <li>. - if ((bListEnd && bPrevIsNumbered) || (!bListEnd && !bNextIsSubitem && rNextInfo.IsNumbered())) + if (bListEnd || (!bNextIsSubitem && rNextInfo.IsNumbered())) { HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), Concat2View(rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_li), @@ -375,15 +303,6 @@ 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. - if (!*oAtLeastOneNumbered) - { - return rWrt; - } - } - OSL_ENSURE( rWrt.m_nLastParaToken == HtmlTokenId::NONE, "<PRE> was not closed before </OL>." ); sal_uInt16 nNextDepth = diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx index a1986daf5dba..aa87bf245592 100644 --- a/sw/source/filter/html/wrthtml.hxx +++ b/sw/source/filter/html/wrthtml.hxx @@ -724,8 +724,7 @@ Writer& OutCSS1_NumberBulletListStyleOpt( Writer& rWrt, const SwNumRule& rNumRul sal_uInt8 nLevel ); Writer& OutHTML_NumberBulletListStart( SwHTMLWriter& rWrt, - const SwHTMLNumRuleInfo& rInfo, - bool& rAtLeastOneNumbered ); + const SwHTMLNumRuleInfo& rInfo ); Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt, const SwHTMLNumRuleInfo& rNextInfo ); |