diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-02-21 16:38:51 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-02-22 12:06:20 +0100 |
commit | c3439e7053d4dafedd87b7128bc2253ff2f9c947 (patch) | |
tree | 3e28c6a78e8efd4f903b666cc913fd0ff16ff9a1 /sw/source/filter/html | |
parent | 503046607b96d4ee1b75034636021b1297853572 (diff) |
sw HTML export, XHTML mode: fix lost </li> when last list item is not numbered
This went wrong in 013a4f1f5c9ea5fb511568c53a7e76d1b365a65d (sw XHTML
export: fix handling of list labels, 2021-05-13), where we started to
assume that in case the last paragraph of a list is not numbered, then
the entire list is not numbered. This lead to loosing the </li> for an
<li> in case the list starts with a numbered paragraph, but ends with a
non-numbered one.
Fix the problem by (if necessary) looking back till the start of the
list to see if any paragraph is numbered: that ensures that the <li> and
</li> is always in sync.
This fixes the new problem and keeps the old problem fixed at the same
time.
(cherry picked from commit 8c2607ae3ce143586e623532b8ae5288277ec3ac)
Conflicts:
sw/source/filter/html/htmlnumwriter.cxx
Change-Id: I7d347b37a40dcc727c2080bf8279e33c3ad147e9
Diffstat (limited to 'sw/source/filter/html')
-rw-r--r-- | sw/source/filter/html/htmlnumwriter.cxx | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/sw/source/filter/html/htmlnumwriter.cxx b/sw/source/filter/html/htmlnumwriter.cxx index 84ed431699d8..7e2583a48583 100644 --- a/sw/source/filter/html/htmlnumwriter.cxx +++ b/sw/source/filter/html/htmlnumwriter.cxx @@ -314,24 +314,10 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt, bool bSameRule = rNextInfo.GetNumRule() == rInfo.GetNumRule(); bool bListEnd = !bSameRule || rNextInfo.GetDepth() < rInfo.GetDepth() || rNextInfo.IsRestart(); - if (rWrt.mbXHTML) - { - if ((bListEnd && rInfo.IsNumbered()) || (!bListEnd && rNextInfo.IsNumbered())) - { - HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(), - rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_li, false); - } - } - - if (!bListEnd) - { - return rWrt; - } - + std::optional<bool> oAtLeastOneNumbered; if (rWrt.mbXHTML && !rInfo.IsNumbered()) { - // If the list only consisted of non-numbered text nodes, then don't end the list. - bool bAtLeastOneNumbered = false; + oAtLeastOneNumbered = false; sal_uLong nPos = rWrt.m_pCurrentPam->GetPoint()->nNode.GetIndex() - 1; while (true) { @@ -349,13 +335,36 @@ Writer& OutHTML_NumberBulletListEnd( SwHTMLWriter& rWrt, if (pTextNode->IsNumbered()) { - bAtLeastOneNumbered = true; + 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 && rNextInfo.IsNumbered())) + { + HTMLOutFuncs::Out_AsciiTag( + rWrt.Strm(), rWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_li, + false); + } + } - if (!bAtLeastOneNumbered) + if (!bListEnd) + { + 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; } |